org.onosproject.net.flow.DefaultTrafficTreatment Java Examples

The following examples show how to use org.onosproject.net.flow.DefaultTrafficTreatment. 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: OvsCorsaPipeline.java    From onos with Apache License 2.0 6 votes vote down vote up
private void processCosTable(boolean install) {
    TrafficTreatment.Builder treatment = DefaultTrafficTreatment
            .builder()
            .transition(FIB_TABLE);
    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();

    FlowRule rule = DefaultFlowRule.builder()
            .forDevice(deviceId)
            .withSelector(selector.build())
            .withTreatment(treatment.build())
            .withPriority(DROP_PRIORITY)
            .fromApp(appId)
            .makePermanent()
            .forTable(COS_MAP_TABLE).build();
    processFlowRule(true, rule, "Provisioned cos table");

}
 
Example #2
Source File: SnatServiceImpl.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void programSnatSameSegmentRules(DeviceId deviceId, SegmentationId matchVni,
                         IpAddress srcIP, IpAddress dstIP, MacAddress ethDst,
                         MacAddress ethSrc, IpAddress ipSrc,
                         SegmentationId actionVni, Objective.Operation type) {
    TrafficSelector selector = DefaultTrafficSelector.builder()
            .matchEthType(Ethernet.TYPE_IPV4)
            .matchTunnelId(Long.parseLong(matchVni.segmentationId()))
            .matchIPSrc(IpPrefix.valueOf(srcIP, PREFIC_LENGTH))
            .matchIPDst(IpPrefix.valueOf(dstIP, PREFIC_LENGTH)).build();

    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
    treatment.setEthDst(ethDst).setEthSrc(ethSrc).setIpSrc(ipSrc)
            .setTunnelId(Long.parseLong(actionVni.segmentationId()));
    ForwardingObjective.Builder objective = DefaultForwardingObjective
            .builder().withTreatment(treatment.build())
            .withSelector(selector).fromApp(appId).withFlag(Flag.SPECIFIC)
            .withPriority(SNAT_SAME_SEG_PRIORITY);
    if (type.equals(Objective.Operation.ADD)) {
        flowObjectiveService.forward(deviceId, objective.add());
    } else {
        flowObjectiveService.forward(deviceId, objective.remove());
    }
}
 
Example #3
Source File: CorsaPipelineV3.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
protected Builder processVlanFiler(FilteringObjective filt, VlanIdCriterion vlan, PortCriterion port) {
    log.debug("adding rule for VLAN: {}", vlan.vlanId());
    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
    selector.matchVlanId(vlan.vlanId());
    selector.matchInPort(port.port());
            /* Static treatment for VLAN_CIRCUIT_TABLE */
    treatment.setVlanPcp(MAX_VLAN_PCP);
    treatment.setQueue(0);
    treatment.meter(MeterId.meterId(defaultMeterId.id())); /* use default meter (Green) */
    treatment.transition(L3_IF_MAC_DA_TABLE);
    return DefaultFlowRule.builder()
            .withSelector(selector.build())
            .withTreatment(treatment.build())
            .withPriority(CONTROLLER_PRIORITY)
            .makePermanent()
            .forTable(VLAN_CIRCUIT_TABLE);
}
 
Example #4
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 #5
Source File: CorsaPipelineV39.java    From onos with Apache License 2.0 6 votes vote down vote up
private void processRouterPacket(boolean install) {

        deviceService.getPorts(deviceId).forEach(port -> {
            if (!port.number().isLogical()) {
                TrafficSelector.Builder selector = DefaultTrafficSelector.builder()
                        .matchVlanId(VlanId.vlanId(NATIVE_VLAN))
                        .matchInPort(port.number());

                TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder()
                        .setVlanPcp((byte) 0)
                        .setQueue(0)
                        .meter(defaultMeterId)
                        .transition(L3_IF_MAC_DA_TABLE);

                FlowRule rule = DefaultFlowRule.builder()
                        .forDevice(deviceId)
                        .withSelector(selector.build())
                        .withTreatment(treatment.build())
                        .withPriority(CONTROLLER_PRIORITY)
                        .fromApp(appId)
                        .makePermanent()
                        .forTable(VLAN_CIRCUIT_TABLE).build();
                processFlowRule(install, rule, "Provisioned vlan circuit table");
            }
        });
    }
 
Example #6
Source File: OpenstackSwitchingHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
private void setNetworkBlockRulesForVlan(String segmentId, boolean install) {
    TrafficSelector selector = DefaultTrafficSelector.builder()
            .matchTunnelId(Long.valueOf(segmentId))
            .build();

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

    osNodeService.completeNodes(COMPUTE)
            .forEach(osNode ->
                osFlowRuleService.setRule(
                    appId,
                    osNode.intgBridge(),
                    selector,
                    treatment,
                    PRIORITY_ADMIN_RULE,
                    ACL_EGRESS_TABLE,
                    install)
            );
}
 
Example #7
Source File: ControlPlaneRedirectManagerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Setup expectations on flowObjectiveService.next for NextObjective.
 *
 **/
private int modifyNextObjective(DeviceId deviceId, PortNumber portNumber, VlanId vlanId, boolean popVlan,
        boolean modifyFlag) {
    NextObjective.Builder nextObjBuilder = DefaultNextObjective.builder().withId(1)
            .withType(NextObjective.Type.SIMPLE).fromApp(APPID);

    TrafficTreatment.Builder ttBuilder = DefaultTrafficTreatment.builder();
    if (popVlan) {
        ttBuilder.popVlan();
    }
    ttBuilder.setOutput(portNumber);

    TrafficSelector.Builder metabuilder = DefaultTrafficSelector.builder();
    metabuilder.matchVlanId(vlanId);

    nextObjBuilder.withMeta(metabuilder.build());
    nextObjBuilder.addTreatment(ttBuilder.build());
    if (modifyFlag) {
        flowObjectiveService.next(deviceId, nextObjBuilder.add());
        expectLastCall().once();
    } else {
        flowObjectiveService.next(deviceId, nextObjBuilder.remove());
        expectLastCall().once();
    }
    return 1;
}
 
Example #8
Source File: OpenstackSwitchingDhcpHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
private void setDhcpRule(OpenstackNode openstackNode, boolean install) {
    TrafficSelector selector = DefaultTrafficSelector.builder()
            .matchEthType(Ethernet.TYPE_IPV4)
            .matchIPProtocol(IPv4.PROTOCOL_UDP)
            .matchUdpDst(TpPort.tpPort(UDP.DHCP_SERVER_PORT))
            .matchUdpSrc(TpPort.tpPort(UDP.DHCP_CLIENT_PORT))
            .build();

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

    osFlowRuleService.setRule(
            appId,
            openstackNode.intgBridge(),
            selector,
            treatment,
            PRIORITY_DHCP_RULE,
            DHCP_TABLE,
            install);
}
 
Example #9
Source File: L3ForwardServiceImpl.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void programRouteRules(DeviceId deviceId, SegmentationId l3Vni,
                              IpAddress dstVmIP, SegmentationId dstVni,
                              MacAddress dstVmGwMac, MacAddress dstVmMac,
                              Operation type) {
    TrafficSelector selector = DefaultTrafficSelector.builder()
            .matchEthType(IP_TYPE)
            .matchTunnelId(Long.parseLong(l3Vni.segmentationId()))
            .matchIPDst(IpPrefix.valueOf(dstVmIP, PREFIX_LENGTH)).build();
    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
    treatment.setEthSrc(dstVmGwMac)
            .setEthDst(dstVmMac)
            .add(Instructions.modTunnelId(Long.parseLong(dstVni
                         .segmentationId())));
    ForwardingObjective.Builder objective = DefaultForwardingObjective
            .builder().withTreatment(treatment.build())
            .withSelector(selector).fromApp(appId).withFlag(Flag.SPECIFIC)
            .withPriority(L3FWD_PRIORITY);
    if (type.equals(Objective.Operation.ADD)) {
        log.debug("RouteRules-->ADD");
        flowObjectiveService.forward(deviceId, objective.add());
    } else {
        log.debug("RouteRules-->REMOVE");
        flowObjectiveService.forward(deviceId, objective.remove());
    }
}
 
Example #10
Source File: KryoSerializerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
@Test
public void testFlowRuleBatchEntry() {
    final FlowRule rule1 =
            DefaultFlowRule.builder()
                    .forDevice(DID1)
                    .withSelector(DefaultTrafficSelector.emptySelector())
                    .withTreatment(DefaultTrafficTreatment.emptyTreatment())
                    .withPriority(0)
                    .fromApp(new DefaultApplicationId(1, "1"))
                    .makeTemporary(1)
                    .build();

    final FlowRuleBatchEntry entry1 =
            new FlowRuleBatchEntry(FlowRuleBatchEntry.FlowRuleOperation.ADD, rule1);
    final FlowRuleBatchEntry entry2 =
            new FlowRuleBatchEntry(FlowRuleBatchEntry.FlowRuleOperation.ADD, rule1, 100L);

    testSerializedEquals(entry1);
    testSerializedEquals(entry2);
}
 
Example #11
Source File: K8sSwitchingHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
private void setLocalTunnelTagFlowRules(K8sNode k8sNode, boolean install) {
    TrafficSelector selector = DefaultTrafficSelector.builder()
            .matchEthType(Ethernet.TYPE_IPV4)
            .matchInPort(PortNumber.LOCAL)
            .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 #12
Source File: OfdpaGroupHandlerUtility.java    From onos with Apache License 2.0 6 votes vote down vote up
static List<GroupBucket> createL3MulticastBucket(List<GroupInfo> groupInfos) {
    List<GroupBucket> l3McastBuckets = new ArrayList<>();
    // For each inner group
    groupInfos.forEach(groupInfo -> {
        // Points to L3 interface group if there is one.
        // Otherwise points to L2 interface group directly.
        GroupDescription nextGroupDesc = (groupInfo.nextGroupDesc() != null) ?
                groupInfo.nextGroupDesc() : groupInfo.innerMostGroupDesc();
        TrafficTreatment.Builder ttb = DefaultTrafficTreatment.builder();
        ttb.group(new GroupId(nextGroupDesc.givenGroupId()));
        GroupBucket abucket = DefaultGroupBucket.createAllGroupBucket(ttb.build());
        l3McastBuckets.add(abucket);
    });
    // Done return the new list of buckets
    return l3McastBuckets;
}
 
Example #13
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 #14
Source File: K8sServiceHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
private void setTrackEstablish(DeviceId deviceId, long ctState, long ctMask,
                               int installTable, int transitTable,
                               int priority, boolean install) {
    ExtensionSelector esCtSate = RulePopulatorUtil
            .buildCtExtensionSelector(driverService, deviceId, ctState, ctMask);
    TrafficSelector selector = DefaultTrafficSelector.builder()
            .extension(esCtSate, deviceId)
            .build();

    TrafficTreatment treatment = DefaultTrafficTreatment.builder()
            .transition(transitTable)
            .build();

    k8sFlowRuleService.setRule(
            appId,
            deviceId,
            selector,
            treatment,
            priority,
            installTable,
            install);
}
 
Example #15
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 #16
Source File: CorsaPipelineV3.java    From onos with Apache License 2.0 6 votes vote down vote up
protected void processL3IFMacDATable(boolean install) {
    int table = L3_IF_MAC_DA_TABLE;

    /* Default action */
    processTableMissDrop(install, table, "Provisioned l3 table drop");

    /* Allow MAC broadcast frames on all ports */
    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
    selector.matchEthDst(MacAddress.BROADCAST);

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

    FlowRule rule = DefaultFlowRule.builder()
            .forDevice(deviceId)
            .withSelector(selector.build())
            .withTreatment(treatment.build())
            .withPriority(CONTROLLER_PRIORITY)
            .fromApp(appId)
            .makePermanent()
            .forTable(table).build();
    processFlowRule(install, rule, "Provisioned l3 table");
}
 
Example #17
Source File: DnatServiceImpl.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void programRules(DeviceId deviceId, IpAddress dstIp,
                         MacAddress ethSrc, IpAddress ipDst,
                         SegmentationId actionVni, Objective.Operation type) {
    TrafficSelector selector = DefaultTrafficSelector.builder()
            .matchEthType(Ethernet.TYPE_IPV4)
            .matchIPDst(IpPrefix.valueOf(dstIp, PREFIX_LENGTH)).build();

    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
    treatment.setEthSrc(ethSrc).setIpDst(ipDst)
            .setTunnelId(Long.parseLong(actionVni.segmentationId()));
    ForwardingObjective.Builder objective = DefaultForwardingObjective
            .builder().withTreatment(treatment.build())
            .withSelector(selector).fromApp(appId).withFlag(Flag.SPECIFIC)
            .withPriority(DNAT_PRIORITY);
    if (type.equals(Objective.Operation.ADD)) {
        log.debug("RouteRules-->ADD");
        flowObjectiveService.forward(deviceId, objective.add());
    } else {
        log.debug("RouteRules-->REMOVE");
        flowObjectiveService.forward(deviceId, objective.remove());
    }
}
 
Example #18
Source File: SpringOpenTTP.java    From onos with Apache License 2.0 6 votes vote down vote up
protected List<FlowRule> processEthDstOnlyFilter(EthCriterion ethCriterion,
        ApplicationId applicationId, int priority) {
    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
    selector.matchEthType(Ethernet.TYPE_IPV4);
    selector.matchEthDst(ethCriterion.mac());
    treatment.transition(TABLE_IPV4_UNICAST);
    FlowRule rule = DefaultFlowRule.builder()
            .forDevice(deviceId)
            .withSelector(selector.build())
            .withTreatment(treatment.build())
            .withPriority(priority)
            .fromApp(applicationId)
            .makePermanent()
            .forTable(TABLE_TMAC).build();
    return ImmutableList.<FlowRule>builder().add(rule).build();
}
 
Example #19
Source File: DemoInstaller.java    From onos with Apache License 2.0 6 votes vote down vote up
private Set<FilteringObjective.Builder> createFilter(int flowObjPerDevice) {
    Set<FilteringObjective.Builder> filterObjSet = new HashSet<>();
    for (int i = 0; i < flowObjPerDevice; i++) {
        TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder();
        tbuilder.add(Instructions.createOutput(PortNumber.portNumber(2)));
        TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder();
        sbuilder.matchInPort(PortNumber.portNumber(i + 3L));
        sbuilder.matchEthDst(MacAddress.valueOf("12:00:00:00:00:10"));

        FilteringObjective.Builder fobBuilder = DefaultFilteringObjective.builder();
        fobBuilder.fromApp(appId)
                  .withKey(sbuilder.build().getCriterion(Criterion.Type.IN_PORT))
                  .addCondition(sbuilder.build().getCriterion(Criterion.Type.ETH_DST))
                  .withMeta(tbuilder.build())
                  .permit()
                  .withPriority(i + 1)
                  .makePermanent();

        filterObjSet.add(fobBuilder);
    }

    return filterObjSet;
}
 
Example #20
Source File: GroupManagerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
private static Group createSouthboundGroupEntry(GroupId gId,
                                         List<PortNumber> ports,
                                         long referenceCount, DeviceId deviceId) {
    List<PortNumber> outPorts = new ArrayList<>();
    outPorts.addAll(ports);

    List<GroupBucket> buckets = new ArrayList<>();
    for (PortNumber portNumber : outPorts) {
        TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
        tBuilder.setOutput(portNumber)
                .setEthDst(MacAddress.valueOf("00:00:00:00:00:02"))
                .setEthSrc(MacAddress.valueOf("00:00:00:00:00:01"))
                .pushMpls()
                .setMpls(MplsLabel.mplsLabel(106));
        buckets.add(DefaultGroupBucket.createSelectGroupBucket(
                tBuilder.build()));
    }
    GroupBuckets groupBuckets = new GroupBuckets(buckets);
    StoredGroupEntry group = new DefaultGroup(
            gId, deviceId, Group.Type.SELECT, groupBuckets);
    group.setReferenceCount(referenceCount);
    return group;
}
 
Example #21
Source File: EvpnManager.java    From onos with Apache License 2.0 6 votes vote down vote up
private ForwardingObjective.Builder getMplsInBuilder(DeviceId deviceId,
                                                     Host host,
                                                     Label label) {
    TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
    TrafficSelector selector = DefaultTrafficSelector.builder()
            .matchInPort(getTunnlePort(deviceId))
            .matchEthType(EthType.EtherType.MPLS_UNICAST.ethType()
                                  .toShort())
            .matchMplsBos(true)
            .matchMplsLabel(MplsLabel.mplsLabel(label.getLabel())).build();
    TrafficTreatment treatment = builder.popMpls(EthType
                                                         .EtherType
                                                         .IPV4.ethType())
            .setOutput(host.location().port()).build();
    return DefaultForwardingObjective
            .builder().withTreatment(treatment).withSelector(selector)
            .fromApp(appId).withFlag(ForwardingObjective.Flag.SPECIFIC)
            .withPriority(60000);
}
 
Example #22
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 #23
Source File: FabricInterpreterTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Map treatment to set_vlan_output action.
 */
@Test
public void testNextTreatment3() throws Exception {
    TrafficTreatment treatment = DefaultTrafficTreatment.builder()
            .setVlanId(VLAN_100)
            .build();
    PiAction mappedAction = interpreter.mapTreatment(
            treatment, FabricConstants.FABRIC_INGRESS_NEXT_NEXT_VLAN);
    PiActionParam vlanParam = new PiActionParam(
            FabricConstants.VLAN_ID, VLAN_100.toShort());
    PiAction expectedAction = PiAction.builder()
            .withId(FabricConstants.FABRIC_INGRESS_NEXT_SET_VLAN)
            .withParameter(vlanParam)
            .build();
    assertEquals(expectedAction, mappedAction);
}
 
Example #24
Source File: DefaultGroupHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
TrafficTreatment treatmentBuilder(PortNumber outport, MacAddress dstMac,
                                  boolean swap, int edgeLabel) {
    TrafficTreatment.Builder tBuilder =
            DefaultTrafficTreatment.builder();
    tBuilder.setOutput(outport)
        .setEthDst(dstMac)
        .setEthSrc(nodeMacAddr);
    if (edgeLabel != DestinationSet.NO_EDGE_LABEL) {
        if (swap) {
            // swap label case
            tBuilder.setMpls(MplsLabel.mplsLabel(edgeLabel));
        } else {
            // ecmp with label push case
            tBuilder.pushMpls()
                .copyTtlOut()
                .setMpls(MplsLabel.mplsLabel(edgeLabel));
        }
    }
    return tBuilder.build();
}
 
Example #25
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 #26
Source File: Dhcp6HandlerImpl.java    From onos with Apache License 2.0 6 votes vote down vote up
private void forwardPacket(InternalPacket packet) {
    //send Packetout to dhcp server connectpoint.
    if (packet.getDestLocation() != null) {
        TrafficTreatment t = DefaultTrafficTreatment.builder()
                .setOutput(packet.getDestLocation().port()).build();
        OutboundPacket o = new DefaultOutboundPacket(
                packet.getDestLocation().deviceId(), t, ByteBuffer.wrap(packet.getPacket().serialize()));
        packetService.emit(o);
        if (log.isTraceEnabled()) {
            IPv6 ip6 = (IPv6) packet.getPacket().getPayload();
            UDP udp = (UDP) ip6.getPayload();
            DHCP6 dhcp6  = (DHCP6) udp.getPayload();
            log.trace("Relaying packet to destination {} eth: {} dhcp: {}",
                    packet.getDestLocation(), packet.getPacket(), dhcp6);
        }

    }
}
 
Example #27
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 #28
Source File: PeerConnectivityManagerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a BGP intent and put it into the intentList.
 * <p/>
 * The purpose of this method is too simplify the setUpBgpIntents() method,
 * and to make the setUpBgpIntents() easy to read.
 *
 * @param srcVlanId ingress VlanId
 * @param dstVlanId egress VlanId
 * @param srcPrefix source IP prefix to match
 * @param dstPrefix destination IP prefix to match
 * @param srcConnectPoint source connect point for PointToPointIntent
 * @param dstConnectPoint destination connect point for PointToPointIntent
 */
private void icmpPathintentConstructor(VlanId srcVlanId, VlanId dstVlanId,
                                       String srcPrefix, String dstPrefix,
                                       ConnectPoint srcConnectPoint,
                                       ConnectPoint dstConnectPoint) {

    TrafficSelector.Builder builder = DefaultTrafficSelector.builder()
            .matchEthType(Ethernet.TYPE_IPV4)
            .matchIPProtocol(IPv4.PROTOCOL_ICMP)
            .matchIPSrc(IpPrefix.valueOf(srcPrefix))
            .matchIPDst(IpPrefix.valueOf(dstPrefix));

    if (!srcVlanId.equals(VlanId.NONE)) {
        builder.matchVlanId(srcVlanId);
    }

    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();

    if (!dstVlanId.equals(VlanId.NONE)) {
        treatment.setVlanId(dstVlanId);
    }

    Key key = Key.of(srcPrefix.split("/")[0] + "-" + dstPrefix.split("/")[0]
            + "-" + "icmp", APPID);

    PointToPointIntent intent = PointToPointIntent.builder()
            .appId(APPID)
            .key(key)
            .selector(builder.build())
            .treatment(treatment.build())
            .filteredIngressPoint(new FilteredConnectPoint(srcConnectPoint))
            .filteredEgressPoint(new FilteredConnectPoint(dstConnectPoint))
            .build();

    intentList.add(intent);
}
 
Example #29
Source File: NdpReplyComponent.java    From onos-p4-tutorial with Apache License 2.0 5 votes vote down vote up
private FlowRule buildNdpReplyFlowRule(DeviceId deviceId,
                                       MacAddress deviceMac,
                                       Ip6Address targetIp) {
    PiCriterion match = PiCriterion.builder()
            .matchExact(PiMatchFieldId.of("hdr.ndp.target_addr"), targetIp.toOctets())
            .build();

    PiActionParam paramRouterMac = new PiActionParam(
            PiActionParamId.of("target_mac"), deviceMac.toBytes());
    PiAction action = PiAction.builder()
            .withId(PiActionId.of("IngressPipeImpl.ndp_ns_to_na"))
            .withParameter(paramRouterMac)
            .build();

    TrafficSelector selector = DefaultTrafficSelector.builder()
            .matchPi(match)
            .build();

    TrafficTreatment treatment = DefaultTrafficTreatment.builder()
            .piTableAction(action)
            .build();

    return DefaultFlowRule.builder()
            .forDevice(deviceId)
            .forTable(PiTableId.of("IngressPipeImpl.ndp_reply_table"))
            .fromApp(appId)
            .makePermanent()
            .withSelector(selector)
            .withTreatment(treatment)
            .withPriority(DEFAULT_FLOW_RULE_PRIORITY)
            .build();
}
 
Example #30
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);
}