org.onosproject.net.flow.DefaultTrafficSelector Java Examples

The following examples show how to use org.onosproject.net.flow.DefaultTrafficSelector. 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: K8sFlowRuleManager.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void connectTables(DeviceId deviceId, int fromTable, int toTable) {
    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();

    treatment.transition(toTable);

    FlowRule flowRule = DefaultFlowRule.builder()
            .forDevice(deviceId)
            .withSelector(selector.build())
            .withTreatment(treatment.build())
            .withPriority(DROP_PRIORITY)
            .fromApp(appId)
            .makePermanent()
            .forTable(fromTable)
            .build();

    applyRule(flowRule, true);
}
 
Example #2
Source File: L2ForwardServiceImpl.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void programLocalOut(DeviceId deviceId,
                            SegmentationId segmentationId,
                            PortNumber outPort, MacAddress sourceMac,
                            Objective.Operation type) {
    TrafficSelector selector = DefaultTrafficSelector.builder()
            .matchTunnelId(Long.parseLong(segmentationId.toString()))
            .matchEthDst(sourceMac).build();
    TrafficTreatment treatment = DefaultTrafficTreatment.builder()
            .setOutput(outPort).build();
    ForwardingObjective.Builder objective = DefaultForwardingObjective
            .builder().withTreatment(treatment).withSelector(selector)
            .fromApp(appId).withFlag(Flag.SPECIFIC)
            .withPriority(MAC_PRIORITY);
    if (type.equals(Objective.Operation.ADD)) {
        flowObjectiveService.forward(deviceId, objective.add());
    } else {
        flowObjectiveService.forward(deviceId, objective.remove());
    }

}
 
Example #3
Source File: McastForwarding.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Active MulticastForwardingIntent.
 */
@Activate
public void activate() {
    appId = coreService.registerApplication("org.onosproject.mfwd");

    mcastIntentManager = new McastIntentManager();
    mcastRouteManager.addListener(mcastIntentManager);

    packetService.addProcessor(processor, PacketProcessor.director(2));

    // Build a traffic selector for all multicast traffic
    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
    selector.matchEthType(Ethernet.TYPE_IPV4);
    selector.matchIPDst(IpPrefix.IPV4_MULTICAST_PREFIX);

    packetService.requestPackets(selector.build(), PacketPriority.REACTIVE, appId);

    log.info("Started");
}
 
Example #4
Source File: TestProtectionEndpointIntentCommand.java    From onos with Apache License 2.0 6 votes vote down vote up
private FilteredConnectPoint output(DeviceId did, String portNumberStr, String vlanStr) {
    ConnectPoint cp = new ConnectPoint(did,
                                       PortNumber.fromString(portNumberStr));
    if (deviceService.getPort(cp) == null) {
        print("Unknown port: %s", cp);
    }

    if (vlanStr == null) {
        return new FilteredConnectPoint(cp);
    } else {
        VlanId vlan = VlanId.vlanId(vlanStr);
        TrafficSelector sel = DefaultTrafficSelector.builder()
                .matchVlanId(vlan)
                .build();

        return new FilteredConnectPoint(cp, sel);

    }
}
 
Example #5
Source File: PathIntentCompilerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the compilation behavior of the path intent compiler in case of
 * VLAN {@link EncapsulationType} encapsulation constraint {@link EncapsulationConstraint}
 * and single-hop-indirect-link scenario. Ingress VLAN. No egress VLAN.
 */
@Test
public void testVlanEncapCompileSingleHopIndirectIngressVlan() {
    sut.activate();

    List<Intent> compiled = sut.compile(singleHopIndirectIntentIngressVlan, Collections.emptyList());
    assertThat(compiled, hasSize(1));

    Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
    assertThat(rules, hasSize(1));


    FlowRule rule = rules.stream()
            .filter(x -> x.deviceId().equals(d2p2.deviceId()))
            .findFirst()
            .get();
    verifyIdAndPriority(rule, d2p2.deviceId());

    assertThat(rule.selector(), is(DefaultTrafficSelector.builder().matchInPort(d2p2.port())
                                           .matchVlanId(ingressVlan).build()));
    assertThat(rule.treatment(),
               is(DefaultTrafficTreatment.builder().setOutput(d2p3.port()).build()));

    sut.deactivate();
}
 
Example #6
Source File: K8sSwitchingHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
private void setExtToIntgTunnelTagFlowRules(K8sNode k8sNode, boolean install) {
    TrafficSelector selector = DefaultTrafficSelector.builder()
            .matchEthType(Ethernet.TYPE_IPV4)
            .matchInPort(k8sNode.intgToExtPatchPortNum())
            .build();

    K8sNetwork net = k8sNetworkService.network(k8sNode.hostname());

    TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder()
            .setTunnelId(Long.valueOf(net.segmentId()))
            .transition(JUMP_TABLE);

    k8sFlowRuleService.setRule(
            appId,
            k8sNode.intgBridge(),
            selector,
            tBuilder.build(),
            PRIORITY_TUNNEL_TAG_RULE,
            VTAG_TABLE,
            install);
}
 
Example #7
Source File: OpenstackFlowRuleManager.java    From onos with Apache License 2.0 6 votes vote down vote up
private void setFlatJumpRuleForPatchPort(DeviceId deviceId,
                                       PortNumber portNumber, short ethType) {
    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
    selector.matchInPort(portNumber)
            .matchEthType(ethType);

    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
    treatment.transition(STAT_FLAT_OUTBOUND_TABLE);
    FlowRule flowRuleForIp = DefaultFlowRule.builder()
            .forDevice(deviceId)
            .withSelector(selector.build())
            .withTreatment(treatment.build())
            .withPriority(PRIORITY_FLAT_JUMP_UPSTREAM_RULE)
            .fromApp(appId)
            .makePermanent()
            .forTable(DHCP_TABLE)
            .build();

    applyRule(flowRuleForIp, true);
}
 
Example #8
Source File: K8sFlowRuleManager.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void setUpTableMissEntry(DeviceId deviceId, int table) {
    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();

    treatment.drop();

    FlowRule flowRule = DefaultFlowRule.builder()
            .forDevice(deviceId)
            .withSelector(selector.build())
            .withTreatment(treatment.build())
            .withPriority(DROP_PRIORITY)
            .fromApp(appId)
            .makePermanent()
            .forTable(table)
            .build();

    applyRule(flowRule, true);
}
 
Example #9
Source File: OpenstackVtapManager.java    From onos with Apache License 2.0 6 votes vote down vote up
private void setOutputTableForDrop(DeviceId deviceId, int tableId,
                                   boolean install) {
    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();

    FlowRule flowRule = DefaultFlowRule.builder()
            .forDevice(deviceId)
            .withSelector(selector.build())
            .withTreatment(treatment.build())
            .withPriority(PRIORITY_VTAP_OUTPUT_DROP)
            .makePermanent()
            .forTable(tableId)
            .fromApp(appId)
            .build();
    applyFlowRule(flowRule, install);
}
 
Example #10
Source File: XconnectManager.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a bridging forwarding objective builder for XConnect.
 *
 * @param key    XConnect key
 * @param nextId next ID of the broadcast group for this XConnect key
 * @return forwarding objective builder
 */
private ForwardingObjective.Builder fwdObjBuilder(XconnectKey key, int nextId) {
    /*
     * Driver should treat objectives with MacAddress.NONE and !VlanId.NONE
     * as the VLAN cross-connect broadcast rules
     */
    TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder();
    sbuilder.matchVlanId(key.vlanId());
    sbuilder.matchEthDst(MacAddress.NONE);

    ForwardingObjective.Builder fob = DefaultForwardingObjective.builder();
    fob.withFlag(ForwardingObjective.Flag.SPECIFIC)
            .withSelector(sbuilder.build())
            .nextStep(nextId)
            .withPriority(XCONNECT_PRIORITY)
            .fromApp(appId)
            .makePermanent();
    return fob;
}
 
Example #11
Source File: AbstractHPPipeline.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * HP Table 0 initialization.
 * Installs rule goto HP_HARDWARE_TABLE in HP_TABLE_ZERO
 */
private void installHPTableZero() {
    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();

    treatment.transition(HP_HARDWARE_TABLE);

    FlowRule rule = DefaultFlowRule.builder().forDevice(this.deviceId)
            .withSelector(selector.build())
            .withTreatment(treatment.build())
            .withPriority(0)
            .fromApp(appId)
            .makePermanent()
            .forTable(HP_TABLE_ZERO)
            .build();

    this.applyRules(true, rule);
}
 
Example #12
Source File: ControlPlaneRedirectManager.java    From onos with Apache License 2.0 6 votes vote down vote up
static TrafficSelector.Builder buildBaseSelectorBuilder(PortNumber inPort,
                                                        MacAddress srcMac,
                                                        MacAddress dstMac,
                                                        VlanId vlanId) {
    TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
    if (inPort != null) {
        selectorBuilder.matchInPort(inPort);
    }
    if (srcMac != null) {
        selectorBuilder.matchEthSrc(srcMac);
    }
    if (dstMac != null) {
        selectorBuilder.matchEthDst(dstMac);
    }
    if (vlanId != null) {
        selectorBuilder.matchVlanId(vlanId);
    }
    return selectorBuilder;
}
 
Example #13
Source File: OvsOfdpaPipeline.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Creates punt table entry that matches IN_PORT and VLAN_VID and forwards
 * packet to controller tagged.
 *
 * @param portNumber port number
 * @param packetVlan vlan tag of the packet
 * @return punt table flow rule
 */
private FlowRule buildPuntTableRuleTagged(PortNumber portNumber, VlanId packetVlan) {
    TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder()
            .matchInPort(portNumber)
            .matchVlanId(packetVlan);
    TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder().punt();

    return DefaultFlowRule.builder()
            .forDevice(deviceId)
            .withSelector(sbuilder.build())
            .withTreatment(tbuilder.build())
            .withPriority(PacketPriority.CONTROL.priorityValue())
            .fromApp(driverId)
            .makePermanent()
            .forTable(PUNT_TABLE).build();
}
 
Example #14
Source File: OvsOfdpaPipeline.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
protected List<List<FlowRule>> processEthDstOnlyFilter(EthCriterion ethCriterion,
                                                 ApplicationId applicationId) {
    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
    selector.matchEthType(Ethernet.TYPE_IPV4);
    selector.matchEthDst(ethCriterion.mac());
    treatment.transition(UNICAST_ROUTING_TABLE);
    FlowRule rule = DefaultFlowRule.builder()
            .forDevice(deviceId)
            .withSelector(selector.build())
            .withTreatment(treatment.build())
            .withPriority(DEFAULT_PRIORITY)
            .fromApp(applicationId)
            .makePermanent()
            .forTable(TMAC_TABLE).build();
    return ImmutableList.of(ImmutableList.of(rule));
}
 
Example #15
Source File: DefaultVirtualFlowRuleProviderTest.java    From onos with Apache License 2.0 6 votes vote down vote up
@Test
public void removeVirtualizeFlowRule() {
    TrafficSelector ts = DefaultTrafficSelector.builder().build();
    TrafficTreatment tr = DefaultTrafficTreatment.builder()
            .setOutput(PORT_NUM2).build();

    FlowRule r1 = DefaultFlowRule.builder()
            .forDevice(VDID)
            .withSelector(ts)
            .withTreatment(tr)
            .withPriority(10)
            .fromApp(vAppId)
            .makeTemporary(TIMEOUT)
            .build();

    virtualProvider.removeFlowRule(VNET_ID, r1);

    assertEquals("0 rules should exist", 0,
                 virtualProvider.flowRuleService.getFlowRuleCount());
}
 
Example #16
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 #17
Source File: OpenstackSwitchingArpHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Installs flow rules at remote node to match ARP request packets for Tunnel.
 *
 * @param port      instance port
 * @param install   installation flag
 */
private void setRemoteArpRequestRuleForTunnel(InstancePort port, boolean install) {

    OpenstackNode localNode = osNodeService.node(port.deviceId());

    String segId = osNetworkService.segmentId(port.networkId());

    TrafficSelector selector = DefaultTrafficSelector.builder()
            .matchEthType(EthType.EtherType.ARP.ethType().toShort())
            .matchArpOp(ARP.OP_REQUEST)
            .matchArpTpa(port.ipAddress().getIp4Address())
            .matchTunnelId(Long.parseLong(segId))
            .build();

    setRemoteArpTreatmentForTunnel(selector, port, localNode, install);
}
 
Example #18
Source File: K8sSwitchingArpHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
private void setDefaultArpRuleForProxyMode(K8sNode node, boolean install) {
    TrafficSelector selector = DefaultTrafficSelector.builder()
            .matchEthType(EthType.EtherType.ARP.ethType().toShort())
            .build();

    TrafficTreatment treatment = DefaultTrafficTreatment.builder()
            .punt()
            .build();

    k8sFlowRuleService.setRule(
            appId,
            node.intgBridge(),
            selector,
            treatment,
            PRIORITY_ARP_CONTROL_RULE,
            ARP_TABLE,
            install
    );
}
 
Example #19
Source File: K8sNetworkPolicyHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
private void setBlackToRouteRules(boolean install) {

        k8sNodeService.completeNodes().forEach(n -> {
            ImmutableSet.of(ACL_INGRESS_BLACK_TABLE, ACL_EGRESS_BLACK_TABLE).forEach(t -> {
                k8sFlowRuleService.setRule(
                        appId,
                        n.intgBridge(),
                        DefaultTrafficSelector.builder().build(),
                        DefaultTrafficTreatment.builder()
                                .transition(ROUTING_TABLE).build(),
                        0,
                        t,
                        install
                );
            });
        });
    }
 
Example #20
Source File: LearningSwitchSolution.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Create a variable of the SwitchPacketProcessor class using the PacketProcessor defined above.
 * Activates the app.
 */
@Activate
protected void activate() {
    log.info("Started");
    appId = coreService.getAppId("org.onosproject.learningswitch"); //equal to the name shown in pom.xml file

    processor = new SwitchPacketProcessor();
    packetService.addProcessor(processor, PacketProcessor.director(3));

    /*
     * Restricts packet types to IPV4 and ARP by only requesting those types.
     */
    packetService.requestPackets(DefaultTrafficSelector.builder()
            .matchEthType(Ethernet.TYPE_IPV4).build(), PacketPriority.REACTIVE, appId, Optional.empty());
    packetService.requestPackets(DefaultTrafficSelector.builder()
            .matchEthType(Ethernet.TYPE_ARP).build(), PacketPriority.REACTIVE, appId, Optional.empty());
}
 
Example #21
Source File: ClassifierServiceImpl.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void programLocalIn(DeviceId deviceId,
                           SegmentationId segmentationId, PortNumber inPort,
                           MacAddress srcMac, ApplicationId appid,
                           Objective.Operation type) {
    TrafficSelector selector = DefaultTrafficSelector.builder()
            .matchInPort(inPort).matchEthSrc(srcMac).build();
    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
    treatment.add(Instructions
            .modTunnelId(Long.parseLong(segmentationId.toString())));
    ForwardingObjective.Builder objective = DefaultForwardingObjective
            .builder().withTreatment(treatment.build())
            .withSelector(selector).fromApp(appId).makePermanent()
            .withFlag(Flag.SPECIFIC).withPriority(L2_CLASSIFIER_PRIORITY);
    if (type.equals(Objective.Operation.ADD)) {
        log.debug("programLocalIn-->ADD");
        flowObjectiveService.forward(deviceId, objective.add());
    } else {
        log.debug("programLocalIn-->REMOVE");
        flowObjectiveService.forward(deviceId, objective.remove());
    }
}
 
Example #22
Source File: InOrderFlowObjectiveManagerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Creates next objective builder.
 *
 * @param nextId next ID
 * @param vlanId VLAN ID
 * @param ports Set of ports that is in the given VLAN ID
 *
 * @return Next objective builder
 */
private static NextObjective.Builder buildNextObjective(int nextId, VlanId vlanId, Collection<PortNumber> ports) {
    TrafficSelector metadata =
            DefaultTrafficSelector.builder().matchVlanId(vlanId).build();

    NextObjective.Builder nextObjBuilder = DefaultNextObjective
            .builder().withId(nextId)
            .withType(NextObjective.Type.BROADCAST).fromApp(APP_ID)
            .withMeta(metadata);

    ports.forEach(port -> {
        TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
        tBuilder.popVlan();
        tBuilder.setOutput(port);
        nextObjBuilder.addTreatment(tBuilder.build());
    });

    return nextObjBuilder;
}
 
Example #23
Source File: OpenstackSecurityGroupHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
private void initializeAclTable(DeviceId deviceId, boolean install) {

        ExtensionTreatment ctTreatment =
                niciraConnTrackTreatmentBuilder(driverService, deviceId)
                        .commit(true)
                        .build();

        TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
        sBuilder.matchEthType(Ethernet.TYPE_IPV4);

        TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
        tBuilder.extension(ctTreatment, deviceId)
                .transition(JUMP_TABLE);

        osFlowRuleService.setRule(appId,
                deviceId,
                sBuilder.build(),
                tBuilder.build(),
                PRIORITY_ACL_INGRESS_RULE,
                ACL_RECIRC_TABLE,
                install);
    }
 
Example #24
Source File: DefaultL2TunnelHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Creates the forwarding objective for the initiation.
 *
 * @param tunnelId the tunnel id
 * @param inPort   the input port
 * @param nextId   the next step
 * @return the forwarding objective to support the initiation.
 */
private ForwardingObjective.Builder createInitFwdObjective(long tunnelId, PortNumber inPort, int nextId) {

    log.debug("Creating forwarding objective for tunnel {} : Port {} , nextId {}", tunnelId, inPort, nextId);
    TrafficSelector.Builder trafficSelector = DefaultTrafficSelector.builder();

    // The flow has to match on the mpls logical
    // port and the tunnel id.
    trafficSelector.matchTunnelId(tunnelId);
    trafficSelector.matchInPort(inPort);

    return DefaultForwardingObjective
            .builder()
            .fromApp(srManager.appId())
            .makePermanent()
            .nextStep(nextId)
            .withPriority(SegmentRoutingService.DEFAULT_PRIORITY)
            .withSelector(trafficSelector.build())
            .withFlag(VERSATILE);

}
 
Example #25
Source File: AbstractCorsaPipeline.java    From onos with Apache License 2.0 6 votes vote down vote up
protected void processTableMissGoTo(boolean install, int table, int goTo, String description) {
    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();

    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
    treatment.transition(goTo);

    FlowRule rule = DefaultFlowRule.builder()
            .forDevice(deviceId)
            .withSelector(selector.build())
            .withTreatment(treatment.build())
            .withPriority(DROP_PRIORITY)
            .fromApp(appId)
            .makePermanent()
            .forTable(table).build();

    processFlowRule(install, rule, description);
}
 
Example #26
Source File: K8sRoutingSnatHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
private void setContainerToExtRule(K8sNode k8sNode, boolean install) {

        K8sNetwork net = k8sNetworkService.network(k8sNode.hostname());

        if (net == null) {
            return;
        }

        TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder()
                .matchEthType(Ethernet.TYPE_IPV4)
                .matchTunnelId(Long.valueOf(net.segmentId()))
                .matchEthDst(DEFAULT_GATEWAY_MAC);

        TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder()
                .setOutput(k8sNode.intgToExtPatchPortNum());

        k8sFlowRuleService.setRule(
                appId,
                k8sNode.intgBridge(),
                sBuilder.build(),
                tBuilder.build(),
                PRIORITY_EXTERNAL_ROUTING_RULE,
                ROUTING_TABLE,
                install);
    }
 
Example #27
Source File: SpringOpenTTP.java    From onos with Apache License 2.0 6 votes vote down vote up
protected void populateTableMissEntry(int tableToAdd,
                                      boolean toControllerNow,
                                      boolean toControllerWrite,
                                      boolean toTable, int tableToSend) {
    TrafficSelector selector = DefaultTrafficSelector.builder().build();
    TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();

    if (toControllerNow) {
        tBuilder.setOutput(PortNumber.CONTROLLER);
    }

    if (toControllerWrite) {
        tBuilder.deferred().setOutput(PortNumber.CONTROLLER);
    }

    if (toTable) {
        tBuilder.transition(tableToSend);
    }

    FlowRule flow = DefaultFlowRule.builder().forDevice(deviceId)
            .withSelector(selector).withTreatment(tBuilder.build())
            .withPriority(0).fromApp(appId).makePermanent()
            .forTable(tableToAdd).build();

    flowRuleService.applyFlowRules(flow);
}
 
Example #28
Source File: FlowObjectiveManagerTest.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();

    manager.forward(id1, forward);

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

    assertThat(forwardingObjectives, hasItem("of:d1"));
    assertThat(filteringObjectives, hasSize(0));
    assertThat(nextObjectives, hasSize(0));
}
 
Example #29
Source File: CorsaPipelineV3.java    From onos with Apache License 2.0 6 votes vote down vote up
protected void processTaggedPackets(boolean install) {
    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
    selector.matchVlanId(VlanId.ANY);

    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
    treatment.transition(VLAN_MAC_XLATE_TABLE);

    FlowRule rule = DefaultFlowRule.builder()
            .forDevice(deviceId)
            .withSelector(selector.build())
            .withTreatment(treatment.build())
            .withPriority(CONTROLLER_PRIORITY)
            .fromApp(appId)
            .makePermanent()
            .forTable(VLAN_CHECK_TABLE).build();
    processFlowRule(install, rule, "Provisioned vlan table tagged packets");
}
 
Example #30
Source File: IntProgrammableImpl.java    From onos with Apache License 2.0 5 votes vote down vote up
private void populateInstTableEntry(PiTableId tableId, PiMatchFieldId matchFieldId,
                                    int matchValue, PiActionId actionId, ApplicationId appId) {
    PiCriterion instCriterion = PiCriterion.builder()
            .matchExact(matchFieldId, matchValue)
            .build();
    TrafficSelector instSelector = DefaultTrafficSelector.builder()
            .matchPi(instCriterion)
            .build();
    PiAction instAction = PiAction.builder()
            .withId(actionId)
            .build();
    TrafficTreatment instTreatment = DefaultTrafficTreatment.builder()
            .piTableAction(instAction)
            .build();

    FlowRule instFlowRule = DefaultFlowRule.builder()
            .withSelector(instSelector)
            .withTreatment(instTreatment)
            .withPriority(DEFAULT_PRIORITY)
            .makePermanent()
            .forDevice(deviceId)
            .forTable(tableId)
            .fromApp(appId)
            .build();

    flowRuleService.applyFlowRules(instFlowRule);
}