sdnのfloodlight控制器的流量数目统计Word格式.docx
《sdnのfloodlight控制器的流量数目统计Word格式.docx》由会员分享,可在线阅读,更多相关《sdnのfloodlight控制器的流量数目统计Word格式.docx(17页珍藏版)》请在冰豆网上搜索。
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{
protectedICounterStoreServicecounterStore;
protectedIFloodlightProviderServicefloodlightProvider;
protectedstaticLoggerlogger;
@Override
publicStringgetName(){
//TODOAuto-generatedmethodstub
returnTrafficAnalyser.class.getSimpleName();
}
publicbooleanisCallbackOrderingPrereq(OFTypetype,Stringname){
//TODOAuto-generatedmethodstub
returnfalse;
publicbooleanisCallbackOrderingPostreq(OFTypetype,Stringname){
publicCollection<
Class<
?
extendsIFloodlightService>
>
getModuleServices(){
returnnull;
publicMap<
IFloodlightService>
getServiceImpls(){
returnnull;
getModuleDependencies(){
Collection<
l=
newArrayList<
();
l.add(IFloodlightProviderService.class);
returnl;
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"
)
String,Object>
retrieve(){
StringcounterTitle=
(String)getRequestAttributes().get("
counterTitle"
);
Map<
model=newHashMap<
String,Object>
CounterValuev;
if(counterTitle.equalsIgnoreCase("
all"
)){
String,ICounter>
counters=this.counterStore.getAll();
if(counters!
=null){
Iterator<
Map.Entry<
it=
counters.entrySet().iterator();
while(it.hasNext()){
Entry<
entry=it.next();
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());
}
}
}else{
ICountercounter=this.counterStore.getCounter(counterTitle);
if(counter!
v=counter.getCounterValue();
v=newCounterValue(CounterValue.CounterType.LONG);
model.put(counterTitle,v.getLong());
model.put(counterTitle,v.getDouble());
returnmodel;
protectedvoiddoInit()throwsResourceException{
super.doInit();
counterStore=
(ICounterStoreService)getContext().getAttributes().
get(ICounterStoreService.class.getCanonicalName());
publicnet.floodlightcontroller.core.IListener.Commandreceive(IOFSwitchsw,OFMessagemsg,FloodlightContextcntx){
System.out.println(retrieve().toString());
returnCommand.CONTINUE;
这歌代码没有报错,可是,控制器只能连接到ovs,在mininet中用hosts去pingall的时候就会一下连接,一下断开,无法ping通。
于是就简化了一下代码,去掉觉得有bug的代码,抛出的异常是没有实例化;
代码如下:
returnTrafficAnalyser.class.getSimpleName();
publicCollection<
publicvoidstartUp(FloodlightModuleContextcontext){
if(CounterValue.CounterType.LONG==v.getType()){
model.put(counterName,v.getLong());
model.put(counterName,v.getDouble());
(ICounterStoreService)getContext().getAttributes().
用
sudomn--toposingle,3--mac--switchovsk--controller=remote,ip=10.0.2.15,port=6633
建立hosts去pingall
eclipse中控制台出来的信息截图如上,完整信息如下:
00:
58:
01.133INFO[n.f.c.m.FloodlightModuleLoader:
main]Loadingdefaultmodules
01.846INFO[n.f.c.i.Controller:
main]ControllerrolesettoMASTER
01.869INFO[n.f.c.i.Controller:
main]Flushswitchesonreconnect--Disabled
02.968ERROR[o.s.s.i.c.DelegatingCCProvider:
main]Failedtoinitializeproviderorg.sdnplatform.sync.internal.config.SyncStoreCCProvider
org.sdnplatform.sync.error.PersistException:
Couldnotinitializepersistentstorage
atorg.sdnplatform.sync.internal.store.JavaDBStorageEngine.<
init>
(JavaDBStorageEngine.java:
106)~[bin/:
na]
atorg.sdnplatform.sync.internal.StoreRegistry.register(StoreRegistry.java:
116)~[bin/:
atorg.sdnplatform.sync.internal.SyncManager.registerPersistentStore(SyncManager.java:
184)[bin/:
atorg.sdnplatform.sync.internal.config.SyncStoreCCProvider.init(SyncStoreCCProvider.java:
85)~[bin/:
atorg.sdnplatform.sync.internal.config.DelegatingCCProvider.init(DelegatingCCProvider.java:
37)