Java Code Examples for org.onosproject.net.flow.DefaultTrafficTreatment#emptyTreatment()

The following examples show how to use org.onosproject.net.flow.DefaultTrafficTreatment#emptyTreatment() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FlowObjectiveManagerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Tests adding a filtering objective.
 */
@Test
public void filteringObjective() {
    TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
    FilteringObjective filter =
            DefaultFilteringObjective.builder()
                    .fromApp(NetTestTools.APP_ID)
                    .withMeta(treatment)
                    .makePermanent()
                    .deny()
                    .addCondition(Criteria.matchEthType(12))
                    .add();

    manager.activate(null);
    manager.filter(id1, filter);

    TestTools.assertAfter(RETRY_MS, () ->
            assertThat(filteringObjectives, hasSize(1)));

    assertThat(forwardingObjectives, hasSize(0));
    assertThat(filteringObjectives, hasItem("of:d1"));
    assertThat(nextObjectives, hasSize(0));
}
 
Example 2
Source File: AbstractIntentInstallerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Creates point to point Intent for test.
 *
 * @return the point to point Intent
 */
public PointToPointIntent createP2PIntent() {
    PointToPointIntent intent;
    TrafficSelector selector = DefaultTrafficSelector.emptySelector();
    TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();

    FilteredConnectPoint ingress = new FilteredConnectPoint(CP1);
    FilteredConnectPoint egress = new FilteredConnectPoint(CP2);

    intent = PointToPointIntent.builder()
            .selector(selector)
            .treatment(treatment)
            .filteredIngressPoint(ingress)
            .filteredEgressPoint(egress)
            .appId(APP_ID)
            .build();

    return intent;
}
 
Example 3
Source File: IntentPerfInstaller.java    From onos with Apache License 2.0 6 votes vote down vote up
private Intent createIntent(Key key, long mac, NodeId node, Multimap<NodeId, Device> devices) {
    // choose a random device for which this node is master
    List<Device> deviceList = devices.get(node).stream().collect(Collectors.toList());
    Device device = deviceList.get(RandomUtils.nextInt(deviceList.size()));

    //FIXME we currently ignore the path length and always use the same device
    TrafficSelector selector = DefaultTrafficSelector.builder()
            .matchEthDst(MacAddress.valueOf(mac)).build();
    TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
    ConnectPoint ingress = new ConnectPoint(device.id(), PortNumber.portNumber(1));
    ConnectPoint egress = new ConnectPoint(device.id(), PortNumber.portNumber(2));

    return PointToPointIntent.builder()
            .appId(appId)
            .key(key)
            .selector(selector)
            .treatment(treatment)
            .filteredIngressPoint(new FilteredConnectPoint(ingress))
            .filteredEgressPoint(new FilteredConnectPoint(egress))
            .build();
}
 
Example 4
Source File: DemoInstaller.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    TrafficSelector selector = DefaultTrafficSelector.emptySelector();
    TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
    List<Constraint> constraint = Lists.newArrayList();
    List<Host> hosts = Lists.newArrayList(hostService.getHosts());
    while (!hosts.isEmpty()) {
        Host src = hosts.remove(0);
        for (Host dst : hosts) {
            HostToHostIntent intent = HostToHostIntent.builder()
                    .appId(appId)
                    .one(src.id())
                    .two(dst.id())
                    .selector(selector)
                    .treatment(treatment)
                    .constraints(constraint)
                    .build();
            existingIntents.add(intent);
            intentService.submit(intent);
        }
    }
}
 
Example 5
Source File: VirtualNetworkFlowObjectiveManagerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Tests adding a filtering objective.
 */
@Test
public void filteringObjective() {
    TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
    FilteringObjective filter =
            DefaultFilteringObjective.builder()
                    .fromApp(NetTestTools.APP_ID)
                    .withMeta(treatment)
                    .makePermanent()
                    .deny()
                    .addCondition(Criteria.matchEthType(12))
                    .add(new ObjectiveContext() {
                        @Override
                        public void onSuccess(Objective objective) {
                            assertEquals("1 flowrule entry expected",
                                         1,
                                         flowRuleStore.getFlowRuleCount(vnet1.id()));
                            assertEquals("0 flowrule entry expected",
                                         0,
                                         flowRuleStore.getFlowRuleCount(vnet2.id()));

                        }
                    });

    service1.filter(VDID1, filter);
}
 
Example 6
Source File: VirtualNetworkFlowObjectiveManagerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Tests adding a forwarding objective.
 */
@Test
public void forwardingObjective() {
    TrafficSelector selector = DefaultTrafficSelector.emptySelector();
    TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
    ForwardingObjective forward =
            DefaultForwardingObjective.builder()
                    .fromApp(NetTestTools.APP_ID)
                    .withFlag(ForwardingObjective.Flag.SPECIFIC)
                    .withSelector(selector)
                    .withTreatment(treatment)
                    .makePermanent()
                    .add(new ObjectiveContext() {
                        @Override
                        public void onSuccess(Objective objective) {
                            assertEquals("1 flowrule entry expected",
                                         1, flowRuleStore.getFlowRuleCount(vnet1.id()));
                            assertEquals("0 flowrule entry expected",
                                         0, flowRuleStore.getFlowRuleCount(vnet2.id()));
                        }
                    });

    service1.forward(VDID1, forward);
}
 
Example 7
Source File: IntentPushTestCommand.java    From onos with Apache License 2.0 6 votes vote down vote up
private List<Intent> generateIntents(ConnectPoint ingress, ConnectPoint egress) {
    TrafficSelector.Builder selectorBldr = DefaultTrafficSelector.builder()
            .matchEthType(Ethernet.TYPE_IPV4);
    TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();

    List<Intent> intents = Lists.newArrayList();
    for (long i = 0; i < count; i++) {
        TrafficSelector selector = selectorBldr
                .matchEthSrc(MacAddress.valueOf(i + keyOffset))
                .build();
        intents.add(PointToPointIntent.builder()
                .appId(appId())
                .key(Key.of(i + keyOffset, appId()))
                .selector(selector)
                .treatment(treatment)
                .filteredIngressPoint(new FilteredConnectPoint(ingress))
                .filteredEgressPoint(new FilteredConnectPoint(egress))
                .build());
        keysForInstall.add(Key.of(i + keyOffset, appId()));
        keysForWithdraw.add(Key.of(i + keyOffset, appId()));
    }
    return intents;
}
 
Example 8
Source File: FlowObjectiveManagerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Tests adding a next objective.
 */
@Test
public void nextObjective() {
    TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
    NextObjective next =
            DefaultNextObjective.builder()
                    .withId(manager.allocateNextId())
                    .addTreatment(treatment)
                    .withType(NextObjective.Type.BROADCAST)
                    .fromApp(NetTestTools.APP_ID)
                    .makePermanent()
                    .add();

    manager.next(id1, next);

    TestTools.assertAfter(RETRY_MS, () ->
            assertThat(nextObjectives, hasSize(1)));

    assertThat(forwardingObjectives, hasSize(0));
    assertThat(filteringObjectives, hasSize(0));
    assertThat(nextObjectives, hasItem("of:d1"));
}
 
Example 9
Source File: VirtualNetworkPacketManagerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the correct usage of emit() for a outbound packet.
 */
@Test
public void emitTest() {
    OutboundPacket packet =
            new DefaultOutboundPacket(VDID1, DefaultTrafficTreatment.emptyTreatment(), ByteBuffer.allocate(5));
    packetManager1.emit(packet);
    assertEquals("Packet not emitted correctly", packet, emittedPacket);
}
 
Example 10
Source File: VirtualNetworkPacketManagerWithDistStoreTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the correct usage of emit() for a outbound packet - master of packet's
 * sendThrough is not local node.
 */
@Test
@Ignore("Ignore until there is MastershipService support for virtual devices")
public void emit2Test() {
    OutboundPacket packet =
            new DefaultOutboundPacket(VDID2, DefaultTrafficTreatment.emptyTreatment(), ByteBuffer.allocate(5));
    packetManager1.emit(packet);
    assertNull("Packet should not have been emmitted", emittedPacket);
}
 
Example 11
Source File: TopologyViewMessageHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void process(ObjectNode payload) {
    // TODO: add protection against device ids and non-existent hosts.
    Set<HostId> src = getHostIds((ArrayNode) payload.path(SRC));
    HostId dst = hostId(string(payload, DST));
    Host dstHost = services.host().getHost(dst);

    Set<FilteredConnectPoint> ingressPoints = getHostLocations(src);

    // FIXME: clearly, this is not enough
    TrafficSelector selector = DefaultTrafficSelector.builder()
            .matchEthDst(dstHost.mac()).build();
    TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();

    MultiPointToSinglePointIntent intent =
            MultiPointToSinglePointIntent.builder()
                    .appId(appId)
                    .selector(selector)
                    .treatment(treatment)
                    .filteredIngressPoints(ingressPoints)
                    .filteredEgressPoint(new FilteredConnectPoint(dstHost.location()))
                    .build();

    services.intent().submit(intent);
    if (overlayCache.isActive(TrafficOverlay.TRAFFIC_ID)) {
        traffic.monitor(intent);
    }
}
 
Example 12
Source File: FabricInterpreterTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Map empty treatment for ACL table.
 */
@Test
public void testAclTreatmentEmpty() throws Exception {
    TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
    PiAction mappedAction = interpreter.mapTreatment(
            treatment, FabricConstants.FABRIC_INGRESS_ACL_ACL);
    PiAction expectedAction = PiAction.builder()
            .withId(FabricConstants.FABRIC_INGRESS_ACL_NOP_ACL)
            .build();
    assertEquals(expectedAction, mappedAction);
}
 
Example 13
Source File: FabricInterpreterTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Map empty treatment for routing v4 table.
 */
@Test
public void testRoutingV4TreatmentEmpty() throws Exception {
    TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
    PiAction mappedAction = interpreter.mapTreatment(
            treatment, FabricConstants.FABRIC_INGRESS_FORWARDING_ROUTING_V4);
    PiAction expectedAction = PiAction.builder()
            .withId(FabricConstants.FABRIC_INGRESS_FORWARDING_NOP_ROUTING_V4)
            .build();
    assertEquals(expectedAction, mappedAction);
}
 
Example 14
Source File: FabricInterpreterTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Map treatment to permit action.
 */
@Test
public void testFilteringTreatmentPermit() throws Exception {
    TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
    PiAction mappedAction = interpreter.mapTreatment(treatment,
                                                     FabricConstants.FABRIC_INGRESS_FILTERING_INGRESS_PORT_VLAN);
    PiAction expectedAction = PiAction.builder()
            .withId(FabricConstants.FABRIC_INGRESS_FILTERING_PERMIT)
            .build();

    assertEquals(expectedAction, mappedAction);
}
 
Example 15
Source File: Topo2TrafficMessageHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void process(ObjectNode payload) {
    // TODO: add protection against device ids and non-existent hosts.
    Set<HostId> src = getHostIds((ArrayNode) payload.path(SRC));
    HostId dst = hostId(string(payload, DST));
    Host dstHost = services.host().getHost(dst);

    Set<FilteredConnectPoint> ingressPoints = getHostLocations(src);

    // FIXME: clearly, this is not enough
    TrafficSelector selector = DefaultTrafficSelector.builder()
            .matchEthDst(dstHost.mac()).build();
    TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();

    MultiPointToSinglePointIntent intent =
            MultiPointToSinglePointIntent.builder()
                    .appId(appId)
                    .selector(selector)
                    .treatment(treatment)
                    .filteredIngressPoints(ingressPoints)
                    .filteredEgressPoint(new FilteredConnectPoint(dstHost.location()))
                    .build();

    services.intent().submit(intent);
    if (overlay2Cache.isActive(Traffic2Overlay.OVERLAY_ID)) {
        traffic2.monitor(intent);
    }
}
 
Example 16
Source File: ConnectivityIntentCommand.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Generates a traffic treatment for this intent based on command line
 * arguments presented to the command.
 *
 * @return traffic treatment
 */
protected TrafficTreatment buildTrafficTreatment() {
    final TrafficTreatment.Builder treatmentBuilder = builder();
    boolean emptyTreatment = true;

    if (!isNullOrEmpty(setEthSrcString)) {
        treatmentBuilder.setEthSrc(MacAddress.valueOf(setEthSrcString));
        emptyTreatment = false;
    }

    if (!isNullOrEmpty(setEthDstString)) {
        treatmentBuilder.setEthDst(MacAddress.valueOf(setEthDstString));
        emptyTreatment = false;
    }

    if (!isNullOrEmpty(setIpSrcString)) {
        treatmentBuilder.setIpSrc(IpAddress.valueOf(setIpSrcString));
        emptyTreatment = false;
    }

    if (!isNullOrEmpty(setIpDstString)) {
        treatmentBuilder.setIpDst(IpAddress.valueOf(setIpDstString));
        emptyTreatment = false;
    }
    if (!isNullOrEmpty(setVlan)) {
        treatmentBuilder.setVlanId(VlanId.vlanId(Short.parseShort(setVlan)));
        emptyTreatment = false;
    }
    if (popVlan) {
        treatmentBuilder.popVlan();
        emptyTreatment = false;
    }
    if (!isNullOrEmpty(pushVlan)) {
        treatmentBuilder.pushVlan();
        treatmentBuilder.setVlanId(VlanId.vlanId(Short.parseShort(pushVlan)));
        emptyTreatment = false;
    }
    if (!isNullOrEmpty(setQueue)) {
        // OpenFlow 1.0 notation (for ENQUEUE): <port>/<queue>
        if (setQueue.contains("/")) {
            String[] queueConfig = setQueue.split("/");
            PortNumber port = PortNumber.portNumber(Long.parseLong(queueConfig[0]));
            long queueId = Long.parseLong(queueConfig[1]);
            treatmentBuilder.setQueue(queueId, port);
        } else {
            treatmentBuilder.setQueue(Long.parseLong(setQueue));
        }
        emptyTreatment = false;
    }

    if (emptyTreatment) {
        return DefaultTrafficTreatment.emptyTreatment();
    } else {
        return treatmentBuilder.build();
    }
}
 
Example 17
Source File: FlowObjectiveManagerTest.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Tests adding a pending forwarding objective.
 *
 * @throws TestUtilsException if lookup of a field fails
 */
@Test
public void pendingForwardingObjective() throws TestUtilsException {
    TrafficSelector selector = DefaultTrafficSelector.emptySelector();
    TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();

    ForwardingObjective forward4 =
            DefaultForwardingObjective.builder()
                    .fromApp(NetTestTools.APP_ID)
                    .withFlag(ForwardingObjective.Flag.SPECIFIC)
                    .withSelector(selector)
                    .withTreatment(treatment)
                    .makePermanent()
                    .nextStep(4)
                    .add();
    ForwardingObjective forward5 =
            DefaultForwardingObjective.builder()
                    .fromApp(NetTestTools.APP_ID)
                    .withFlag(ForwardingObjective.Flag.SPECIFIC)
                    .withSelector(selector)
                    .withTreatment(treatment)
                    .makePermanent()
                    .nextStep(5)
                    .add();

    //  multiple pending forwards should be combined
    manager.forward(id1, forward4);
    manager.forward(id1, forward4);
    manager.forward(id1, forward5);


    //  1 should be complete, 1 pending
    TestTools.assertAfter(RETRY_MS, () ->
            assertThat(forwardingObjectives, hasSize(1)));

    assertThat(forwardingObjectives, hasItem("of:d1"));
    assertThat(filteringObjectives, hasSize(0));
    assertThat(nextObjectives, hasSize(0));

    // Now send events to trigger the objective still in the queue
    ObjectiveEvent event1 = new ObjectiveEvent(ObjectiveEvent.Type.ADD, 4);
    FlowObjectiveStoreDelegate delegate = TestUtils.getField(manager, "delegate");
    delegate.notify(event1);

    // all should be processed now
    TestTools.assertAfter(RETRY_MS, () ->
            assertThat(forwardingObjectives, hasSize(2)));
    assertThat(forwardingObjectives, hasItem("of:d1"));
    assertThat(filteringObjectives, hasSize(0));
    assertThat(nextObjectives, hasSize(0));
}
 
Example 18
Source File: LinkCollectionCompiler.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Compares tag type between ingress and egress point and generate
 * treatment for egress point of intent.
 *
 * @param ingress ingress selector for the intent
 * @param egress egress selector for the intent
 * @param ethType the ethertype to use in mpls_pop
 * @return Builder of TrafficTreatment
 */
private TrafficTreatment forwardingTreatment(TrafficSelector ingress,
                                             TrafficSelector egress,
                                             EthType ethType) {


    if (ingress.equals(egress)) {
        return DefaultTrafficTreatment.emptyTreatment();
    }

    TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();

    /*
     * "null" means there is no tag for the port
     * Tag criterion will be null if port is normal connection point
     */
    Criterion ingressTagCriterion = getTagCriterion(ingress);
    Criterion egressTagCriterion = getTagCriterion(egress);

    if (ingressTagCriterion.type() != egressTagCriterion.type()) {

        /*
         * Tag type of ingress port and egress port are different.
         * Need to remove tag from ingress, then add new tag for egress.
         * Remove nothing if ingress port use VXLAN or there is no tag
         * on ingress port.
         */
        switch (ingressTagCriterion.type()) {
            case VLAN_VID:
                builder.popVlan();
                break;

            case MPLS_LABEL:
                if (copyTtl) {
                    builder.copyTtlIn();
                }
                builder.popMpls(ethType);
                break;

            default:
                break;

        }

        /*
         * Push new tag for egress port.
         */
        switch (egressTagCriterion.type()) {
            case VLAN_VID:
                builder.pushVlan();
                break;

            case MPLS_LABEL:
                builder.pushMpls();
                if (copyTtl) {
                    builder.copyTtlOut();
                }
                break;

            default:
                break;

        }
    }

    switch (egressTagCriterion.type()) {
        case VLAN_VID:
            VlanIdCriterion vlanIdCriterion = (VlanIdCriterion) egressTagCriterion;
            builder.setVlanId(vlanIdCriterion.vlanId());
            break;

        case MPLS_LABEL:
            MplsCriterion mplsCriterion = (MplsCriterion) egressTagCriterion;
            builder.setMpls(mplsCriterion.label());
            break;

        case TUNNEL_ID:
            TunnelIdCriterion tunnelIdCriterion = (TunnelIdCriterion) egressTagCriterion;
            builder.setTunnelId(tunnelIdCriterion.tunnelId());
            break;

        default:
            break;

    }

    return builder.build();
}
 
Example 19
Source File: FilteringObjectiveTranslator.java    From onos with Apache License 2.0 4 votes vote down vote up
private void ingressPortVlanRule(
        FilteringObjective obj,
        Criterion inPortCriterion,
        VlanIdCriterion outerVlanCriterion,
        VlanIdCriterion innerVlanCriterion,
        ObjectiveTranslation.Builder resultBuilder)
        throws FabricPipelinerException {

    final boolean outerVlanValid = outerVlanCriterion != null
            && !outerVlanCriterion.vlanId().equals(VlanId.NONE);
    final boolean innerVlanValid = innerVlanCriterion != null
            && !innerVlanCriterion.vlanId().equals(VlanId.NONE);

    if (innerVlanValid && !capabilities.supportDoubleVlanTerm()) {
        throw new FabricPipelinerException(
                "Found 2 VLAN IDs, but the pipeline does not support double VLAN termination",
                ObjectiveError.UNSUPPORTED);
    }

    final PiCriterion piCriterion = PiCriterion.builder()
            .matchExact(FabricConstants.HDR_VLAN_IS_VALID, outerVlanValid ? ONE : ZERO)
            .build();

    final TrafficSelector.Builder selector = DefaultTrafficSelector.builder()
            .add(inPortCriterion)
            .add(piCriterion);
    if (outerVlanValid) {
        selector.add(outerVlanCriterion);
    }
    if (innerVlanValid) {
        selector.add(innerVlanCriterion);
    }

    final TrafficTreatment treatment;
    if (obj.type().equals(FilteringObjective.Type.DENY)) {
        treatment = DefaultTrafficTreatment.builder()
                .piTableAction(DENY)
                .build();
    } else {
        treatment = obj.meta() == null
                ? DefaultTrafficTreatment.emptyTreatment() : obj.meta();
    }
    resultBuilder.addFlowRule(flowRule(
            obj, FabricConstants.FABRIC_INGRESS_FILTERING_INGRESS_PORT_VLAN,
            selector.build(), treatment));
}
 
Example 20
Source File: NetTestTools.java    From onos with Apache License 2.0 2 votes vote down vote up
/**
 * Builds an empty treatment.
 *
 * @return the treatment
 */
public static TrafficTreatment emptyTreatment() {
    return DefaultTrafficTreatment.emptyTreatment();
}