Skip to content
Snippets Groups Projects
Commit 59e7c41f authored by Alex Reimers's avatar Alex Reimers
Browse files

Add to the Topology REST API. You can now get tunnel links and broadcast domain ports. [#28640601]

parent bb29bd78
No related branches found
No related tags found
No related merge requests found
package net.floodlightcontroller.core.web.serializers;
import java.io.IOException;
import net.floodlightcontroller.topology.NodePortTuple;
import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.map.JsonSerializer;
import org.codehaus.jackson.map.SerializerProvider;
import org.openflow.util.HexString;
public class NodePortTupleJSONSerializer extends JsonSerializer<NodePortTuple> {
@Override
public void serialize(NodePortTuple ntp, JsonGenerator jgen,
SerializerProvider sp) throws IOException,
JsonProcessingException {
jgen.writeStartObject();
jgen.writeStringField("switch", HexString.toHexString(ntp.getNodeId()));
jgen.writeNumberField("port", ntp.getPortId());
jgen.writeEndObject();
}
@Override
public Class<NodePortTuple> handledType() {
return NodePortTuple.class;
}
}
......@@ -67,7 +67,6 @@ import net.floodlightcontroller.packet.Ethernet;
import net.floodlightcontroller.packet.IPv4;
import net.floodlightcontroller.packet.LLDP;
import net.floodlightcontroller.packet.LLDPTLV;
import net.floodlightcontroller.restserver.IRestApiService;
import net.floodlightcontroller.routing.IRoutingService;
import net.floodlightcontroller.storage.IResultSet;
import net.floodlightcontroller.storage.IStorageSourceService;
......@@ -75,7 +74,6 @@ import net.floodlightcontroller.storage.IStorageSourceListener;
import net.floodlightcontroller.storage.OperatorPredicate;
import net.floodlightcontroller.storage.StorageException;
import net.floodlightcontroller.threadpool.IThreadPoolService;
import net.floodlightcontroller.topology.web.TopologyWebRoutable;
import net.floodlightcontroller.util.EventHistory;
import net.floodlightcontroller.util.EventHistory.EvAction;
import net.floodlightcontroller.util.StackTraceUtil;
......@@ -143,7 +141,6 @@ public class LinkDiscoveryManager
protected IFloodlightProviderService floodlightProvider;
protected IStorageSourceService storageSource;
protected IRoutingService routingEngine;
protected IRestApiService restApi;
protected IThreadPoolService threadPool;
private static final byte[] LLDP_STANDARD_DST_MAC_STRING =
......@@ -1313,8 +1310,6 @@ public class LinkDiscoveryManager
IFloodlightService>();
// We are the class that implements the service
m.put(ILinkDiscoveryService.class, this);
//m.put(ITopologyService.class, this);
return m;
}
......@@ -1325,7 +1320,6 @@ public class LinkDiscoveryManager
l.add(IFloodlightProviderService.class);
l.add(IStorageSourceService.class);
l.add(IRoutingService.class);
l.add(IRestApiService.class);
l.add(IThreadPoolService.class);
return l;
}
......@@ -1336,7 +1330,6 @@ public class LinkDiscoveryManager
floodlightProvider = context.getServiceImpl(IFloodlightProviderService.class);
storageSource = context.getServiceImpl(IStorageSourceService.class);
routingEngine = context.getServiceImpl(IRoutingService.class);
restApi = context.getServiceImpl(IRestApiService.class);
threadPool = context.getServiceImpl(IThreadPoolService.class);
// We create this here because there is no ordering guarantee
......@@ -1440,13 +1433,6 @@ public class LinkDiscoveryManager
floodlightProvider.addOFSwitchListener(this);
floodlightProvider.addHAListener(this);
floodlightProvider.addInfoProvider("summary", this);
// init our rest api
if (restApi != null) {
restApi.addRestletRoutable(new TopologyWebRoutable());
} else {
log.error("Could not instantiate REST API");
}
setControllerTLV();
}
......
......@@ -51,8 +51,24 @@ public interface ITopologyService extends IFloodlightService {
*/
public boolean inSameIsland(long switch1, long switch2);
/**
* Adds a listener to get topology notifications
* @param listener The module that wants to listen for events
*/
public void addListener(ITopologyListener listener);
/**
* Gets the set of ports that belong to a broadcast domain.
* @return The set of ports that belong to a broadcast domain.
*/
public Set<NodePortTuple> getBroadcastDomainLinks();
/**
* Returns that set of links that are tunnel links.
* @return The set of links that are tunnel links.
*/
public Set<NodePortTuple> getTunnelLinks();
public boolean isBroadcastDomainPort(long sw, short port);
public boolean isAllowed(long sw, short portId);
......
......@@ -36,15 +36,14 @@ public class TopologyInstance {
protected Set<Long> switches;
protected Set<NodePortTuple> broadcastDomainPorts;
protected Set<NodePortTuple> tunnelPorts;
//protected Set<NodePortTuple> blockedPorts;
protected Set<Cluster> clusters; // set of clusters
protected Map<Long, Cluster> switchClusterMap; // switch to cluster map
// States for routing
protected Map<Long, BroadcastTree> destinationRootedTrees;
protected Map<Long, Set<NodePortTuple>> clusterBroadcastNodePorts;
protected Map<Long, BroadcastTree> clusterBroadcastTrees;
protected Map<Long, BroadcastTree> destinationRootedTrees; // DPID -> BroadcastTree
protected Map<Long, Set<NodePortTuple>> clusterBroadcastNodePorts; // ClusterID -> BroadcastTree
protected Map<Long, BroadcastTree> clusterBroadcastTrees; // ClusterID -> BroadcastTree
protected LRUHashMap<RouteId, Route> pathcache;
public TopologyInstance() {
......
......@@ -21,11 +21,13 @@ import net.floodlightcontroller.core.module.IFloodlightService;
import net.floodlightcontroller.core.util.SingletonTask;
import net.floodlightcontroller.linkdiscovery.ILinkDiscoveryListener;
import net.floodlightcontroller.linkdiscovery.ILinkDiscoveryService;
import net.floodlightcontroller.restserver.IRestApiService;
import net.floodlightcontroller.routing.BroadcastTree;
import net.floodlightcontroller.routing.IRoutingService;
import net.floodlightcontroller.routing.Link;
import net.floodlightcontroller.routing.Route;
import net.floodlightcontroller.threadpool.IThreadPoolService;
import net.floodlightcontroller.topology.web.TopologyWebRoutable;
import net.floodlightcontroller.util.StackTraceUtil;
......@@ -54,6 +56,7 @@ public class TopologyManager
protected ILinkDiscoveryService linkDiscovery;
protected IThreadPoolService threadPool;
protected IFloodlightProviderService floodlightProvider;
protected IRestApiService restApi;
// Modules that listen to our updates
protected ArrayList<ITopologyListener> topologyAware;
......@@ -261,11 +264,7 @@ public class TopologyManager
public Map<NodePortTuple, Set<Link>> getPortBroadcastDomainLinks() {
return portBroadcastDomainLinks;
}
public Map<NodePortTuple, Set<Link>> getTunnelLinks() {
return tunnelLinks;
}
public TopologyInstance getCurrentInstance() {
return currentInstance;
}
......@@ -297,7 +296,6 @@ public class TopologyManager
@Override
public Collection<Class<? extends IFloodlightService>> getModuleServices() {
// TODO Auto-generated method stub
Collection<Class<? extends IFloodlightService>> l =
new ArrayList<Class<? extends IFloodlightService>>();
l.add(ITopologyService.class);
......@@ -306,12 +304,10 @@ public class TopologyManager
}
@Override
public Map<Class<? extends IFloodlightService>, IFloodlightService>
getServiceImpls() {
public Map<Class<? extends IFloodlightService>, IFloodlightService> getServiceImpls() {
Map<Class<? extends IFloodlightService>,
IFloodlightService> m =
new HashMap<Class<? extends IFloodlightService>,
IFloodlightService>();
IFloodlightService> m =
new HashMap<Class<? extends IFloodlightService>, IFloodlightService>();
// We are the class that implements the service
m.put(ITopologyService.class, this);
m.put(IRoutingService.class, this);
......@@ -327,6 +323,7 @@ public class TopologyManager
l.add(ILinkDiscoveryService.class);
l.add(IThreadPoolService.class);
l.add(IFloodlightProviderService.class);
l.add(IRestApiService.class);
return l;
}
......@@ -336,6 +333,7 @@ public class TopologyManager
linkDiscovery = context.getServiceImpl(ILinkDiscoveryService.class);
threadPool = context.getServiceImpl(IThreadPoolService.class);
floodlightProvider = context.getServiceImpl(IFloodlightProviderService.class);
restApi = context.getServiceImpl(IRestApiService.class);
switchPorts = new HashMap<Long,Set<Short>>();
switchPortLinks = new HashMap<NodePortTuple, Set<Link>>();
......@@ -351,8 +349,13 @@ public class TopologyManager
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
......@@ -499,5 +502,15 @@ public class TopologyManager
break;
}
}
@Override
public Set<NodePortTuple> getBroadcastDomainLinks() {
return portBroadcastDomainLinks.keySet();
}
@Override
public Set<NodePortTuple> getTunnelLinks() {
return tunnelLinks.keySet();
}
}
package net.floodlightcontroller.topology.web;
import java.util.Set;
import net.floodlightcontroller.topology.ITopologyService;
import net.floodlightcontroller.topology.NodePortTuple;
import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;
public class BroadcastDomainResource extends ServerResource {
@Get("json")
public Set<NodePortTuple> retrieve() {
ITopologyService topology =
(ITopologyService)getContext().getAttributes().
get(ITopologyService.class.getCanonicalName());
return topology.getBroadcastDomainLinks();
}
}
package net.floodlightcontroller.topology.web;
import org.restlet.Context;
import org.restlet.Restlet;
import org.restlet.routing.Router;
import net.floodlightcontroller.linkdiscovery.web.LinksResource;
......@@ -12,10 +11,12 @@ public class TopologyWebRoutable implements RestletRoutable {
* Create the Restlet router and bind to the proper resources.
*/
@Override
public Restlet getRestlet(Context context) {
public Router getRestlet(Context context) {
Router router = new Router(context);
router.attach("/links/json", LinksResource.class);
router.attach("/tunnellinks/json", TunnelLinksResource.class);
router.attach("/switchclusters/json", SwitchClustersResource.class);
router.attach("/broadcastdomainports/json", BroadcastDomainResource.class);
return router;
}
......
package net.floodlightcontroller.topology.web;
import java.util.Set;
import net.floodlightcontroller.topology.ITopologyService;
import net.floodlightcontroller.topology.NodePortTuple;
import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;
public class TunnelLinksResource extends ServerResource {
@Get("json")
public Set<NodePortTuple> retrieve() {
ITopologyService topology =
(ITopologyService)getContext().getAttributes().
get(ITopologyService.class.getCanonicalName());
return topology.getTunnelLinks();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment