Search in sources :

Example 6 with Link

use of org.onosproject.net.Link in project onos by opennetworkinglab.

the class OpticalConnectivityTest method testCreate.

/**
 * Checks the construction of OpticalConnectivity object.
 */
@Test
public void testCreate() {
    Bandwidth bandwidth = Bandwidth.bps(100);
    Duration latency = Duration.ofMillis(10);
    // Mock 3-nodes linear topology
    ConnectPoint cp12 = createConnectPoint(1, 2);
    ConnectPoint cp21 = createConnectPoint(2, 1);
    ConnectPoint cp22 = createConnectPoint(2, 2);
    ConnectPoint cp31 = createConnectPoint(3, 1);
    Link link1 = createLink(cp12, cp21);
    Link link2 = createLink(cp22, cp31);
    List<Link> links = Stream.of(link1, link2).collect(Collectors.toList());
    OpticalConnectivityId cid = OpticalConnectivityId.of(1L);
    OpticalConnectivity oc = new OpticalConnectivity(cid, links, bandwidth, latency, Collections.emptySet(), Collections.emptySet());
    assertNotNull(oc);
    assertEquals(oc.id(), cid);
    assertEquals(oc.links(), links);
    assertEquals(oc.bandwidth(), bandwidth);
    assertEquals(oc.latency(), latency);
}
Also used : OpticalConnectivityId(org.onosproject.newoptical.api.OpticalConnectivityId) Bandwidth(org.onlab.util.Bandwidth) Duration(java.time.Duration) ConnectPoint(org.onosproject.net.ConnectPoint) Link(org.onosproject.net.Link) DefaultLink(org.onosproject.net.DefaultLink) Test(org.junit.Test)

Example 7 with Link

use of org.onosproject.net.Link in project onos by opennetworkinglab.

the class OpticalConnectivityTest method testLinkEstablishedByConnectivityIntent.

/**
 * Checks that isAllRealizingLink(Not)Established works for OpticalConnectivityIntent.
 */
@Test
public void testLinkEstablishedByConnectivityIntent() {
    // Mock 7-nodes linear topology
    ConnectPoint cp12 = createConnectPoint(1, 2);
    ConnectPoint cp21 = createConnectPoint(2, 1);
    ConnectPoint cp22 = createConnectPoint(2, 2);
    ConnectPoint cp31 = createConnectPoint(3, 1);
    ConnectPoint cp32 = createConnectPoint(3, 2);
    ConnectPoint cp41 = createConnectPoint(4, 1);
    ConnectPoint cp42 = createConnectPoint(4, 2);
    ConnectPoint cp51 = createConnectPoint(5, 1);
    ConnectPoint cp52 = createConnectPoint(5, 2);
    ConnectPoint cp61 = createConnectPoint(6, 1);
    ConnectPoint cp62 = createConnectPoint(6, 2);
    ConnectPoint cp71 = createConnectPoint(7, 1);
    Link link1 = createLink(cp12, cp21);
    Link link2 = createLink(cp22, cp31);
    Link link3 = createLink(cp32, cp41);
    Link link4 = createLink(cp42, cp51);
    Link link5 = createLink(cp52, cp61);
    Link link6 = createLink(cp62, cp71);
    List<Link> links = Stream.of(link1, link2, link3, link4, link5, link6).collect(Collectors.toList());
    // Mocks 2 intents to create OduCtl connectivity
    OpticalConnectivityIntent connIntent1 = createConnectivityIntent(cp21, cp32);
    PacketLinkRealizedByOptical oduLink1 = PacketLinkRealizedByOptical.create(cp12, cp41, connIntent1);
    OpticalConnectivityIntent connIntent2 = createConnectivityIntent(cp51, cp62);
    PacketLinkRealizedByOptical oduLink2 = PacketLinkRealizedByOptical.create(cp42, cp71, connIntent2);
    Set<PacketLinkRealizedByOptical> plinks = ImmutableSet.of(oduLink1, oduLink2);
    Bandwidth bandwidth = Bandwidth.bps(100);
    Duration latency = Duration.ofMillis(10);
    OpticalConnectivityId cid = OpticalConnectivityId.of(1L);
    OpticalConnectivity oc1 = new OpticalConnectivity(cid, links, bandwidth, latency, plinks, Collections.emptySet());
    assertTrue(oc1.isAllRealizingLinkNotEstablished());
    assertFalse(oc1.isAllRealizingLinkEstablished());
    // Sets link realized by connIntent1 to be established
    OpticalConnectivity oc2 = oc1.setLinkEstablished(cp12, cp41, true);
    assertFalse(oc2.isAllRealizingLinkNotEstablished());
    assertFalse(oc2.isAllRealizingLinkEstablished());
    // Sets link realized by connIntent2 to be established
    OpticalConnectivity oc3 = oc2.setLinkEstablished(cp42, cp71, true);
    assertFalse(oc3.isAllRealizingLinkNotEstablished());
    assertTrue(oc3.isAllRealizingLinkEstablished());
}
Also used : OpticalConnectivityId(org.onosproject.newoptical.api.OpticalConnectivityId) Bandwidth(org.onlab.util.Bandwidth) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) Duration(java.time.Duration) ConnectPoint(org.onosproject.net.ConnectPoint) Link(org.onosproject.net.Link) DefaultLink(org.onosproject.net.DefaultLink) Test(org.junit.Test)

Example 8 with Link

use of org.onosproject.net.Link in project onos by opennetworkinglab.

the class OpticalPathProvisionerTest method testGetPath.

/**
 * Checks getPath method works.
 */
@Test
public void testGetPath() {
    Bandwidth bandwidth = Bandwidth.bps(100);
    Duration latency = Duration.ofMillis(10);
    List<Link> links = Stream.of(LINK1, LINK2, LINK3, LINK4, LINK5, LINK6).collect(Collectors.toList());
    OpticalConnectivityId cid = target.setupConnectivity(CP12, CP71, bandwidth, latency);
    Optional<List<Link>> path = target.getPath(cid);
    // Checks returned path is as expected
    assertTrue(path.isPresent());
    assertEquals(links, path.get());
}
Also used : OpticalConnectivityId(org.onosproject.newoptical.api.OpticalConnectivityId) Bandwidth(org.onlab.util.Bandwidth) Duration(java.time.Duration) ArrayList(java.util.ArrayList) List(java.util.List) DefaultLink(org.onosproject.net.DefaultLink) Link(org.onosproject.net.Link) Test(org.junit.Test)

Example 9 with Link

use of org.onosproject.net.Link 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 10 with Link

use of org.onosproject.net.Link 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)

Aggregations

Link (org.onosproject.net.Link)172 ConnectPoint (org.onosproject.net.ConnectPoint)75 Test (org.junit.Test)66 DefaultLink (org.onosproject.net.DefaultLink)44 Intent (org.onosproject.net.intent.Intent)40 DeviceId (org.onosproject.net.DeviceId)39 TrafficSelector (org.onosproject.net.flow.TrafficSelector)27 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)26 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)26 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)26 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)26 LinkCollectionIntent (org.onosproject.net.intent.LinkCollectionIntent)26 FlowRuleIntent (org.onosproject.net.intent.FlowRuleIntent)24 List (java.util.List)23 LinkKey (org.onosproject.net.LinkKey)23 Set (java.util.Set)22 DefaultPath (org.onosproject.net.DefaultPath)20 FlowRule (org.onosproject.net.flow.FlowRule)20 Collectors (java.util.stream.Collectors)19 PathIntent (org.onosproject.net.intent.PathIntent)18