Search in sources :

Example 21 with IpPrefix

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

the class BgpUpdateMsgTest method bgpUpdateMessageTest31.

/**
 * This test case checks update message with MPUnreach.
 */
@Test
public void bgpUpdateMessageTest31() throws BgpParseException {
    byte[] updateMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, // withdrawn routes
    (byte) 0xff, // withdrawn routes
    (byte) 0xff, // withdrawn routes
    0x00, // withdrawn routes
    0x5e, // withdrawn routes
    0x02, // withdrawn routes
    0x00, // withdrawn routes
    0x04, // withdrawn routes
    0x18, // withdrawn routes
    0x0a, // withdrawn routes
    0x01, // withdrawn routes
    0x01, // path attribute len
    0x00, // path attribute len
    0x43, // origin
    0x04, // origin
    0x01, // origin
    0x01, // origin
    0x00, // as_path
    0x40, // as_path
    0x02, // as_path
    0x04, // as_path
    0x02, // as_path
    0x01, // as_path
    (byte) 0xfd, // as_path
    (byte) 0xe9, // med
    (byte) 0x80, // med
    0x04, // med
    0x04, // med
    0x00, // med
    0x00, // med
    0x00, // med
    0x00, // mpunreach with safi = 71
    (byte) 0x80, // mpunreach with safi = 71
    0x0f, // mpunreach with safi = 71
    0x2e, // mpunreach with safi = 71
    0x40, // mpunreach with safi = 71
    0x04, // mpunreach with safi = 71
    0x47, 0x00, 0x01, 0x00, 0x27, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1a, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, // node nlri
    0x58 };
    ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
    buffer.writeBytes(updateMsg);
    BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
    BgpMessage message;
    BgpHeader bgpHeader = new BgpHeader();
    message = reader.readFrom(buffer, bgpHeader);
    assertThat(message, instanceOf(BgpUpdateMsg.class));
    BgpUpdateMsg other = (BgpUpdateMsg) message;
    assertThat(other.getHeader().getMarker(), is(MARKER));
    assertThat(other.getHeader().getType(), is(UPDATE_MSG_TYPE));
    assertThat(other.getHeader().getLength(), is((short) 94));
    ListIterator<IpPrefix> listIterator1 = other.withdrawnRoutes().listIterator();
    byte[] prefix = new byte[] { 0x0a, 0x01, 0x01, 0x00 };
    IpPrefix testPrefixValue = listIterator1.next();
    assertThat(testPrefixValue.prefixLength(), is((int) 24));
    assertThat(testPrefixValue.address().toOctets(), is(prefix));
    BgpValueType testPathAttribute;
    Origin origin;
    AsPath asPath;
    Med med;
    MpUnReachNlri mpUnReach;
    List<BgpValueType> pathAttributes = new LinkedList<>();
    BgpPathAttributes actualpathAttribute = other.bgpPathAttributes();
    pathAttributes = actualpathAttribute.pathAttributes();
    ListIterator<BgpValueType> listIterator = pathAttributes.listIterator();
    OriginType originValue = OriginType.IGP;
    testPathAttribute = listIterator.next();
    origin = (Origin) testPathAttribute;
    assertThat(origin.origin(), is(originValue));
    testPathAttribute = listIterator.next();
    asPath = (AsPath) testPathAttribute;
    ListIterator<Short> listIterator2 = asPath.asPathSeq().listIterator();
    assertThat(listIterator2.next(), is((short) 65001));
    testPathAttribute = listIterator.next();
    med = (Med) testPathAttribute;
    assertThat(med.med(), is(0));
    testPathAttribute = listIterator.next();
    mpUnReach = (MpUnReachNlri) testPathAttribute;
    assertThat(mpUnReach.mpUnReachNlriLen(), is((int) 46));
    assertThat(mpUnReach.getType(), is((short) 15));
    List<BgpLSNlri> testMpUnReachNlri = new LinkedList<>();
    testMpUnReachNlri = mpUnReach.mpUnReachNlri();
    ListIterator<BgpLSNlri> list1 = testMpUnReachNlri.listIterator();
    BgpLSNlri testnlri = list1.next();
    NlriType nlriType = org.onosproject.bgpio.protocol.NlriType.NODE;
    ProtocolType protocolId = org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO;
    assertThat(testnlri.getIdentifier(), is((long) 0));
    assertThat(testnlri.getNlriType(), is(nlriType));
    assertThat(testnlri.getProtocolId(), is(protocolId));
    BgpNodeLSNlriVer4 testNodenlri = (BgpNodeLSNlriVer4) testnlri;
    BgpNodeLSIdentifier testLocalNodeDescriptors = testNodenlri.getLocalNodeDescriptors();
    List<BgpValueType> testSubTlvs = new LinkedList<>();
    NodeDescriptors localNodeDescriptors = testLocalNodeDescriptors.getNodedescriptors();
    testSubTlvs = localNodeDescriptors.getSubTlvs();
    ListIterator<BgpValueType> subtlvlist1 = testSubTlvs.listIterator();
    AutonomousSystemTlv testAutonomousSystemTlv = (AutonomousSystemTlv) subtlvlist1.next();
    assertThat(testAutonomousSystemTlv.getAsNum(), is(2222));
    assertThat(testAutonomousSystemTlv.getType(), is((short) 512));
    BgpLSIdentifierTlv testBgpLsIdentifierTlv = (BgpLSIdentifierTlv) subtlvlist1.next();
    assertThat(testBgpLsIdentifierTlv.getBgpLsIdentifier(), is(33686018));
    assertThat(testBgpLsIdentifierTlv.getType(), is((short) 513));
    IsIsNonPseudonode testIsIsNonPseudonode = (IsIsNonPseudonode) subtlvlist1.next();
    byte[] expIsoNodeId = new byte[] { 0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x58 };
    assertThat(testIsIsNonPseudonode.getIsoNodeId(), is(expIsoNodeId));
    assertThat(testIsIsNonPseudonode.getType(), is((short) 515));
}
Also used : Origin(org.onosproject.bgpio.types.Origin) MpUnReachNlri(org.onosproject.bgpio.types.MpUnReachNlri) BgpHeader(org.onosproject.bgpio.types.BgpHeader) NodeDescriptors(org.onosproject.bgpio.protocol.linkstate.NodeDescriptors) BgpNodeLSIdentifier(org.onosproject.bgpio.protocol.linkstate.BgpNodeLSIdentifier) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) IpPrefix(org.onlab.packet.IpPrefix) BgpNodeLSNlriVer4(org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4) BgpValueType(org.onosproject.bgpio.types.BgpValueType) OriginType(org.onosproject.bgpio.types.Origin.OriginType) BgpLSIdentifierTlv(org.onosproject.bgpio.types.BgpLSIdentifierTlv) Med(org.onosproject.bgpio.types.Med) LinkedList(java.util.LinkedList) IsIsNonPseudonode(org.onosproject.bgpio.types.IsIsNonPseudonode) AsPath(org.onosproject.bgpio.types.AsPath) BgpPathAttributes(org.onosproject.bgpio.protocol.ver4.BgpPathAttributes) AutonomousSystemTlv(org.onosproject.bgpio.types.AutonomousSystemTlv) ProtocolType(org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType) Test(org.junit.Test)

Example 22 with IpPrefix

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

the class OpenstackVtapCriterionCodec method decode.

@Override
public OpenstackVtapCriterion decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    OpenstackVtapCriterion.Builder cBuilder = DefaultOpenstackVtapCriterion.builder();
    // parse source IP address
    IpPrefix srcIp = IpPrefix.valueOf(IpAddress.valueOf(nullIsIllegal(json.get(SRC_IP).asText(), SRC_IP + MISSING_MESSAGE)), 32);
    // parse destination IP address
    IpPrefix dstIp = IpPrefix.valueOf(IpAddress.valueOf(nullIsIllegal(json.get(DST_IP).asText(), DST_IP + MISSING_MESSAGE)), 32);
    cBuilder.srcIpPrefix(srcIp);
    cBuilder.dstIpPrefix(dstIp);
    // parse IP protocol
    String ipProtoStr = json.get(IP_PROTOCOL).asText();
    if (ipProtoStr != null) {
        cBuilder.ipProtocol(getProtocolTypeFromString(ipProtoStr));
    }
    // parse source port number
    int srcPort = json.get(SRC_PORT).asInt(0);
    // parse destination port number
    int dstPort = json.get(DST_PORT).asInt(0);
    cBuilder.srcTpPort(TpPort.tpPort(srcPort));
    cBuilder.dstTpPort(TpPort.tpPort(dstPort));
    return cBuilder.build();
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) DefaultOpenstackVtapCriterion(org.onosproject.openstackvtap.impl.DefaultOpenstackVtapCriterion) OpenstackVtapCriterion(org.onosproject.openstackvtap.api.OpenstackVtapCriterion) OpenstackVtapUtil.getProtocolTypeFromString(org.onosproject.openstackvtap.util.OpenstackVtapUtil.getProtocolTypeFromString)

Example 23 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 24 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 25 with IpPrefix

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

the class Ofdpa2Pipeline method buildIpv6Selector.

/**
 * Helper method to build Ipv6 selector using the selector provided by
 * a forwarding objective.
 *
 * @param builderToUpdate the builder to update
 * @param fwd the selector to read
 * @return 0 if the update ends correctly. -1 if the matches
 * are not yet supported
 */
int buildIpv6Selector(TrafficSelector.Builder builderToUpdate, ForwardingObjective fwd) {
    TrafficSelector selector = fwd.selector();
    IpPrefix ipv6Dst = ((IPCriterion) selector.getCriterion(Criterion.Type.IPV6_DST)).ip();
    if (ipv6Dst.isMulticast()) {
        if (ipv6Dst.prefixLength() != IpAddress.INET6_BIT_LENGTH) {
            log.warn("Multicast specific forwarding objective can only be /128");
            fail(fwd, ObjectiveError.BADPARAMS);
            return -1;
        }
        VlanId assignedVlan = readVlanFromSelector(fwd.meta());
        if (assignedVlan == null) {
            log.warn("VLAN ID required by multicast specific fwd obj is missing. Abort.");
            fail(fwd, ObjectiveError.BADPARAMS);
            return -1;
        }
        if (requireVlanExtensions()) {
            OfdpaMatchVlanVid ofdpaMatchVlanVid = new OfdpaMatchVlanVid(assignedVlan);
            builderToUpdate.extension(ofdpaMatchVlanVid, deviceId);
        } else {
            builderToUpdate.matchVlanId(assignedVlan);
        }
        builderToUpdate.matchEthType(Ethernet.TYPE_IPV6).matchIPv6Dst(ipv6Dst);
        log.debug("processing IPv6 multicast specific forwarding objective {} -> next:{}" + " in dev:{}", fwd.id(), fwd.nextId(), deviceId);
    } else {
        if (ipv6Dst.prefixLength() != 0) {
            builderToUpdate.matchIPv6Dst(ipv6Dst);
        }
        builderToUpdate.matchEthType(Ethernet.TYPE_IPV6);
        log.debug("processing IPv6 unicast specific forwarding objective {} -> next:{}" + " in dev:{}", fwd.id(), fwd.nextId(), deviceId);
    }
    return 0;
}
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) VlanId(org.onlab.packet.VlanId) OfdpaMatchVlanVid(org.onosproject.driver.extensions.OfdpaMatchVlanVid)

Aggregations

IpPrefix (org.onlab.packet.IpPrefix)131 Test (org.junit.Test)42 IpAddress (org.onlab.packet.IpAddress)36 LinkedList (java.util.LinkedList)24 TrafficSelector (org.onosproject.net.flow.TrafficSelector)24 MacAddress (org.onlab.packet.MacAddress)23 ConnectPoint (org.onosproject.net.ConnectPoint)23 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 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)21 Med (org.onosproject.bgpio.types.Med)20 VlanId (org.onlab.packet.VlanId)19 ProtocolType (org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType)19 MpReachNlri (org.onosproject.bgpio.types.MpReachNlri)18 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)18