Search in sources :

Example 76 with Link

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

the class LinkCollectionIntentFlowObjectiveCompilerTest method singleHopTestForMp.

/**
 * Multiple point to single point intent with only one switch.
 * We test the proper compilation of mp2sp with
 * trivial selector, trivial treatment and 1 hop.
 */
@Test
public void singleHopTestForMp() {
    Set<Link> testLinks = ImmutableSet.of();
    Set<FilteredConnectPoint> ingress = ImmutableSet.of(new FilteredConnectPoint(of1p1, vlan100Selector), new FilteredConnectPoint(of1p2, vlan100Selector));
    Set<FilteredConnectPoint> egress = ImmutableSet.of(new FilteredConnectPoint(of1p3, vlan100Selector));
    LinkCollectionIntent intent = LinkCollectionIntent.builder().appId(appId).selector(ethDstSelector).treatment(treatment).links(testLinks).filteredIngressPoints(ingress).filteredEgressPoints(egress).build();
    List<Intent> result = compiler.compile(intent, Collections.emptyList());
    assertThat(result, hasSize(1));
    assertThat(result.get(0), instanceOf(FlowObjectiveIntent.class));
    FlowObjectiveIntent foIntent = (FlowObjectiveIntent) result.get(0);
    List<Objective> objectives = foIntent.objectives();
    assertThat(objectives, hasSize(6));
    TrafficSelector expectSelector = DefaultTrafficSelector.builder(ethDstSelector).matchInPort(PortNumber.portNumber(1)).matchVlanId(VLAN_100).build();
    TrafficTreatment expectTreatment = DefaultTrafficTreatment.builder().setOutput(PortNumber.portNumber(3)).build();
    /*
         * First set of objective
         */
    filteringObjective = (FilteringObjective) objectives.get(0);
    forwardingObjective = (ForwardingObjective) objectives.get(1);
    nextObjective = (NextObjective) objectives.get(2);
    PortCriterion inPortCriterion = (PortCriterion) expectSelector.getCriterion(Criterion.Type.IN_PORT);
    // test case for first filtering objective
    checkFiltering(filteringObjective, inPortCriterion, intent.priority(), null, appId, true, vlan100Selector.criteria());
    // test case for first next objective
    checkNext(nextObjective, SIMPLE, expectTreatment, expectSelector, ADD);
    // test case for first forwarding objective
    checkForward(forwardingObjective, ADD, expectSelector, nextObjective.id(), SPECIFIC);
    /*
         * Second set of objective
         */
    filteringObjective = (FilteringObjective) objectives.get(3);
    forwardingObjective = (ForwardingObjective) objectives.get(4);
    nextObjective = (NextObjective) objectives.get(5);
    expectSelector = DefaultTrafficSelector.builder(ethDstSelector).matchInPort(PortNumber.portNumber(2)).matchVlanId(VLAN_100).build();
    inPortCriterion = (PortCriterion) expectSelector.getCriterion(Criterion.Type.IN_PORT);
    // test case for first filtering objective
    checkFiltering(filteringObjective, inPortCriterion, intent.priority(), null, appId, true, vlan100Selector.criteria());
    // test case for first next objective
    checkNext(nextObjective, SIMPLE, expectTreatment, expectSelector, ADD);
    // test case for first forwarding objective
    checkForward(forwardingObjective, ADD, expectSelector, nextObjective.id(), SPECIFIC);
}
Also used : FlowObjectiveIntent(org.onosproject.net.intent.FlowObjectiveIntent) Intent(org.onosproject.net.intent.Intent) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) FlowObjectiveIntent(org.onosproject.net.intent.FlowObjectiveIntent) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) Objective(org.onosproject.net.flowobjective.Objective) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Link(org.onosproject.net.Link) DefaultLink(org.onosproject.net.DefaultLink) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) Test(org.junit.Test)

Example 77 with Link

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

the class ObjectiveTrackerTest method testEventLinkDownMatch.

/**
 * Tests an event for a link down where the link matches existing intents.
 *
 * @throws InterruptedException if the latch wait fails.
 */
@Test
public void testEventLinkDownMatch() throws Exception {
    final Link link = link("src", 1, "dst", 2);
    final LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link);
    reasons.add(linkEvent);
    final TopologyEvent event = new TopologyEvent(TopologyEvent.Type.TOPOLOGY_CHANGED, topology, reasons);
    final Key key = Key.of(0x333L, APP_ID);
    Collection<NetworkResource> resources = ImmutableSet.of(link);
    tracker.addTrackedResources(key, resources);
    listener.event(event);
    assertThat(delegate.latch.await(WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS), is(true));
    assertThat(delegate.intentIdsFromEvent, hasSize(1));
    assertThat(delegate.compileAllFailedFromEvent, is(false));
    assertThat(delegate.intentIdsFromEvent.get(0).toString(), equalTo("0x333"));
}
Also used : NetworkResource(org.onosproject.net.NetworkResource) LinkEvent(org.onosproject.net.link.LinkEvent) TopologyEvent(org.onosproject.net.topology.TopologyEvent) Link(org.onosproject.net.Link) Key(org.onosproject.net.intent.Key) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 78 with Link

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

the class ObjectiveTrackerTest method testEventLinkDownNoMatches.

/**
 * Tests an event for a link down where none of the reasons match
 * currently installed intents.
 *
 * @throws InterruptedException if the latch wait fails.
 */
@Test
public void testEventLinkDownNoMatches() throws InterruptedException {
    final Link link = link("src", 1, "dst", 2);
    final LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link);
    reasons.add(linkEvent);
    final TopologyEvent event = new TopologyEvent(TopologyEvent.Type.TOPOLOGY_CHANGED, topology, reasons);
    listener.event(event);
    assertThat(delegate.latch.await(WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS), is(true));
    assertThat(delegate.intentIdsFromEvent, hasSize(0));
    assertThat(delegate.compileAllFailedFromEvent, is(false));
}
Also used : LinkEvent(org.onosproject.net.link.LinkEvent) TopologyEvent(org.onosproject.net.topology.TopologyEvent) Link(org.onosproject.net.Link) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 79 with Link

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

the class HostToHostIntentCompilerTest method testSingleLongPathCompilation.

/**
 * Tests a pair of hosts with 8 hops between them.
 */
@Test
public void testSingleLongPathCompilation() {
    HostToHostIntent intent = makeIntent(HOST_ONE, HOST_TWO);
    assertThat(intent, is(notNullValue()));
    String[] hops = { HOST_ONE, S1, S2, S3, S4, S5, S6, S7, S8, HOST_TWO };
    HostToHostIntentCompiler compiler = makeCompiler(hops);
    assertThat(compiler, is(notNullValue()));
    List<Intent> result = compiler.compile(intent, null);
    assertThat(result, is(Matchers.notNullValue()));
    assertThat(result, hasSize(2));
    Intent forwardIntent = result.get(0);
    assertThat(forwardIntent instanceof LinkCollectionIntent, is(true));
    Intent reverseIntent = result.get(1);
    assertThat(reverseIntent instanceof LinkCollectionIntent, is(true));
    LinkCollectionIntent forwardLCIntent = (LinkCollectionIntent) forwardIntent;
    Set<Link> links = forwardLCIntent.links();
    assertThat(links, hasSize(7));
    Set<FilteredConnectPoint> ingressPoints = ImmutableSet.of(new FilteredConnectPoint(new ConnectPoint(DID_S1, PORT_1)));
    assertThat(forwardLCIntent.filteredIngressPoints(), is(ingressPoints));
    assertThat(links, linksHasPath(S1, S2));
    assertThat(links, linksHasPath(S2, S3));
    assertThat(links, linksHasPath(S3, S4));
    assertThat(links, linksHasPath(S4, S5));
    assertThat(links, linksHasPath(S5, S6));
    assertThat(links, linksHasPath(S6, S7));
    assertThat(links, linksHasPath(S7, S8));
    Set<FilteredConnectPoint> egressPoints = ImmutableSet.of(new FilteredConnectPoint(new ConnectPoint(DID_S8, PORT_2)));
    assertThat(forwardLCIntent.filteredEgressPoints(), is(egressPoints));
    LinkCollectionIntent reverseLCIntent = (LinkCollectionIntent) reverseIntent;
    links = reverseLCIntent.links();
    assertThat(reverseLCIntent.links(), hasSize(7));
    ingressPoints = ImmutableSet.of(new FilteredConnectPoint(new ConnectPoint(DID_S8, PORT_2)));
    assertThat(reverseLCIntent.filteredIngressPoints(), is(ingressPoints));
    assertThat(links, linksHasPath(S2, S1));
    assertThat(links, linksHasPath(S3, S2));
    assertThat(links, linksHasPath(S4, S3));
    assertThat(links, linksHasPath(S5, S4));
    assertThat(links, linksHasPath(S6, S5));
    assertThat(links, linksHasPath(S7, S6));
    assertThat(links, linksHasPath(S8, S7));
    egressPoints = ImmutableSet.of(new FilteredConnectPoint(new ConnectPoint(DID_S1, PORT_1)));
    assertThat(reverseLCIntent.filteredEgressPoints(), is(egressPoints));
    assertThat("key is inherited", result.stream().map(Intent::key).collect(Collectors.toList()), everyItem(is(intent.key())));
}
Also used : HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) Intent(org.onosproject.net.intent.Intent) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) Link(org.onosproject.net.Link) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 80 with Link

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

the class FlowRuleJuniperImpl method findIpDst.

/**
 * Helper method to find the next hop IP address.
 * The logic is to check if the destination ports have an IP address
 * by checking the logical interface (e.g., for port physical ge-2/0/1,
 * a logical interface may be ge-2/0/1.0
 *
 * @param deviceId the device id of the flow rule to be installed
 * @param port     output port of the flow rule treatment
 * @return optional IPv4 address of a next hop
 */
private Optional<Ip4Address> findIpDst(DeviceId deviceId, Port port) {
    LinkService linkService = this.handler().get(LinkService.class);
    Set<Link> links = linkService.getEgressLinks(new ConnectPoint(deviceId, port.number()));
    DeviceService deviceService = this.handler().get(DeviceService.class);
    // Using only links with adjacency discovered by the LLDP protocol (see LinkDiscoveryJuniperImpl)
    Map<DeviceId, Port> dstPorts = links.stream().filter(l -> JuniperUtils.AK_IP.toUpperCase().equals(l.annotations().value(AnnotationKeys.LAYER))).collect(Collectors.toMap(l -> l.dst().deviceId(), l -> deviceService.getPort(l.dst().deviceId(), l.dst().port())));
    for (Map.Entry<DeviceId, Port> entry : dstPorts.entrySet()) {
        String portName = entry.getValue().annotations().value(AnnotationKeys.PORT_NAME);
        Optional<Port> childPort = deviceService.getPorts(entry.getKey()).stream().filter(p -> Strings.nullToEmpty(p.annotations().value(AnnotationKeys.PORT_NAME)).contains(portName.trim())).filter(this::isIp).findAny();
        if (childPort.isPresent()) {
            return Optional.ofNullable(Ip4Address.valueOf(childPort.get().annotations().value(JuniperUtils.AK_IP)));
        }
    }
    return Optional.empty();
}
Also used : NetconfException(org.onosproject.netconf.NetconfException) StringUtils(org.apache.commons.lang.StringUtils) JuniperUtils.commitBuilder(org.onosproject.drivers.juniper.JuniperUtils.commitBuilder) FlowRuleProgrammable(org.onosproject.net.flow.FlowRuleProgrammable) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) FlowEntry(org.onosproject.net.flow.FlowEntry) AnnotationKeys(org.onosproject.net.AnnotationKeys) JuniperUtils.routeAddBuilder(org.onosproject.drivers.juniper.JuniperUtils.routeAddBuilder) Link(org.onosproject.net.Link) NetconfSession(org.onosproject.netconf.NetconfSession) ConnectPoint(org.onosproject.net.ConnectPoint) HashSet(java.util.HashSet) XmlConfigParser.loadXmlString(org.onosproject.drivers.utilities.XmlConfigParser.loadXmlString) Strings(com.google.common.base.Strings) FlowRuleService(org.onosproject.net.flow.FlowRuleService) JuniperUtils.routeDeleteBuilder(org.onosproject.drivers.juniper.JuniperUtils.routeDeleteBuilder) Port(org.onosproject.net.Port) Map(java.util.Map) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) Ip4Address(org.onlab.packet.Ip4Address) Instruction(org.onosproject.net.flow.instructions.Instruction) Collection(java.util.Collection) PENDING_REMOVE(org.onosproject.net.flow.FlowEntry.FlowEntryState.PENDING_REMOVE) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Set(java.util.Set) Collectors(java.util.stream.Collectors) ADD(org.onosproject.drivers.juniper.JuniperUtils.OperationType.ADD) REMOVED(org.onosproject.net.flow.FlowEntry.FlowEntryState.REMOVED) Beta(com.google.common.annotations.Beta) DatastoreId(org.onosproject.netconf.DatastoreId) OperationType(org.onosproject.drivers.juniper.JuniperUtils.OperationType) FlowRule(org.onosproject.net.flow.FlowRule) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) LinkService(org.onosproject.net.link.LinkService) Optional(java.util.Optional) REMOVE(org.onosproject.drivers.juniper.JuniperUtils.OperationType.REMOVE) DeviceId(org.onosproject.net.DeviceId) Collections(java.util.Collections) JuniperUtils.rollbackBuilder(org.onosproject.drivers.juniper.JuniperUtils.rollbackBuilder) DeviceId(org.onosproject.net.DeviceId) Port(org.onosproject.net.Port) DeviceService(org.onosproject.net.device.DeviceService) XmlConfigParser.loadXmlString(org.onosproject.drivers.utilities.XmlConfigParser.loadXmlString) ConnectPoint(org.onosproject.net.ConnectPoint) LinkService(org.onosproject.net.link.LinkService) Map(java.util.Map) Link(org.onosproject.net.Link)

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