org.onosproject.net.flow.TrafficTreatment Java Examples

The following examples show how to use org.onosproject.net.flow.TrafficTreatment. 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: FlowObjectiveCompositionUtil.java    From onos with Apache License 2.0 6 votes vote down vote up
public static ForwardingObjective composeSequential(ForwardingObjective fo1,
                                                    ForwardingObjective fo2,
                                                    int priorityMultiplier) {

    TrafficSelector revertTrafficSelector = revertTreatmentSelector(fo1.treatment(), fo2.selector());
    if (revertTrafficSelector == null) {
        return null;
    }

    TrafficSelector trafficSelector = intersectTrafficSelector(fo1.selector(), revertTrafficSelector);
    if (trafficSelector == null) {
        return null;
    }

    TrafficTreatment trafficTreatment = unionTrafficTreatment(fo1.treatment(), fo2.treatment());

    return DefaultForwardingObjective.builder()
            .fromApp(fo1.appId())
            .makePermanent()
            .withFlag(ForwardingObjective.Flag.VERSATILE)
            .withPriority(fo1.priority() * priorityMultiplier + fo2.priority())
            .withSelector(trafficSelector)
            .withTreatment(trafficTreatment)
            .add();
}
 
Example #2
Source File: AbstractHPPipeline.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Gets traffic treatment from a next objective.
 * Merge traffic treatments from next objective if the next objective is
 * BROADCAST type and contains multiple traffic treatments.
 * Returns first treatment from next objective if the next objective is
 * SIMPLE type and it contains only one treatment.
 *
 * @param nextObjective the next objective
 * @return the treatment from next objective; null if not supported
 */
private TrafficTreatment getTreatment(NextObjective nextObjective) {
    Collection<TrafficTreatment> treatments = nextObjective.next();
    switch (nextObjective.type()) {
        case SIMPLE:
            if (treatments.size() != 1) {
                log.error("Next Objectives of type SIMPLE should have only " +
                                "one traffic treatment. NexObjective: {}",
                        nextObjective.toString());
                return null;
            }
            return treatments.iterator().next();
        case BROADCAST:
            TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
            treatments.forEach(builder::addTreatment);
            return builder.build();
        default:
            log.error("Unsupported next objective type {}.", nextObjective.type());
            return null;
    }
}
 
Example #3
Source File: DefaultVirtualFlowRuleProvider.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Generates the corresponding flow rules for the physical network.
 *
 * @param networkId The virtual network identifier
 * @param ingressPoint The ingress point of the physical network
 * @param egressPoint The egress point of the physical network
 * @param commonSelector A common traffic selector between the virtual
 *                       and physical flow rules
 * @param commonTreatment A common traffic treatment between the virtual
 *                        and physical flow rules
 * @param flowRule The virtual flow rule to be translated
 * @return A set of flow rules for the physical network
 */
private Set<FlowRule> generateRules(NetworkId networkId,
                                    ConnectPoint ingressPoint,
                                    ConnectPoint egressPoint,
                                    TrafficSelector commonSelector,
                                    TrafficTreatment commonTreatment,
                                    FlowRule flowRule) {

    if (ingressPoint.deviceId().equals(egressPoint.deviceId()) ||
            egressPoint.port().isLogical()) {
        return generateRuleForSingle(networkId, ingressPoint, egressPoint,
                                     commonSelector, commonTreatment, flowRule);
    } else {
        return generateRuleForMulti(networkId, ingressPoint, egressPoint,
                                     commonSelector, commonTreatment, flowRule);
    }
}
 
Example #4
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 #5
Source File: OpenstackFlowRuleManagerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Tests whether the set rule method installs the flow rules properly.
 */
@Test
public void testSetRule() {
    int testPriority = 10;
    int testTableType = 10;

    fros = Sets.newConcurrentHashSet();

    TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
    TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();

    FlowRule.Builder flowRuleBuilder = DefaultFlowRule.builder()
            .forDevice(DEVICE_ID)
            .withSelector(selectorBuilder.build())
            .withTreatment(treatmentBuilder.build())
            .withPriority(testPriority)
            .fromApp(TEST_APP_ID)
            .forTable(testTableType)
            .makePermanent();

    target.setRule(TEST_APP_ID, DEVICE_ID, selectorBuilder.build(),
            treatmentBuilder.build(), testPriority, testTableType, true);
    validateFlowRule(flowRuleBuilder.build());
}
 
Example #6
Source File: K8sFlowRuleManager.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void setRule(ApplicationId appId, DeviceId deviceId,
                    TrafficSelector selector, TrafficTreatment treatment,
                    int priority, int tableType, boolean install) {
    FlowRule.Builder flowRuleBuilder = DefaultFlowRule.builder()
            .forDevice(deviceId)
            .withSelector(selector)
            .withTreatment(treatment)
            .withPriority(priority)
            .fromApp(appId)
            .forTable(tableType);

    if (priority == PRIORITY_SNAT_RULE) {
        flowRuleBuilder.makeTemporary(TIMEOUT_SNAT_RULE);
    } else {
        flowRuleBuilder.makePermanent();
    }

    applyRule(flowRuleBuilder.build(), install);
}
 
Example #7
Source File: IntentCycleCommand.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());


    }
    return intents;
}
 
Example #8
Source File: FabricInterpreterTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Map treatment for hashed table to routing v4 action.
 */
@Test
public void testNextTreatmentHashedRoutingMpls() throws Exception {
    TrafficTreatment treatment = DefaultTrafficTreatment.builder()
            .setEthSrc(SRC_MAC)
            .setEthDst(DST_MAC)
            .setOutput(PORT_1)
            .pushMpls()
            .setMpls(MPLS_10)
            .build();
    PiAction mappedAction = interpreter.mapTreatment(
            treatment, FabricConstants.FABRIC_INGRESS_NEXT_HASHED);
    PiActionParam ethSrcParam = new PiActionParam(FabricConstants.SMAC, SRC_MAC.toBytes());
    PiActionParam ethDstParam = new PiActionParam(FabricConstants.DMAC, DST_MAC.toBytes());
    PiActionParam portParam = new PiActionParam(FabricConstants.PORT_NUM, PORT_1.toLong());
    PiActionParam mplsParam = new PiActionParam(FabricConstants.LABEL, MPLS_10.toInt());
    PiAction expectedAction = PiAction.builder()
            .withId(FabricConstants.FABRIC_INGRESS_NEXT_MPLS_ROUTING_HASHED)
            .withParameters(ImmutableList.of(ethSrcParam, ethDstParam, portParam, mplsParam))
            .build();
    assertEquals(expectedAction, mappedAction);
}
 
Example #9
Source File: ForwardingObjectiveTranslator.java    From onos with Apache License 2.0 6 votes vote down vote up
private static TrafficTreatment nextIdOrTreatment(
        ForwardingObjective obj, PiTableId tableId)
        throws FabricPipelinerException {
    if (obj.nextId() == null) {
        return obj.treatment();
    } else {
        if (!NEXT_ID_ACTIONS.containsKey(tableId)) {
            throw new FabricPipelinerException(format(
                    "BUG? no next_id action set for table %s", tableId));
        }
        return DefaultTrafficTreatment.builder()
                .piTableAction(
                        setNextIdAction(obj.nextId(),
                                        NEXT_ID_ACTIONS.get(tableId)))
                .build();
    }
}
 
Example #10
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 #11
Source File: OpenstackRoutingSnatIcmpHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
private void setIcmpReplyRules(DeviceId deviceId, boolean install) {
    // Sends ICMP response to controller for SNATing ingress traffic
    TrafficSelector selector = DefaultTrafficSelector.builder()
            .matchEthType(Ethernet.TYPE_IPV4)
            .matchIPProtocol(IPv4.PROTOCOL_ICMP)
            .matchIcmpType(ICMP.TYPE_ECHO_REPLY)
            .build();

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

    osFlowRuleService.setRule(
            appId,
            deviceId,
            selector,
            treatment,
            PRIORITY_INTERNAL_ROUTING_RULE,
            GW_COMMON_TABLE,
            install);
}
 
Example #12
Source File: ClassifierServiceImpl.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void programExportPortArpClassifierRules(Port exportPort,
                                                DeviceId deviceId,
                                                Operation type) {
    TrafficSelector selector = DefaultTrafficSelector.builder()
            .matchEthType(EtherType.ARP.ethType().toShort())
            .matchInPort(exportPort.number()).build();
    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
    treatment.add(Instructions.createOutput(PortNumber.CONTROLLER));
    ForwardingObjective.Builder objective = DefaultForwardingObjective
            .builder().withTreatment(treatment.build())
            .withSelector(selector).fromApp(appId).withFlag(Flag.SPECIFIC)
            .withPriority(L3_CLASSIFIER_PRIORITY);
    if (type.equals(Objective.Operation.ADD)) {
        flowObjectiveService.forward(deviceId, objective.add());
    } else {
        flowObjectiveService.forward(deviceId, objective.remove());
    }
}
 
Example #13
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 #14
Source File: TunnellingConnectivityManager.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Pushes the flow rules for forwarding BGP TCP packets to controller.
 * It is called when switches are connected and available.
 */
public void notifySwitchAvailable() {
    // control plane OVS is available, push default flows
    TrafficSelector selectorDst = DefaultTrafficSelector.builder()
            .matchEthType(Ethernet.TYPE_IPV4)
            .matchIPProtocol(IPv4.PROTOCOL_TCP)
            .matchTcpDst(TpPort.tpPort(BGP_PORT))
            .build();

    TrafficSelector selectorSrc = DefaultTrafficSelector.builder()
            .matchEthType(Ethernet.TYPE_IPV4)
            .matchIPProtocol(IPv4.PROTOCOL_TCP)
            .matchTcpSrc(TpPort.tpPort(BGP_PORT))
            .build();

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

    ForwardingObjective puntSrc = DefaultForwardingObjective.builder()
            .fromApp(appId)
            .makePermanent()
            .withSelector(selectorSrc)
            .withTreatment(treatment)
            .withFlag(ForwardingObjective.Flag.VERSATILE)
            .add();
    flowObjectiveService.forward(bgpSpeaker.connectPoint().deviceId(),
            puntSrc);

    ForwardingObjective puntDst = DefaultForwardingObjective.builder()
            .fromApp(appId)
            .makePermanent()
            .withSelector(selectorDst)
            .withTreatment(treatment)
            .withFlag(ForwardingObjective.Flag.VERSATILE)
            .add();
    flowObjectiveService.forward(bgpSpeaker.connectPoint().deviceId(),
            puntDst);
    log.info("Sent punt forwarding objective to {}", bgpSpeaker.connectPoint().deviceId());
}
 
Example #15
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 #16
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 #17
Source File: OpenstackRoutingArpHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
private void setDefaultArpRuleForProxyMode(OpenstackNode osNode,
                                           boolean install) {
    TrafficSelector selector = DefaultTrafficSelector.builder()
            .matchEthType(EthType.EtherType.ARP.ethType().toShort())
            .build();

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

    osFlowRuleService.setRule(
            appId,
            osNode.intgBridge(),
            selector,
            treatment,
            PRIORITY_ARP_CONTROL_RULE,
            GW_COMMON_TABLE,
            install
    );
}
 
Example #18
Source File: DefaultGroupHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the next objective of type simple associated with the port on the
 * device, given the treatment. Different treatments to the same port result
 * in different next objectives. If no such objective exists, this method
 * creates one (if requested) and returns the id. Optionally metadata can be passed in for
 * the creation of the objective. Typically this is used for L2 and L3 forwarding
 * to compute nodes and containers/VMs on the compute nodes directly attached
 * to the switch.
 *
 * @param portNum the port number for the simple next objective
 * @param treatment the actions to apply on the packets (should include outport)
 * @param meta optional metadata passed into the creation of the next objective
 * @param createIfMissing true if a next object should be created if not found
 * @return int if found or created, -1 if there are errors during the
 *          creation of the next objective.
 */
public int getPortNextObjectiveId(PortNumber portNum, TrafficTreatment treatment,
                                  TrafficSelector meta, boolean createIfMissing) {
    Integer nextId = portNextObjStore
            .get(new PortNextObjectiveStoreKey(deviceId, portNum, treatment, meta));
    if (nextId != null) {
        return nextId;
    }
    log.debug("getPortNextObjectiveId in device {}: Next objective id "
            + "not found for port: {} .. {}", deviceId, portNum,
            (createIfMissing) ? "creating" : "aborting");
    if (!createIfMissing) {
        return -1;
    }
    // create missing next objective
    createGroupFromPort(portNum, treatment, meta);
    nextId = portNextObjStore.get(new PortNextObjectiveStoreKey(deviceId, portNum,
                                                                treatment, meta));
    if (nextId == null) {
        log.warn("getPortNextObjectiveId: unable to create next obj"
                + "for dev:{} port:{}", deviceId, portNum);
        return -1;
    }
    return nextId;
}
 
Example #19
Source File: VirtualNetworkGroupManagerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
private 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 #20
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 #21
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 #22
Source File: DefaultGroupBucket.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Creates indirect group bucket.
 *
 * @param treatment traffic treatment associated with group bucket
 * @return indirect group bucket object
 */
public static GroupBucket createIndirectGroupBucket(
                            TrafficTreatment treatment) {
    return new DefaultGroupBucket(GroupDescription.Type.INDIRECT,
                                  treatment,
                                  (short) -1,
                                  null,
                                  null);
}
 
Example #23
Source File: Ofdpa2GroupHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Removes buckets in the top level group of a possible group-chain. Does
 * not remove the groups in the group-chain pointed to by this bucket, as they
 * may be in use (referenced by other groups) elsewhere.
 *
 * @param nextObjective a next objective that contains information for the
 *                          buckets to be removed from the group
 * @param next the representation of the existing group-chains for this next
 *          objective, from which the top-level buckets to remove are determined
 */
protected void removeBucketFromGroup(NextObjective nextObjective, NextGroup next) {
    if (nextObjective.type() != NextObjective.Type.HASHED &&
            nextObjective.type() != NextObjective.Type.BROADCAST) {
        log.warn("RemoveBuckets not applied to nextType:{} in dev:{} for next:{}",
                nextObjective.type(), deviceId, nextObjective.id());
        fail(nextObjective, ObjectiveError.UNSUPPORTED);
        return;
    }
    List<Deque<GroupKey>> allActiveKeys = appKryo.deserialize(next.data());
    List<Integer> indicesToRemove = Lists.newArrayList();
    for (TrafficTreatment treatment : nextObjective.next()) {
        // find the top-level bucket in the group-chain by matching the
        // outport and label from different groups in the chain
        PortNumber portToRemove = readOutPortFromTreatment(treatment);
        int labelToRemove = readLabelFromTreatment(treatment);
        if (portToRemove == null) {
            log.warn("treatment {} of next objective {} has no outport.. "
                    + "cannot remove bucket from group in dev: {}", treatment,
                    nextObjective.id(), deviceId);
            continue;
        }
        List<Integer> existing = existingPortAndLabel(allActiveKeys,
                                                      groupService, deviceId,
                                                      portToRemove, labelToRemove);
        indicesToRemove.addAll(existing);

    }

    List<Deque<GroupKey>> chainsToRemove = Lists.newArrayList();
    indicesToRemove.forEach(index -> chainsToRemove
                            .add(allActiveKeys.get(index)));
    if (chainsToRemove.isEmpty()) {
        log.warn("Could not find appropriate group-chain for removing bucket"
                + " for next id {} in dev:{}", nextObjective.id(), deviceId);
        fail(nextObjective, ObjectiveError.BADPARAMS);
        return;
    }
    removeBucket(chainsToRemove, nextObjective);
}
 
Example #24
Source File: PathIntentCompiler.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void createFlow(TrafficSelector originalSelector, TrafficTreatment originalTreatment,
                       ConnectPoint ingress, ConnectPoint egress,
                       int priority, boolean applyTreatment,
                       List<FlowRule> rules,
                       List<DeviceId> devices) {

    TrafficSelector selector = DefaultTrafficSelector.builder(originalSelector)
            .matchInPort(ingress.port())
            .build();

    TrafficTreatment.Builder treatmentBuilder;
    if (applyTreatment) {
        treatmentBuilder = DefaultTrafficTreatment.builder(originalTreatment);
    } else {
        treatmentBuilder = DefaultTrafficTreatment.builder();
    }
    TrafficTreatment treatment = treatmentBuilder.setOutput(egress.port()).build();

    rules.add(DefaultFlowRule.builder()
            .forDevice(ingress.deviceId())
            .withSelector(selector)
            .withTreatment(treatment)
            .withPriority(priority)
            .fromApp(appId)
            .makePermanent()
            .build());

}
 
Example #25
Source File: Ofdpa2Pipeline.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Builds TMAC rules for IPv4 packets.
 *
 * @param ethCriterion dst mac matching
 * @param vidCriterion vlan id assigned to the port
 * @param ofdpaMatchVlanVid OFDPA vlan id matching
 * @param applicationId application id
 * @param pnum port number
 * @return TMAC rule for IPV4 packets
 */
private FlowRule buildTmacRuleForIpv4(EthCriterion ethCriterion,
                                      VlanIdCriterion vidCriterion,
                                      OfdpaMatchVlanVid ofdpaMatchVlanVid,
                                      ApplicationId applicationId,
                                      PortNumber pnum) {
    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
    if (pnum != null) {
        if (matchInPortTmacTable()) {
            selector.matchInPort(pnum);
        } else {
            log.debug("Pipeline does not support IN_PORT matching in TMAC table, " +
                    "ignoring the IN_PORT criteria");
        }
    }
    if (vidCriterion != null) {
        if (requireVlanExtensions()) {
            selector.extension(ofdpaMatchVlanVid, deviceId);
        } else {
            selector.matchVlanId(vidCriterion.vlanId());
        }
    }
    selector.matchEthType(Ethernet.TYPE_IPV4);
    selector.matchEthDst(ethCriterion.mac());
    treatment.transition(UNICAST_ROUTING_TABLE);
    return DefaultFlowRule.builder()
            .forDevice(deviceId)
            .withSelector(selector.build())
            .withTreatment(treatment.build())
            .withPriority(DEFAULT_PRIORITY)
            .fromApp(applicationId)
            .makePermanent()
            .forTable(TMAC_TABLE).build();
}
 
Example #26
Source File: OpenstackSwitchingArpHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
private void processFlowTableRules(OpenstackNode osNode,
                                    String segId, String netId,
                                    boolean isTunnel,
                                    boolean install) {
    TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder()
            .matchEthType(EthType.EtherType.ARP.ethType().toShort())
            .matchArpOp(ARP.OP_REQUEST);

    if (isTunnel) {
        sBuilder.matchTunnelId(Long.parseLong(segId));
    } else {
        sBuilder.matchVlanId(VlanId.vlanId(segId));
    }

    TrafficTreatment treatment = DefaultTrafficTreatment.builder()
            .group(GroupId.valueOf(netId.hashCode()))
            .build();

    osFlowRuleService.setRule(
            appId,
            osNode.intgBridge(),
            sBuilder.build(),
            treatment,
            PRIORITY_ARP_GROUP_RULE,
            ARP_TABLE,
            install
    );
}
 
Example #27
Source File: FlowEntryCodec.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public ObjectNode encode(FlowEntry flowEntry, CodecContext context) {
    checkNotNull(flowEntry, "Flow entry cannot be null");

    ObjectNode result = context.mapper().createObjectNode()
            .put(GROUP_ID, flowEntry.groupId().id())
            .put(STATE, flowEntry.state().toString())
            //FIXME life is destroying precision (seconds granularity is default)
            .put(LIFE, flowEntry.life())
            .put(LIVE_TYPE, flowEntry.liveType().toString())
            .put(LAST_SEEN, flowEntry.lastSeen())
            .put(PACKETS, flowEntry.packets())
            .put(BYTES, flowEntry.bytes())
            // encode FlowRule-specific fields using the FlowRule codec
            .setAll(context.codec(FlowRule.class).encode((FlowRule) flowEntry, context));

    if (flowEntry.treatment() != null) {
        final JsonCodec<TrafficTreatment> treatmentCodec =
                context.codec(TrafficTreatment.class);
        result.set(TREATMENT, treatmentCodec.encode(flowEntry.treatment(), context));
    }

    if (flowEntry.selector() != null) {
        final JsonCodec<TrafficSelector> selectorCodec =
                context.codec(TrafficSelector.class);
        result.set(SELECTOR, selectorCodec.encode(flowEntry.selector(), context));
    }

    return result;
}
 
Example #28
Source File: SpringOpenTTP.java    From onos with Apache License 2.0 5 votes vote down vote up
private void addBucketToGroup(NextObjective nextObjective) {
    log.debug("addBucketToGroup in {}: for next objective id {}",
              deviceId, nextObjective.id());
    Collection<TrafficTreatment> treatments = nextObjective.next();
    TrafficTreatment treatment = treatments.iterator().next();
    final GroupKey key = new DefaultGroupKey(
            appKryo.serialize(nextObjective
                    .id()));
    Group group = groupService.getGroup(deviceId, key);
    if (group == null) {
        log.warn("Group is not found in {} for {}", deviceId, key);
        return;
    }
    GroupBucket bucket;
    if (group.type() == GroupDescription.Type.INDIRECT) {
        bucket = DefaultGroupBucket.createIndirectGroupBucket(treatment);
    } else if (group.type() == GroupDescription.Type.SELECT) {
        bucket = DefaultGroupBucket.createSelectGroupBucket(treatment);
    } else if (group.type() == GroupDescription.Type.ALL) {
        bucket = DefaultGroupBucket.createAllGroupBucket(treatment);
    } else {
        log.warn("Unsupported Group type {}", group.type());
        return;
    }
    GroupBuckets bucketsToAdd = new GroupBuckets(Collections.singletonList(bucket));
    log.debug("Adding buckets to group id {} of next objective id {} in device {}",
              group.id(), nextObjective.id(), deviceId);
    groupService.addBucketsToGroup(deviceId, key, bucketsToAdd, key, appId);
}
 
Example #29
Source File: RoadmManager.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public FlowId createConnection(DeviceId deviceId, int priority, boolean isPermanent,
                               int timeout, PortNumber inPort, PortNumber outPort, OchSignal ochSignal) {
    checkNotNull(deviceId);
    checkNotNull(inPort);
    checkNotNull(outPort);

    //Creation of selector.
    TrafficSelector selector = DefaultTrafficSelector.builder()
            .add(Criteria.matchInPort(inPort))
            .add(Criteria.matchOchSignalType(OchSignalType.FIXED_GRID))
            .add(Criteria.matchLambda(ochSignal))
            .build();

    //Creation of treatment
    TrafficTreatment treatment = DefaultTrafficTreatment.builder()
            .add(Instructions.modL0Lambda(ochSignal))
            .add(Instructions.createOutput(outPort))
            .build();

    FlowRule.Builder flowBuilder = DefaultFlowRule.builder()
            .forDevice(deviceId)
            .fromApp(appId)
            .withPriority(priority)
            .withSelector(selector)
            .withTreatment(treatment);
    if (isPermanent) {
        flowBuilder.makePermanent();
    } else {
        flowBuilder.makeTemporary(timeout);
    }

    FlowRule flowRule = flowBuilder.build();
    flowRuleService.applyFlowRules(flowRule);

    log.info("Created connection from input port {} to output port {}",
            inPort.toLong(), outPort.toLong());

    return flowRule.id();
}
 
Example #30
Source File: CorsaL2OverlayPipeline.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void forward(ForwardingObjective fwd) {
    // The Corsa devices don't support the clear deferred actions
    // so for now we have to filter this instruction for the fwd
    // objectives sent by the Packet Manager before to create the
    // flow rule
    if (fwd.flag() == VERSATILE && fwd.treatment().clearedDeferred()) {
        // First we create a new treatment without the unsupported action
        TrafficTreatment.Builder noClearTreatment = DefaultTrafficTreatment.builder();
        fwd.treatment().allInstructions().forEach(noClearTreatment::add);
        // Then we create a new forwarding objective without the unsupported action
        ForwardingObjective.Builder noClearFwd = DefaultForwardingObjective.builder(fwd);
        noClearFwd.withTreatment(noClearTreatment.build());
        // According to the operation we substitute fwd with the correct objective
        switch (fwd.op()) {
            case ADD:
                fwd = noClearFwd.add(fwd.context().orElse(null));
                break;
            case REMOVE:
                fwd = noClearFwd.remove(fwd.context().orElse(null));
                break;
            default:
                log.warn("Unknown operation {}", fwd.op());
                return;
        }
    }
    // Finally we send to the DefaultSingleTablePipeline for the real processing
    super.forward(fwd);
}