Search in sources :

Example 31 with IpPrefix

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

the class ConnectivityIntentCommand method buildTrafficSelector.

/**
 * Constructs a traffic selector based on the command line arguments
 * presented to the command.
 * @return traffic selector
 */
protected TrafficSelector buildTrafficSelector() {
    IpPrefix srcIpPrefix = null;
    IpPrefix dstIpPrefix = null;
    TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
    if (!isNullOrEmpty(srcIpString)) {
        srcIpPrefix = IpPrefix.valueOf(srcIpString);
        if (srcIpPrefix.isIp4()) {
            selectorBuilder.matchIPSrc(srcIpPrefix);
        } else {
            selectorBuilder.matchIPv6Src(srcIpPrefix);
        }
    }
    if (!isNullOrEmpty(dstIpString)) {
        dstIpPrefix = IpPrefix.valueOf(dstIpString);
        if (dstIpPrefix.isIp4()) {
            selectorBuilder.matchIPDst(dstIpPrefix);
        } else {
            selectorBuilder.matchIPv6Dst(dstIpPrefix);
        }
    }
    if ((srcIpPrefix != null) && (dstIpPrefix != null) && (srcIpPrefix.version() != dstIpPrefix.version())) {
        // ERROR: IP src/dst version mismatch
        throw new IllegalArgumentException("IP source and destination version mismatch");
    }
    // 
    // Set the default EthType based on the IP version if the matching
    // source or destination IP prefixes.
    // 
    Short ethType = null;
    if ((srcIpPrefix != null) && srcIpPrefix.isIp6()) {
        ethType = EthType.IPV6.value();
    }
    if ((dstIpPrefix != null) && dstIpPrefix.isIp6()) {
        ethType = EthType.IPV6.value();
    }
    if (!isNullOrEmpty(ethTypeString)) {
        ethType = EthType.parseFromString(ethTypeString);
    }
    if (ethType != null) {
        selectorBuilder.matchEthType(ethType);
    }
    if (!isNullOrEmpty(vlanString)) {
        selectorBuilder.matchVlanId(VlanId.vlanId(Short.parseShort(vlanString)));
    }
    if (!isNullOrEmpty(srcMacString)) {
        selectorBuilder.matchEthSrc(MacAddress.valueOf(srcMacString));
    }
    if (!isNullOrEmpty(dstMacString)) {
        selectorBuilder.matchEthDst(MacAddress.valueOf(dstMacString));
    }
    if (!isNullOrEmpty(ipProtoString)) {
        short ipProtoShort = IpProtocol.parseFromString(ipProtoString);
        selectorBuilder.matchIPProtocol((byte) ipProtoShort);
    }
    if (!isNullOrEmpty(fLabelString)) {
        selectorBuilder.matchIPv6FlowLabel(Integer.parseInt(fLabelString));
    }
    if (!isNullOrEmpty(icmp6TypeString)) {
        byte icmp6Type = Icmp6Type.parseFromString(icmp6TypeString);
        selectorBuilder.matchIcmpv6Type(icmp6Type);
    }
    if (!isNullOrEmpty(icmp6CodeString)) {
        byte icmp6Code = Icmp6Code.parseFromString(icmp6CodeString);
        selectorBuilder.matchIcmpv6Code(icmp6Code);
    }
    if (!isNullOrEmpty(ndTargetString)) {
        selectorBuilder.matchIPv6NDTargetAddress(Ip6Address.valueOf(ndTargetString));
    }
    if (!isNullOrEmpty(ndSllString)) {
        selectorBuilder.matchIPv6NDSourceLinkLayerAddress(MacAddress.valueOf(ndSllString));
    }
    if (!isNullOrEmpty(ndTllString)) {
        selectorBuilder.matchIPv6NDTargetLinkLayerAddress(MacAddress.valueOf(ndTllString));
    }
    if (!isNullOrEmpty(srcTcpString)) {
        selectorBuilder.matchTcpSrc(TpPort.tpPort(Integer.parseInt(srcTcpString)));
    }
    if (!isNullOrEmpty(dstTcpString)) {
        selectorBuilder.matchTcpDst(TpPort.tpPort(Integer.parseInt(dstTcpString)));
    }
    if (extHdrStringList != null) {
        short extHdr = 0;
        for (String extHdrString : extHdrStringList) {
            extHdr = (short) (extHdr | ExtHeader.parseFromString(extHdrString));
        }
        selectorBuilder.matchIPv6ExthdrFlags(extHdr);
    }
    return selectorBuilder.build();
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector)

Example 32 with IpPrefix

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

the class InterfaceConfigTest method getIp.

private InterfaceIpAddress getIp(int index, int position) {
    IpPrefix subnet1 = IpPrefix.valueOf("1.2.0.0/16");
    IpAddress ip = IpAddress.valueOf("1.2.3." + Integer.toString(index + ((position - 1) * 10)));
    return new InterfaceIpAddress(ip, subnet1);
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) IpAddress(org.onlab.packet.IpAddress) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress)

Example 33 with IpPrefix

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

the class InterfaceIpAddressTest method testConstructorForDefaultBroadcastAddress.

/**
 * Tests valid class constructor for regular interface address with
 * default broadcast address.
 */
@Test
public void testConstructorForDefaultBroadcastAddress() {
    InterfaceIpAddress addr = new InterfaceIpAddress(IP_ADDRESS, SUBNET_ADDRESS);
    assertThat(addr.ipAddress(), is(IP_ADDRESS));
    assertThat(addr.subnetAddress(), is(SUBNET_ADDRESS));
    assertThat(addr.broadcastAddress(), is(DEF_BROADCAST_ADDRESS));
    assertThat(addr.peerAddress(), nullValue());
    IpPrefix subnetAddr = IpPrefix.valueOf("10.2.3.0/24");
    InterfaceIpAddress addr1 = new InterfaceIpAddress(IP_ADDRESS2, subnetAddr);
    assertThat(addr1.broadcastAddress().toString(), is("10.2.3.255"));
    IpAddress ipAddress = IpAddress.valueOf("2001::4");
    InterfaceIpAddress addr2 = new InterfaceIpAddress(ipAddress, V6_SUBNET_ADDRESS);
    assertThat(addr2.broadcastAddress(), is(nullValue()));
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) IpAddress(org.onlab.packet.IpAddress) Test(org.junit.Test)

Example 34 with IpPrefix

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

the class LinkCollectionCompiler method updateBuilder.

/**
 * Update the selector builder using a L3 instruction.
 *
 * @param builder the builder to update
 * @param l3instruction the l3 instruction to use
 */
private void updateBuilder(TrafficSelector.Builder builder, L3ModificationInstruction l3instruction) {
    // TODO check ethernet proto
    switch(l3instruction.subtype()) {
        case IPV4_SRC:
        case IPV4_DST:
        case IPV6_SRC:
        case IPV6_DST:
            ModIPInstruction ipInstr = (ModIPInstruction) l3instruction;
            // TODO check if ip falls in original prefix
            IpPrefix prefix = ipInstr.ip().toIpPrefix();
            switch(ipInstr.subtype()) {
                case IPV4_SRC:
                    builder.matchIPSrc(prefix);
                    break;
                case IPV4_DST:
                    builder.matchIPSrc(prefix);
                    break;
                case IPV6_SRC:
                    builder.matchIPv6Src(prefix);
                    break;
                case IPV6_DST:
                    builder.matchIPv6Dst(prefix);
                    break;
                default:
                    throw new IntentCompilationException(UNSUPPORTED_IP_SUBTYPE);
            }
            break;
        case IPV6_FLABEL:
            ModIPv6FlowLabelInstruction ipFlowInstr = (ModIPv6FlowLabelInstruction) l3instruction;
            builder.matchIPv6FlowLabel(ipFlowInstr.flowLabel());
            break;
        case DEC_TTL:
            // no-op
            break;
        case TTL_OUT:
            // no-op
            break;
        case TTL_IN:
            // no-op
            break;
        case ARP_SPA:
            ModArpIPInstruction srcArpIpInstr = (ModArpIPInstruction) l3instruction;
            if (srcArpIpInstr.ip().isIp4()) {
                builder.matchArpSpa((Ip4Address) srcArpIpInstr.ip());
            } else {
                throw new IntentCompilationException(UNSUPPORTED_ARP);
            }
            break;
        case ARP_SHA:
            ModArpEthInstruction srcArpEthInstr = (ModArpEthInstruction) l3instruction;
            builder.matchArpSha(srcArpEthInstr.mac());
            break;
        case ARP_TPA:
            ModArpIPInstruction dstArpIpInstr = (ModArpIPInstruction) l3instruction;
            if (dstArpIpInstr.ip().isIp4()) {
                builder.matchArpTpa((Ip4Address) dstArpIpInstr.ip());
            } else {
                throw new IntentCompilationException(UNSUPPORTED_ARP);
            }
            break;
        case ARP_THA:
            ModArpEthInstruction dstArpEthInstr = (ModArpEthInstruction) l3instruction;
            builder.matchArpTha(dstArpEthInstr.mac());
            break;
        case ARP_OP:
            ModArpOpInstruction arpOpInstr = (ModArpOpInstruction) l3instruction;
            // FIXME is the long to int cast safe?
            builder.matchArpOp((int) arpOpInstr.op());
            break;
        default:
            throw new IntentCompilationException(UNSUPPORTED_L3);
    }
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) ModArpEthInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpEthInstruction) ModIPv6FlowLabelInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction) IntentCompilationException(org.onosproject.net.intent.IntentCompilationException) ModArpOpInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpOpInstruction) ModIPInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction) ModArpIPInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpIPInstruction)

Example 35 with IpPrefix

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

the class OpenVSwitchPipeline method processSpecific.

private Collection<FlowRule> processSpecific(ForwardingObjective fwd) {
    log.debug("Processing specific forwarding objective");
    TrafficSelector selector = fwd.selector();
    TrafficTreatment tb = fwd.treatment();
    FlowRule.Builder ruleBuilder = DefaultFlowRule.builder().fromApp(fwd.appId()).withPriority(fwd.priority()).forDevice(deviceId).withSelector(selector).withTreatment(tb).makeTemporary(TIME_OUT);
    ruleBuilder.withPriority(fwd.priority());
    if (fwd.permanent()) {
        ruleBuilder.makePermanent();
    }
    Integer transition = null;
    Integer forTable = null;
    // MAC table flow rules
    if (selector.getCriterion(Type.TUNNEL_ID) != null && (selector.getCriterion(Type.ETH_DST) != null || selector.getCriterion(Type.ETH_SRC) != null)) {
        forTable = MAC_TABLE;
        return reassemblyFlowRule(ruleBuilder, tb, transition, forTable);
    }
    // CLASSIFIER table flow rules
    if (selector.getCriterion(Type.IN_PORT) != null) {
        forTable = CLASSIFIER_TABLE;
        if (selector.getCriterion(Type.ETH_SRC) != null && selector.getCriterion(Type.ETH_DST) != null) {
            transition = L3FWD_TABLE;
        } else if (selector.getCriterion(Type.ETH_SRC) != null || selector.getCriterion(Type.TUNNEL_ID) != null) {
            transition = MAC_TABLE;
        } else if (selector.getCriterion(Type.IPV4_DST) != null) {
            transition = DNAT_TABLE;
        } else if (selector.getCriterion(Type.ETH_TYPE) != null && selector.getCriterion(Type.ETH_TYPE).equals(Criteria.matchEthType(EtherType.ARP.ethType().toShort()))) {
            transition = ARP_TABLE;
        }
        return reassemblyFlowRule(ruleBuilder, tb, transition, forTable);
    }
    // ARP table flow rules
    if (selector.getCriterion(Type.ETH_TYPE) != null && selector.getCriterion(Type.ETH_TYPE).equals(Criteria.matchEthType(EtherType.ARP.ethType().toShort()))) {
        // CLASSIFIER table arp flow rules
        if (selector.getCriterion(Type.TUNNEL_ID) == null) {
            if (selector.getCriterion(Type.ARP_OP) != null) {
                forTable = CLASSIFIER_TABLE;
                return reassemblyFlowRule(ruleBuilder, tb, null, forTable);
            }
            transition = ARP_TABLE;
            forTable = CLASSIFIER_TABLE;
            return reassemblyFlowRule(ruleBuilder, tb, transition, forTable);
        }
        forTable = ARP_TABLE;
        return reassemblyFlowRule(ruleBuilder, tb, transition, forTable);
    }
    // SNAT table flow rules
    if (selector.getCriterion(Type.TUNNEL_ID) != null && selector.getCriterion(Type.IPV4_SRC) != null) {
        transition = MAC_TABLE;
        forTable = SNAT_TABLE;
        return reassemblyFlowRule(ruleBuilder, tb, transition, forTable);
    }
    // L3FWD table flow rules
    if (selector.getCriterion(Type.TUNNEL_ID) != null && selector.getCriterion(Type.IPV4_DST) != null) {
        transition = MAC_TABLE;
        forTable = L3FWD_TABLE;
        return reassemblyFlowRule(ruleBuilder, tb, transition, forTable);
    }
    // DNAT table flow rules
    if (selector.getCriterion(Type.IPV4_DST) != null) {
        IPCriterion ipCriterion = (IPCriterion) selector.getCriterion(Type.IPV4_DST);
        IpPrefix ipPrefix = ipCriterion.ip();
        // specific CLASSIFIER table flow rules for userdata
        if (ipPrefix.address().equals(IpAddress.valueOf(USERDATA_IP))) {
            forTable = CLASSIFIER_TABLE;
            transition = MAC_TABLE;
            return reassemblyFlowRule(ruleBuilder, tb, transition, forTable);
        }
        transition = L3FWD_TABLE;
        forTable = DNAT_TABLE;
        return reassemblyFlowRule(ruleBuilder, tb, transition, forTable);
    }
    return Collections.singletonList(ruleBuilder.build());
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) 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)

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