public TopologyInstance getCurrentInstance() {
return currentInstance;
}
<<<<<<< HEAD
=======
//
// ILinkDiscoveryListener interface methods
//
public void linkDiscoveryUpdate(LDUpdate update) {
boolean scheduleFlag = false;
// if there's no udpates in the queue, then
// we need to schedule an update.
if (ldUpdates.peek() == null)
scheduleFlag = true;
if (log.isTraceEnabled()) {
log.trace("Queuing update: {}", update);
}
ldUpdates.add(update);
if (scheduleFlag) {
newInstanceTask.reschedule(1, TimeUnit.MICROSECONDS);
}
}
//
// IFloodlightModule interfaces
//
@Override
public Collection> getModuleServices() {
l.add(IRoutingService.class);
return l;
}
@Override
@Override
new ArrayList>();
l.add(ITopologyService.class);
Collection> l =
public Map, IFloodlightService> getServiceImpls() {
Map,
IFloodlightService> m =
new HashMap, IFloodlightService>();
// We are the class that implements the service
m.put(ITopologyService.class, this);
m.put(IRoutingService.class, this);
return m;
}
@Override
public Collection>
getModuleDependencies() {
Collection> l =
new ArrayList>();
l.add(ILinkDiscoveryService.class);
l.add(IThreadPoolService.class);
l.add(IFloodlightProviderService.class);
l.add(IRestApiService.class);
return l;
}
@Override
public void init(FloodlightModuleContext context)
throws FloodlightModuleException {
linkDiscovery = context.getServiceImpl(ILinkDiscoveryService.class);
threadPool = context.getServiceImpl(IThreadPoolService.class);
floodlightProvider = context.getServiceImpl(IFloodlightProviderService.class);
restApi = context.getServiceImpl(IRestApiService.class);
switchPorts = new HashMap>();
switchPortLinks = new HashMap>();
portBroadcastDomainLinks = new HashMap>();
tunnelLinks = new HashMap>();
topologyAware = new ArrayList();
ldUpdates = new LinkedBlockingQueue();
}
@Override
public void startUp(FloodlightModuleContext context) {
ScheduledExecutorService ses = threadPool.getScheduledExecutor();
newInstanceTask = new SingletonTask(ses, new NewInstanceWorker());
linkDiscovery.addListener(this);
floodlightProvider.addHAListener(this);
addWebRoutable();
newInstanceTask.reschedule(1, TimeUnit.MILLISECONDS);
}
protected void addWebRoutable() {
restApi.addRestletRoutable(new TopologyWebRoutable());
}
//
// ITopologyService interface methods
//
@Override
public boolean isInternal(long switchid, short port) {
return currentInstance.isInternal(switchid, port);
}
@Override
public long getSwitchClusterId(long switchId) {
return currentInstance.getSwitchClusterId(switchId);
}
@Override
public Set getSwitchesInCluster(long switchId) {
return currentInstance.getSwitchesInCluster(switchId);
}
@Override
public boolean inSameCluster(long switch1, long switch2) {
return currentInstance.inSameCluster(switch1, switch2);
}
@Override
public void addListener(ITopologyListener listener) {
topologyAware.add(listener);
}
@Override
public boolean isAllowed(long sw, short portId) {
return currentInstance.isAllowed(sw, portId);
}
@Override
public NodePortTuple getAllowedOutgoingBroadcastPort(long src,
short srcPort,
long dst,
short dstPort) {
return currentInstance.getAllowedOutgoingBroadcastPort(src,srcPort,
dst,dstPort);
}
public NodePortTuple getAllowedIncomingBroadcastPort(long src,
short srcPort) {
return currentInstance.getAllowedIncomingBroadcastPort(src,srcPort);
}
@Override
public boolean isIncomingBroadcastAllowed(long sw, short portId) {
return currentInstance.isIncomingBroadcastAllowedOnSwitchPort(sw, portId);
}
@Override
public Set getPorts(long sw) {
return currentInstance.getPorts(sw);
}
public Set getBroadcastPorts(long targetSw, long src, short srcPort) {
return currentInstance.getBroadcastPorts(targetSw, src, srcPort);
}
//
// IRoutingService interface methods
//
@Override
public Route getRoute(long src, long dst) {
Route r = currentInstance.getRoute(src, dst);
return r;
}
@Override
public boolean routeExists(long src, long dst) {
return currentInstance.routeExists(src, dst);
}
@Override
public BroadcastTree getBroadcastTreeForCluster(long clusterId) {
return currentInstance.getBroadcastTreeForCluster(clusterId);
}
@Override
public boolean isInSameBroadcastDomain(long s1, short p1, long s2, short p2) {
return currentInstance.isInSameBroadcastDomain(s1, p1, s2, p2);
}
@Override
public NodePortTuple getOutgoingSwitchPort(long src, short srcPort,
long dst, short dstPort) {
// Use this function to redirect traffic if needed.
return currentInstance.getOutgoingSwitchPort(src, srcPort, dst, dstPort);
}
@Override
public NodePortTuple getIncomingSwitchPort(long src, short srcPort,
long dst, short dstPort) {
return currentInstance.getIncomingSwitchPort(src, srcPort, dst, dstPort);
}
@Override
public boolean isBroadcastDomainPort(long sw, short port) {
return currentInstance.isBroadcastDomainPort(new NodePortTuple(sw, port));
}
@Override
public boolean isConsistent(long oldSw, short oldPort, long newSw,
short newPort) {
return currentInstance.isConsistent(oldSw, oldPort, newSw, newPort);
}
@Override
public boolean inSameIsland(long switch1, long switch2) {
return currentInstance.inSameIsland(switch1, switch2);
}
/**
* Clears the current topology. Note that this does NOT
* send out updates.
*/
public void clearCurrentTopology() {
switchPorts.clear();
switchPortLinks.clear();
portBroadcastDomainLinks.clear();
tunnelLinks.clear();
createNewInstance();
}
// IHAListener
@Override
public void roleChanged(Role oldRole, Role newRole) {
switch(newRole) {
case MASTER:
if (oldRole == Role.SLAVE) {
log.debug("Re-computing topology due " +
"to HA change from SLAVE->MASTER");
newInstanceTask.reschedule(1, TimeUnit.MILLISECONDS);
}
break;
case SLAVE:
log.debug("Clearing topology due to " +
"HA change to SLAVE");
clearCurrentTopology();
break;
}
}
@Override
public void controllerNodeIPsChanged(
Map curControllerNodeIPs,
Map addedControllerNodeIPs,
Map removedControllerNodeIPs) {
// ignore
}
@Override
public Set getBroadcastDomainLinks() {
return portBroadcastDomainLinks.keySet();
}
@Override
public Set getTunnelLinks() {
return tunnelLinks.keySet();
}
>>>>>>> d54c2c80d3397071e2b1a9ae1d8538bc13bcfcda
}
|