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")
publicMapretrieve(){
StringcounterTitle=
(String)getRequestAttributes().get("counterTitle");
Mapmodel=newHashMap();
CounterValuev;
if(counterTitle.equalsIgnoreCase("all")){
Mapcounters=this.counterStore.getAll();
if(counters!
=null){
Iterator>it=
counters.entrySet().iterator();
while(it.hasNext()){
Entryentry=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!
=null){
v=counter.getCounterValue();
}else{
v=newCounterValue(CounterValue.CounterType.LONG);
}
if(CounterValue.CounterType.LONG==v.getType()){
model.put(counterTitle,v.getLong());
}elseif(v.getType()==CounterValue.CounterType.DOUBLE){
model.put(counterTitle,v.getDouble());
}
}
returnmodel;
}
protectedvoiddoInit()throwsResourceException{
super.doInit();
counterStore=
(ICounterStoreService)getContext().getAttributes().
get(ICounterStoreService.class.getCanonicalName());
}
@Override
publicnet.floodlightcontroller.core.IListener.Commandreceive(IOFSwitchsw,OFMessagemsg,FloodlightContextcntx){
System.out.println(retrieve().toString());
returnCommand.CONTINUE;
}
}
这歌代码没有报错,可是,控制器只能连接到ovs,在mininet中用hosts去pingall的时候就会一下连接,一下断开,无法ping通。
于是就简化了一下代码,去掉觉得有bug的代码,抛出的异常是没有实例化;
代码如下:
packageedu.wzu.steve.trafficanalyser;
importjava.util.ArrayList;
importjava.util.Collection;
importjava.util.HashMap;
importjava.util.Iterator;
importjava.util.Map;
importjava.util.Map.Entry;
importorg.restlet.resource.ResourceException;
importorg.restlet.resource.ServerResource;
importnet.floodlightcontroller.counter.CounterValue;
importnet.floodlightcontroller.counter.ICounter;
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{
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
publicCollectionextendsIFloodlightService>>getModuleServices(){
//TODOAuto-generatedmethodstub
returnnull;
}
@Override
publicMapextendsIFloodlightService>,IFloodlightService>getServiceImpls(){
//TODOAuto-generatedmethodstub
returnnull;
}
@Override
publicCollectionextendsIFloodlightService>>getModuleDependencies(){
//TODOAuto-generatedmethodstub
CollectionextendsIFloodlightService>>l=
newArrayListextendsIFloodlightService>>();
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")
publicMapretrieve(){
Mapmodel=newHashMap();
CounterValuev;
Mapcounters=this.counterStore.getAll();
if(counters!
=null){
Iterator>it=
counters.entrySet().iterator();
while(it.hasNext()){
Entryentry=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());
}
}
}
returnmodel;
}
protectedvoiddoInit()throwsResourceException{
super.doInit();
counterStore=
(ICounterStoreService)getContext().getAttributes().
get(ICounterStoreService.class.getCanonicalName());
}
@Override
publicnet.floodlightcontroller.core.IListener.Commandreceive(IOFSwitchsw,OFMessagemsg,FloodlightContextcntx){
System.out.println(retrieve().toString());
returnCommand.CONTINUE;
}
}
用
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
00:
58:
01.846INFO[n.f.c.i.Controller:
main]ControllerrolesettoMASTER
00:
58:
01.869INFO[n.f.c.i.Controller:
main]Flushswitchesonreconnect--Disabled
00:
58:
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.(JavaDBStorageEngine.java:
106)~[bin/:
na]
atorg.sdnplatform.sync.internal.StoreRegistry.register(StoreRegistry.java:
116)~[bin/:
na]
atorg.sdnplatform.sync.internal.SyncManager.registerPersistentStore(SyncManager.java:
184)[bin/:
na]
atorg.sdnplatform.sync.internal.config.SyncStoreCCProvider.init(SyncStoreCCProvider.java:
85)~[bin/:
na]
atorg.sdnplatform.sync.internal.config.DelegatingCCProvider.init(DelegatingCCProvider.java:
37)