SDN 实践之floodlight控制器统计流量种类.docx
- 文档编号:2440612
- 上传时间:2022-10-29
- 格式:DOCX
- 页数:16
- 大小:18.53KB
SDN 实践之floodlight控制器统计流量种类.docx
《SDN 实践之floodlight控制器统计流量种类.docx》由会员分享,可在线阅读,更多相关《SDN 实践之floodlight控制器统计流量种类.docx(16页珍藏版)》请在冰豆网上搜索。
SDN实践之floodlight控制器统计流量种类
SDN实践之floodlight控制器统计流量种类
@温州大学12网工
在floodlight控制器统计流量的基础上接着把packed-in流量的种类也区分一下。
counter这个类琢磨了一个月终于有些会用了。
下面贴代码:
分两个.java
1.
packageedu.wzu.steve.trafficanalyser;
importjava.util.ArrayList;
importjava.util.Collection;
importjava.util.HashMap;
importjava.util.Iterator;
importjava.util.List;
importjava.util.Map;
importjava.util.Map.Entry;
importorg.restlet.resource.ResourceException;
importorg.restlet.resource.ServerResource;
importnet.floodlightcontroller.counter.CounterValue;
importnet.floodlightcontroller.counter.ICounter;
importnet.floodlightcontroller.packet.Ethernet;
importnet.floodlightcontroller.packet.IPv4;
importorg.restlet.resource.Get;
importnet.floodlightcontroller.core.FloodlightContext;
importnet.floodlightcontroller.core.IFloodlightProviderService;
importnet.floodlightcontroller.core.IOFMessageListener;
importnet.floodlightcontroller.core.IOFSwitch;
importnet.floodlightcontroller.core.module.FloodlightModuleContext;
importnet.floodlightcontroller.core.module.FloodlightModuleException;
importnet.floodlightcontroller.core.module.IFloodlightModule;
importnet.floodlightcontroller.core.module.IFloodlightService;
importnet.floodlightcontroller.counter.ICounterStoreService;
importorg.openflow.protocol.OFMessage;
importorg.openflow.protocol.OFType;
importorg.slf4j.Logger;
importorg.slf4j.LoggerFactory;
publicclassTrafficAnalyserextendsServerResourceimplementsIOFMessageListener,IFloodlightModule{
publicfinalstaticStringBROADCAST="broadcast";
publicfinalstaticStringMULTICAST="multicast";
publicfinalstaticStringUNICAST="unicast";
protectedICounterStoreServicecounterStore;
protectedIFloodlightProviderServicefloodlightProvider;
protectedstaticLoggerlogger;
@Override
publicStringgetName(){
//TODOAuto-generatedmethodstub
returnTrafficAnalyser.class.getSimpleName();
}
@Override
publicbooleanisCallbackOrderingPrereq(OFTypetype,Stringname){
//TODOAuto-generatedmethodstub
returnfalse;
}
@Override
publicbooleanisCallbackOrderingPostreq(OFTypetype,Stringname){
//TODOAuto-generatedmethodstub
returnfalse;
}
@Override
publicCollection extendsIFloodlightService>>getModuleServices(){ //TODOAuto-generatedmethodstub returnnull; } @Override publicMap extendsIFloodlightService>,IFloodlightService>getServiceImpls(){ //TODOAuto-generatedmethodstub returnnull; } @Override publicCollection extendsIFloodlightService>>getModuleDependencies(){ //TODOAuto-generatedmethodstub Collection extendsIFloodlightService>>l= newArrayList extendsIFloodlightService>>(); l.add(IFloodlightProviderService.class); returnl; } @Override publicvoidinit(FloodlightModuleContextcontext) throwsFloodlightModuleException{ this.floodlightProvider=context.getServiceImpl(IFloodlightProviderService.class); this.counterStore=context.getServiceImpl(ICounterStoreService.class); logger=LoggerFactory.getLogger(TrafficAnalyser.class); } @Override publicvoidstartUp(FloodlightModuleContextcontext){ floodlightProvider.addOFMessageListener(OFType.PACKET_IN,this); } @Get("json") publicMap Map CounterValuev; Map if(counters! =null){ Iterator counters.entrySet().iterator(); while(it.hasNext()){ Entry StringcounterName=entry.getKey(); v=entry.getValue().getCounterValue(); if(CounterValue.CounterType.LONG==v.getType()){ model.put(counterName,v.getLong()); }elseif(v.getType()==CounterValue.CounterType.DOUBLE){ model.put(counterName,v.getDouble()); } } } returnmodel; } protectedList intl3type=eth.getEtherType()&0xffff; StringswitchIdHex=sw.getStringId(); StringetherType=String.format("%04x",eth.getEtherType()); StringpacketName=m.getType().toClass().getName(); packetName=packetName.substring(packetName.lastIndexOf('.')+1); //L2Type Stringl2Type=null; if(eth.isBroadcast()){ l2Type=BROADCAST; } elseif(eth.isMulticast()){ l2Type=MULTICAST; } else{ l2Type=UNICAST; } //UsealiasforL3type //ValidEtherTypemustbegreaterthanorequalto0x0600 //ItisV1EthernetFrameifEtherType<0x0600 if(l3type<0x0600){ etherType="0599"; } if(TypeAnalyser.l3TypeAliasMap! =null&& TypeAnalyser.l3TypeAliasMap.containsKey(etherType)){ etherType=TypeAnalyser.l3TypeAliasMap.get(etherType); } else{ etherType="L3_"+etherType; } /
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- SDN 实践之floodlight控制器统计流量种类 实践 floodlight 控制器 统计 流量 种类