Search in sources :

Example 91 with IpPrefix

use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.

the class PiCriterionTranslatorsTest method testLpmToTernaryTranslation.

@Test
public void testLpmToTernaryTranslation() throws Exception {
    IpPrefix ipPrefix = IpPrefix.valueOf("10.0.0.1/23");
    int bitWidth = ipPrefix.address().toOctets().length * Byte.SIZE;
    IPCriterion criterion = (IPCriterion) Criteria.matchIPDst(ipPrefix);
    PiTernaryFieldMatch ternaryMatch = (PiTernaryFieldMatch) translateCriterion(criterion, fieldId, TERNARY, bitWidth);
    ImmutableByteSequence expectedMask = ImmutableByteSequence.prefixOnes(Integer.BYTES, 23);
    ImmutableByteSequence expectedValue = ImmutableByteSequence.copyFrom(ipPrefix.address().toOctets());
    assertThat(ternaryMatch.mask(), is(expectedMask));
    assertThat(ternaryMatch.value(), is(expectedValue));
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) PiTernaryFieldMatch(org.onosproject.net.pi.runtime.PiTernaryFieldMatch) ImmutableByteSequence(org.onlab.util.ImmutableByteSequence) Test(org.junit.Test)

Example 92 with IpPrefix

use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.

the class SoftRouterPipeline method processSpecific.

/**
 * SoftRouter has a single specific table - the FIB Table. It emulates
 * LPM matching of dstIP by using higher priority flows for longer prefixes.
 * Flows are forwarded using flow-actions
 *
 * @param fwd The forwarding objective of type simple
 * @return A collection of flow rules meant to be delivered to the flowrule
 *         subsystem. Typically the returned collection has a single flowrule.
 *         May return empty collection in case of failures.
 */
private Collection<FlowRule> processSpecific(ForwardingObjective fwd) {
    log.debug("Processing specific forwarding objective to next:{}", fwd.nextId());
    TrafficSelector selector = fwd.selector();
    EthTypeCriterion ethType = (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE);
    // XXX currently supporting only the L3 unicast table
    if (ethType == null || (ethType.ethType().toShort() != TYPE_IPV4 && ethType.ethType().toShort() != Ethernet.TYPE_IPV6)) {
        fail(fwd, ObjectiveError.UNSUPPORTED);
        return Collections.emptySet();
    }
    // We build the selector according the eth type.
    IpPrefix ipPrefix;
    TrafficSelector.Builder filteredSelector;
    if (ethType.ethType().toShort() == TYPE_IPV4) {
        ipPrefix = ((IPCriterion) selector.getCriterion(Criterion.Type.IPV4_DST)).ip();
        filteredSelector = DefaultTrafficSelector.builder().matchEthType(TYPE_IPV4);
    } else {
        ipPrefix = ((IPCriterion) selector.getCriterion(Criterion.Type.IPV6_DST)).ip();
        filteredSelector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV6);
    }
    // If the prefix is different from the default via.
    if (ipPrefix.prefixLength() != 0) {
        if (ethType.ethType().toShort() == TYPE_IPV4) {
            filteredSelector.matchIPDst(ipPrefix);
        } else {
            filteredSelector.matchIPv6Dst(ipPrefix);
        }
    }
    TrafficTreatment tt = null;
    if (fwd.nextId() != null) {
        NextGroup next = flowObjectiveStore.getNextGroup(fwd.nextId());
        if (next == null) {
            log.error("next-id {} does not exist in store", fwd.nextId());
            return Collections.emptySet();
        }
        tt = appKryo.deserialize(next.data());
        if (tt == null) {
            log.error("Error in deserializing next-id {}", fwd.nextId());
            return Collections.emptySet();
        }
    }
    FlowRule.Builder ruleBuilder = DefaultFlowRule.builder().fromApp(fwd.appId()).withPriority(fwd.priority()).forDevice(deviceId).withSelector(filteredSelector.build());
    if (tt != null) {
        ruleBuilder.withTreatment(tt);
    }
    if (fwd.permanent()) {
        ruleBuilder.makePermanent();
    } else {
        ruleBuilder.makeTemporary(fwd.timeout());
    }
    ruleBuilder.forTable(FIB_TABLE);
    return Collections.singletonList(ruleBuilder.build());
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) NextGroup(org.onosproject.net.behaviour.NextGroup) EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 93 with IpPrefix

use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.

the class Ofdpa2GroupHandler method processBroadcastNextObjective.

/**
 * As per the OFDPA 2.0 TTP, packets are sent out of ports by using
 * a chain of groups. The broadcast Next Objective passed in by the application
 * has to be broken up into a group chain comprising of an
 * L2 Flood group or L3 Multicast group, whose buckets point to L2 Interface groups.
 *
 * @param nextObj  the nextObjective of type BROADCAST
 */
private void processBroadcastNextObjective(NextObjective nextObj) {
    VlanId assignedVlan = readVlanFromSelector(nextObj.meta());
    if (assignedVlan == null) {
        log.warn("VLAN ID required by broadcast next obj is missing. Abort.");
        fail(nextObj, ObjectiveError.BADPARAMS);
        return;
    }
    // Handling L2 multicast cases.
    MacAddress dstMac = readEthDstFromSelector(nextObj.meta());
    if (dstMac != null && dstMac.isMulticast()) {
        processL2MulticastNextObjective(nextObj);
        return;
    }
    // FIXME Improve the logic
    // If L2 load balancer is not involved, use L2IG. Otherwise, use L2UG.
    // The purpose is to make sure existing XConnect logic can still work on a configured port.
    List<GroupInfo> groupInfos;
    if (nextObj.nextTreatments().stream().allMatch(n -> n.type() == NextTreatment.Type.TREATMENT)) {
        groupInfos = prepareL2InterfaceGroup(nextObj, assignedVlan);
        log.debug("prepareL2InterfaceGroup");
    } else {
        groupInfos = prepareL2UnfilteredGroup(nextObj);
        log.debug("prepareL2UnfilteredGroup");
    }
    if (groupInfos == null || groupInfos.isEmpty()) {
        log.warn("No buckets for Broadcast NextObj {}", nextObj);
        fail(nextObj, ObjectiveError.GROUPMISSING);
        return;
    }
    IpPrefix ipDst = readIpDstFromSelector(nextObj.meta());
    if (ipDst != null) {
        if (ipDst.isMulticast()) {
            createL3MulticastGroup(nextObj, assignedVlan, groupInfos);
        } else {
            log.warn("Broadcast NextObj with non-multicast IP address {}", nextObj);
            fail(nextObj, ObjectiveError.BADPARAMS);
        }
    } else {
        createL2FloodGroup(nextObj, assignedVlan, groupInfos);
    }
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) MacAddress(org.onlab.packet.MacAddress) VlanId(org.onlab.packet.VlanId)

Example 94 with IpPrefix

use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.

the class OvsOfdpaPipeline method processDoubleTaggedFwd.

/**
 * Handles forwarding rules to the IP Unicast Routing.
 *
 * @param fwd the forwarding objective
 * @return A collection of flow rules, or an empty set
 */
protected Collection<FlowRule> processDoubleTaggedFwd(ForwardingObjective fwd) {
    // inner for UNICAST_ROUTING_TABLE_1, outer for UNICAST_ROUTING_TABLE
    TrafficSelector selector = fwd.selector();
    TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
    TrafficTreatment.Builder innerTtb = DefaultTrafficTreatment.builder();
    TrafficTreatment.Builder outerTtb = DefaultTrafficTreatment.builder();
    EthTypeCriterion ethType = (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE);
    if (ethType.ethType().toShort() == Ethernet.TYPE_IPV4) {
        sBuilder.matchEthType(Ethernet.TYPE_IPV4);
        sBuilder.matchVlanId(VlanId.ANY);
        IpPrefix ipv4Dst = ((IPCriterion) selector.getCriterion(Criterion.Type.IPV4_DST)).ip();
        if (!ipv4Dst.isMulticast() && ipv4Dst.prefixLength() == 32) {
            sBuilder.matchIPDst(ipv4Dst);
            if (fwd.nextId() != null) {
                NextGroup next = getGroupForNextObjective(fwd.nextId());
                if (next != null) {
                    List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data());
                    // we only need the top level group's key to point the flow to it
                    Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst());
                    if (group == null) {
                        log.warn("Group with key:{} for next-id:{} not found in dev:{}", gkeys.get(0).peekFirst(), fwd.nextId(), deviceId);
                        fail(fwd, ObjectiveError.GROUPMISSING);
                        return Collections.emptySet();
                    }
                    outerTtb.immediate().setVlanId(extractDummyVlanIdFromGroupId(group.id().id()));
                    // ACTSET_OUTPUT in OVS will match output action in write_action() set.
                    outerTtb.deferred().setOutput(extractOutputPortFromGroupId(group.id().id()));
                    outerTtb.transition(EGRESS_VLAN_FLOW_TABLE_IN_INGRESS);
                    innerTtb.deferred().group(group.id());
                    innerTtb.transition(ACL_TABLE);
                    FlowRule.Builder innerRuleBuilder = DefaultFlowRule.builder().fromApp(fwd.appId()).withPriority(fwd.priority()).forDevice(deviceId).withSelector(sBuilder.build()).withTreatment(innerTtb.build()).forTable(UNICAST_ROUTING_TABLE_1);
                    if (fwd.permanent()) {
                        innerRuleBuilder.makePermanent();
                    } else {
                        innerRuleBuilder.makeTemporary(fwd.timeout());
                    }
                    Collection<FlowRule> flowRuleCollection = new HashSet<>();
                    flowRuleCollection.add(innerRuleBuilder.build());
                    FlowRule.Builder outerRuleBuilder = DefaultFlowRule.builder().fromApp(fwd.appId()).withPriority(fwd.priority()).forDevice(deviceId).withSelector(sBuilder.build()).withTreatment(outerTtb.build()).forTable(UNICAST_ROUTING_TABLE);
                    if (fwd.permanent()) {
                        outerRuleBuilder.makePermanent();
                    } else {
                        outerRuleBuilder.makeTemporary(fwd.timeout());
                    }
                    flowRuleCollection.add(innerRuleBuilder.build());
                    flowRuleCollection.add(outerRuleBuilder.build());
                    return flowRuleCollection;
                } else {
                    log.warn("Cannot find group for nextId:{} in dev:{}. Aborting fwd:{}", fwd.nextId(), deviceId, fwd.id());
                    fail(fwd, ObjectiveError.FLOWINSTALLATIONFAILED);
                    return Collections.emptySet();
                }
            } else {
                log.warn("NextId is not specified in fwd:{}", fwd.id());
                fail(fwd, ObjectiveError.FLOWINSTALLATIONFAILED);
                return Collections.emptySet();
            }
        }
    }
    return Collections.emptySet();
}
Also used : NextGroup(org.onosproject.net.behaviour.NextGroup) NextGroup(org.onosproject.net.behaviour.NextGroup) Group(org.onosproject.net.group.Group) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Deque(java.util.Deque) IpPrefix(org.onlab.packet.IpPrefix) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) HashSet(java.util.HashSet)

Example 95 with IpPrefix

use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.

the class BgpUpdateMsgVer4 method parseWithdrawnRoutes.

/**
 * Parsing withdrawn routes from channel buffer.
 *
 * @param cb channelBuffer
 * @return list of IP prefix
 * @throws BgpParseException while parsing withdrawn routes
 */
public static LinkedList<IpPrefix> parseWithdrawnRoutes(ChannelBuffer cb) throws BgpParseException {
    LinkedList<IpPrefix> withDrwRoutes = new LinkedList<>();
    while (cb.readableBytes() > 0) {
        int length = cb.readByte();
        IpPrefix ipPrefix;
        if (length == 0) {
            byte[] prefix = new byte[] { 0 };
            ipPrefix = Validation.bytesToPrefix(prefix, length);
            withDrwRoutes.add(ipPrefix);
        } else {
            int len = length / BYTE_IN_BITS;
            int reminder = length % BYTE_IN_BITS;
            if (reminder > 0) {
                len = len + 1;
            }
            if (cb.readableBytes() < len) {
                Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.MALFORMED_ATTRIBUTE_LIST, cb.readableBytes());
            }
            byte[] prefix = new byte[len];
            cb.readBytes(prefix, 0, len);
            ipPrefix = Validation.bytesToPrefix(prefix, length);
            withDrwRoutes.add(ipPrefix);
        }
    }
    return withDrwRoutes;
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) LinkedList(java.util.LinkedList)

Aggregations

IpPrefix (org.onlab.packet.IpPrefix)107 Test (org.junit.Test)37 IpAddress (org.onlab.packet.IpAddress)29 LinkedList (java.util.LinkedList)24 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)22 BgpHeader (org.onosproject.bgpio.types.BgpHeader)22 BgpPathAttributes (org.onosproject.bgpio.protocol.ver4.BgpPathAttributes)21 AsPath (org.onosproject.bgpio.types.AsPath)21 BgpValueType (org.onosproject.bgpio.types.BgpValueType)21 Origin (org.onosproject.bgpio.types.Origin)21 OriginType (org.onosproject.bgpio.types.Origin.OriginType)21 Med (org.onosproject.bgpio.types.Med)20 TrafficSelector (org.onosproject.net.flow.TrafficSelector)20 ProtocolType (org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType)19 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)19 MpReachNlri (org.onosproject.bgpio.types.MpReachNlri)18 LinkStateAttributes (org.onosproject.bgpio.types.LinkStateAttributes)16 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)14 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)14 MacAddress (org.onlab.packet.MacAddress)12