Search in sources :

Example 1 with Topology

use of org.onosproject.net.topology.Topology in project onos by opennetworkinglab.

the class EventsCommand method printEvent.

private void printEvent(Event<?, ?> event) {
    if (event instanceof DeviceEvent) {
        DeviceEvent deviceEvent = (DeviceEvent) event;
        if (event.type().toString().startsWith("PORT")) {
            // Port event
            print("%s %s\t%s/%s [%s]", Tools.defaultOffsetDataTime(event.time()), event.type(), deviceEvent.subject().id(), deviceEvent.port().number(), deviceEvent.port());
        } else {
            // Device event
            print("%s %s\t%s [%s]", Tools.defaultOffsetDataTime(event.time()), event.type(), deviceEvent.subject().id(), deviceEvent.subject());
        }
    } else if (event instanceof MastershipEvent) {
        print("%s %s\t%s [%s]", Tools.defaultOffsetDataTime(event.time()), event.type(), event.subject(), ((MastershipEvent) event).roleInfo());
    } else if (event instanceof LinkEvent) {
        LinkEvent linkEvent = (LinkEvent) event;
        Link link = linkEvent.subject();
        print("%s %s\t%s/%s-%s/%s [%s]", Tools.defaultOffsetDataTime(event.time()), event.type(), link.src().deviceId(), link.src().port(), link.dst().deviceId(), link.dst().port(), link);
    } else if (event instanceof HostEvent) {
        HostEvent hostEvent = (HostEvent) event;
        print("%s %s\t%s [%s->%s]", Tools.defaultOffsetDataTime(event.time()), event.type(), hostEvent.subject().id(), hostEvent.prevSubject(), hostEvent.subject());
    } else if (event instanceof TopologyEvent) {
        TopologyEvent topoEvent = (TopologyEvent) event;
        List<Event> reasons = MoreObjects.firstNonNull(topoEvent.reasons(), ImmutableList.<Event>of());
        Topology topo = topoEvent.subject();
        String summary = String.format("(d=%d,l=%d,c=%d)", topo.deviceCount(), topo.linkCount(), topo.clusterCount());
        print("%s %s%s [%s]", Tools.defaultOffsetDataTime(event.time()), event.type(), summary, reasons.stream().map(e -> e.type()).collect(toList()));
    } else if (event instanceof ClusterEvent) {
        print("%s %s\t%s [%s]", Tools.defaultOffsetDataTime(event.time()), event.type(), ((ClusterEvent) event).subject().id(), event.subject());
    } else {
        // Unknown Event?
        print("%s %s\t%s [%s]", Tools.defaultOffsetDataTime(event.time()), event.type(), event.subject(), event);
    }
}
Also used : DeviceEvent(org.onosproject.net.device.DeviceEvent) HostEvent(org.onosproject.net.host.HostEvent) ClusterEvent(org.onosproject.cluster.ClusterEvent) LinkEvent(org.onosproject.net.link.LinkEvent) MastershipEvent(org.onosproject.mastership.MastershipEvent) TopologyEvent(org.onosproject.net.topology.TopologyEvent) IntentEvent(org.onosproject.net.intent.IntentEvent) LinkEvent(org.onosproject.net.link.LinkEvent) MastershipEvent(org.onosproject.mastership.MastershipEvent) HostEvent(org.onosproject.net.host.HostEvent) Event(org.onosproject.event.Event) TopologyEvent(org.onosproject.net.topology.TopologyEvent) ClusterEvent(org.onosproject.cluster.ClusterEvent) DeviceEvent(org.onosproject.net.device.DeviceEvent) Topology(org.onosproject.net.topology.Topology) Link(org.onosproject.net.Link)

Example 2 with Topology

use of org.onosproject.net.topology.Topology in project onos by opennetworkinglab.

the class EventsCommand method doExecute.

@Override
protected void doExecute() {
    EventHistoryService eventHistoryService = get(EventHistoryService.class);
    Stream<Event<?, ?>> events = eventHistoryService.history().stream();
    boolean dumpAll = all || !(mastership || device || link || topology || host || cluster || intent);
    if (!dumpAll) {
        Predicate<Event<?, ?>> filter = (defaultIs) -> false;
        if (mastership) {
            filter = filter.or(evt -> evt instanceof MastershipEvent);
        }
        if (device) {
            filter = filter.or(evt -> evt instanceof DeviceEvent);
        }
        if (link) {
            filter = filter.or(evt -> evt instanceof LinkEvent);
        }
        if (topology) {
            filter = filter.or(evt -> evt instanceof TopologyEvent);
        }
        if (host) {
            filter = filter.or(evt -> evt instanceof HostEvent);
        }
        if (cluster) {
            filter = filter.or(evt -> evt instanceof ClusterEvent);
        }
        if (intent) {
            filter = filter.or(evt -> evt instanceof IntentEvent);
        }
        events = events.filter(filter);
    }
    if (maxSize > 0) {
        events = events.limit(maxSize);
    }
    if (outputJson()) {
        ArrayNode jsonEvents = events.map(this::json).collect(toArrayNode());
        printJson(jsonEvents);
    } else {
        events.forEach(this::printEvent);
    }
}
Also used : Tools(org.onlab.util.Tools) IntentEvent(org.onosproject.net.intent.IntentEvent) LinkEvent(org.onosproject.net.link.LinkEvent) Link(org.onosproject.net.Link) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Command(org.apache.karaf.shell.api.action.Command) MastershipEvent(org.onosproject.mastership.MastershipEvent) Topology(org.onosproject.net.topology.Topology) ImmutableList(com.google.common.collect.ImmutableList) HostEvent(org.onosproject.net.host.HostEvent) JsonNode(com.fasterxml.jackson.databind.JsonNode) Collector(java.util.stream.Collector) Event(org.onosproject.event.Event) PrintWriter(java.io.PrintWriter) TopologyEvent(org.onosproject.net.topology.TopologyEvent) ClusterEvent(org.onosproject.cluster.ClusterEvent) Predicate(java.util.function.Predicate) StringWriter(java.io.StringWriter) MoreObjects(com.google.common.base.MoreObjects) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) Service(org.apache.karaf.shell.api.action.lifecycle.Service) DeviceEvent(org.onosproject.net.device.DeviceEvent) Option(org.apache.karaf.shell.api.action.Option) DeviceEvent(org.onosproject.net.device.DeviceEvent) MastershipEvent(org.onosproject.mastership.MastershipEvent) TopologyEvent(org.onosproject.net.topology.TopologyEvent) HostEvent(org.onosproject.net.host.HostEvent) ClusterEvent(org.onosproject.cluster.ClusterEvent) LinkEvent(org.onosproject.net.link.LinkEvent) IntentEvent(org.onosproject.net.intent.IntentEvent) LinkEvent(org.onosproject.net.link.LinkEvent) MastershipEvent(org.onosproject.mastership.MastershipEvent) HostEvent(org.onosproject.net.host.HostEvent) Event(org.onosproject.event.Event) TopologyEvent(org.onosproject.net.topology.TopologyEvent) ClusterEvent(org.onosproject.cluster.ClusterEvent) DeviceEvent(org.onosproject.net.device.DeviceEvent) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) IntentEvent(org.onosproject.net.intent.IntentEvent)

Example 3 with Topology

use of org.onosproject.net.topology.Topology in project onos by opennetworkinglab.

the class MQUtil method json.

/**
 * Returns a JSON representation of the given topology event.
 *
 * @param  event the topology event
 * @return       the topology event json message
 */
public static JsonObject json(TopologyEvent event) {
    Topology topology = event.subject();
    JsonObject jo = new JsonObject();
    jo.addProperty(TOPO_TYPE, TopologyEvent.Type.TOPOLOGY_CHANGED.name());
    jo.addProperty(CLUSTER_COUNT, topology.clusterCount());
    jo.addProperty(COMPUTE_COST, topology.computeCost());
    jo.addProperty(CREATE_TIME, new Date(topology.creationTime()).toString());
    jo.addProperty(DEVICE_COUNT, topology.deviceCount());
    jo.addProperty(LINK_COUNT, topology.linkCount());
    jo.addProperty(AVAILABLE, new Date(topology.time()).toString());
    return jo;
}
Also used : JsonObject(com.google.gson.JsonObject) Topology(org.onosproject.net.topology.Topology) Date(java.util.Date)

Example 4 with Topology

use of org.onosproject.net.topology.Topology in project onos by opennetworkinglab.

the class VirtualNetworkTopologyManagerTest method testGetDisjointPaths.

/**
 * Test getDisjointPaths() methods.
 */
@Test
public void testGetDisjointPaths() {
    VirtualNetwork virtualNetwork = setupVirtualNetworkTopology();
    TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class);
    Topology topology = topologyService.currentTopology();
    VirtualDevice srcVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID1);
    VirtualDevice dstVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID2);
    // test the getDisjointPaths() method.
    Set<DisjointPath> paths = topologyService.getDisjointPaths(topology, srcVirtualDevice.id(), dstVirtualDevice.id());
    assertNotNull("The paths should not be null.", paths);
    assertEquals("The paths size did not match.", 1, paths.size());
    // test the getDisjointPaths() method using a weight.
    LinkWeigher weight = new LinkWeigherAdapter(1.0);
    Set<DisjointPath> paths1 = topologyService.getDisjointPaths(topology, srcVirtualDevice.id(), dstVirtualDevice.id(), weight);
    assertNotNull("The paths should not be null.", paths1);
    assertEquals("The paths size did not match.", 1, paths1.size());
}
Also used : VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) LinkWeigherAdapter(org.onosproject.net.topology.LinkWeigherAdapter) LinkWeigher(org.onosproject.net.topology.LinkWeigher) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) Topology(org.onosproject.net.topology.Topology) DisjointPath(org.onosproject.net.DisjointPath) TopologyService(org.onosproject.net.topology.TopologyService) Test(org.junit.Test)

Example 5 with Topology

use of org.onosproject.net.topology.Topology in project onos by opennetworkinglab.

the class VirtualNetworkTopologyManagerTest method testGetClusters.

/**
 * Test getClusters() method.
 */
@Test
public void testGetClusters() {
    VirtualNetwork virtualNetwork = setupVirtualNetworkTopology();
    TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class);
    Topology topology = topologyService.currentTopology();
    // test the getClusters() method.
    assertNotNull("The clusters should not be null.", topologyService.getClusters(topology));
    assertEquals("The clusters size did not match.", 2, topologyService.getClusters(topology).size());
}
Also used : VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) Topology(org.onosproject.net.topology.Topology) TopologyService(org.onosproject.net.topology.TopologyService) Test(org.junit.Test)

Aggregations

Topology (org.onosproject.net.topology.Topology)44 TopologyService (org.onosproject.net.topology.TopologyService)30 Test (org.junit.Test)29 VirtualNetwork (org.onosproject.incubator.net.virtual.VirtualNetwork)23 VirtualDevice (org.onosproject.incubator.net.virtual.VirtualDevice)12 TopologyCluster (org.onosproject.net.topology.TopologyCluster)11 DisjointPath (org.onosproject.net.DisjointPath)9 ConnectPoint (org.onosproject.net.ConnectPoint)8 Path (org.onosproject.net.Path)8 GET (javax.ws.rs.GET)7 Produces (javax.ws.rs.Produces)7 Link (org.onosproject.net.Link)7 Path (javax.ws.rs.Path)6 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 VirtualLink (org.onosproject.incubator.net.virtual.VirtualLink)5 DeviceId (org.onosproject.net.DeviceId)5 LinkWeigher (org.onosproject.net.topology.LinkWeigher)4 Event (org.onosproject.event.Event)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 ClusterEvent (org.onosproject.cluster.ClusterEvent)2