Search in sources :

Example 56 with IpPrefix

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

the class BgpUpdateMsgTest method bgpUpdateMessageTest40.

/**
 * Test for LinkStateattribute BgpAttrNodeRouterId and BgpLinkAttrName.
 *
 * @throws BgpParseException while parsing update message
 */
@Test
public void bgpUpdateMessageTest40() 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, (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x9A, 0x02, 0x00, 0x04, // withdrawn routes
    0x18, // withdrawn routes
    0x0a, // withdrawn routes
    0x01, // withdrawn routes
    0x01, // path attribute len
    0x00, // path attribute len
    0x7F, // 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, // mpreach
    (byte) 0x80, // mpreach
    0x0e, // mpreach
    0x53, // mpreach
    0x40, // mpreach
    0x04, // mpreach
    0x47, // nexthop
    0x04, // nexthop
    0x04, // nexthop
    0x00, // nexthop
    0x00, // nexthop
    0x01, // reserved
    0x00, 0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00, (byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19, // link nlri
    0x00, // link nlri
    (byte) 0x95, // link nlri
    0x02, // link nlri
    0x50, // link nlri
    0x21, // linkstate attr
    (byte) 0x80, // linkstate attr
    0x1d, // linkstate attr
    0x14, // BgpAttrRouterIdV4
    0x04, // BgpAttrRouterIdV4
    0x04, // BgpAttrRouterIdV4
    0x00, // BgpAttrRouterIdV4
    0x04, // BgpAttrRouterIdV4
    (byte) 0x15, // BgpAttrRouterIdV4
    0x15, // BgpAttrRouterIdV4
    0x15, // BgpAttrRouterIdV4
    0x15, 0x04, 0x4A, 0x00, 0x08, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, // BgpLinkAttrName
    0x0b };
    ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
    buffer.writeBytes(updateMsg);
    BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
    BgpMessage message = null;
    BgpHeader bgpHeader = new BgpHeader();
    message = reader.readFrom(buffer, bgpHeader);
    assertThat(message, instanceOf(BgpUpdateMsg.class));
    BgpUpdateMsg other = (BgpUpdateMsg) message;
    byte[] marker = 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, (byte) 0xff, (byte) 0xff };
    assertThat(other.getHeader().getMarker(), is(marker));
    assertThat(other.getHeader().getType(), is((byte) 2));
    assertThat(other.getHeader().getLength(), is((short) 154));
    ListIterator<IpPrefix> listIterator1 = other.withdrawnRoutes().listIterator();
    byte[] prefix = new byte[] { 0x0a, 0x01, 0x01, 0x00 };
    while (listIterator1.hasNext()) {
        IpPrefix testPrefixValue = listIterator1.next();
        assertThat(testPrefixValue.prefixLength(), is((int) 24));
        assertThat(testPrefixValue.address().toOctets(), is(prefix));
    }
    BgpValueType testPathAttribute = null;
    Origin origin;
    AsPath aspath;
    Med med;
    MpReachNlri mpReach;
    LinkStateAttributes linkStateAttr;
    List<BgpValueType> pathAttributeList = new LinkedList<>();
    BgpPathAttributes pathAttribute = other.bgpPathAttributes();
    pathAttributeList = pathAttribute.pathAttributes();
    ListIterator<BgpValueType> listIterator = pathAttributeList.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();
    mpReach = (MpReachNlri) testPathAttribute;
    assertThat(mpReach.mpReachNlriLen(), is((int) 83));
    assertThat(mpReach.getType(), is((short) 14));
    List<BgpLSNlri> testMpReachNlri = new LinkedList<>();
    testMpReachNlri = mpReach.mpReachNlri();
    ListIterator<BgpLSNlri> list1 = testMpReachNlri.listIterator();
    BgpLSNlri testnlri = list1.next();
    NlriType nlriType = org.onosproject.bgpio.protocol.NlriType.LINK;
    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));
    testPathAttribute = listIterator.next();
    linkStateAttr = (LinkStateAttributes) testPathAttribute;
    assertThat(linkStateAttr.getType(), is((short) 29));
    ListIterator<BgpValueType> list = linkStateAttr.linkStateAttributes().listIterator();
    byte[] ipBytes = new byte[] { (byte) 0x15, 0x15, 0x15, 0x15 };
    Ip4Address ip4RouterId = Ip4Address.valueOf(ipBytes);
    assertThat(((BgpAttrRouterIdV4) list.next()).attrRouterId(), is(ip4RouterId));
    byte[] linkName = new byte[] { 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x0b };
    assertThat(((BgpLinkAttrName) list.next()).attrLinkName(), is(linkName));
}
Also used : Origin(org.onosproject.bgpio.types.Origin) Ip4Address(org.onlab.packet.Ip4Address) BgpHeader(org.onosproject.bgpio.types.BgpHeader) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) IpPrefix(org.onlab.packet.IpPrefix) BgpValueType(org.onosproject.bgpio.types.BgpValueType) OriginType(org.onosproject.bgpio.types.Origin.OriginType) Med(org.onosproject.bgpio.types.Med) LinkedList(java.util.LinkedList) LinkStateAttributes(org.onosproject.bgpio.types.LinkStateAttributes) AsPath(org.onosproject.bgpio.types.AsPath) BgpPathAttributes(org.onosproject.bgpio.protocol.ver4.BgpPathAttributes) ProtocolType(org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType) MpReachNlri(org.onosproject.bgpio.types.MpReachNlri) Test(org.junit.Test)

Example 57 with IpPrefix

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

the class MappingAddressBuilder method afi2mapping.

/**
 * Converts AFI address to generalized mapping address.
 *
 * @param afiAddress IP typed AFI address
 * @return generalized mapping address
 */
private static MappingAddress afi2mapping(LispAfiAddress afiAddress) {
    switch(afiAddress.getAfi()) {
        case IP4:
            IpAddress ipv4Address = ((LispIpv4Address) afiAddress).getAddress();
            IpPrefix ipv4Prefix = IpPrefix.valueOf(ipv4Address, IPV4_PREFIX_LENGTH);
            return MappingAddresses.ipv4MappingAddress(ipv4Prefix);
        case IP6:
            IpAddress ipv6Address = ((LispIpv6Address) afiAddress).getAddress();
            IpPrefix ipv6Prefix = IpPrefix.valueOf(ipv6Address, IPV6_PREFIX_LENGTH);
            return MappingAddresses.ipv6MappingAddress(ipv6Prefix);
        default:
            log.warn("Only support to convert IP address type");
            break;
    }
    return null;
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) LispIpv6Address(org.onosproject.lisp.msg.types.LispIpv6Address) LispIpv4Address(org.onosproject.lisp.msg.types.LispIpv4Address) IpAddress(org.onlab.packet.IpAddress)

Example 58 with IpPrefix

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

the class PIMAddrSource method setAddr.

/**
 * PIM Encoded Source Address.
 *
 * @param addr IPv4 or IPv6
 */
public void setAddr(String addr) {
    IpPrefix spfx = IpPrefix.valueOf(addr);
    setAddr(spfx);
}
Also used : IpPrefix(org.onlab.packet.IpPrefix)

Example 59 with IpPrefix

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

the class PIMJoinPrune method serialize.

/**
 * Sets all payloads parent packet if applicable, then serializes this
 * packet and all payloads.
 *
 * @return a byte[] containing this packet and payloads
 */
@Override
public byte[] serialize() {
    // Come up with something better
    byte[] data = new byte[8096];
    ByteBuffer bb = ByteBuffer.wrap(data);
    bb.put(upstreamAddr.serialize());
    // reserved
    bb.put((byte) 0);
    int ngrps = joinPrunes.size();
    bb.put((byte) ngrps);
    bb.putShort(this.holdTime);
    // Walk the group list and input all groups
    for (PIMJoinPruneGroup jpg : joinPrunes.values()) {
        PIMAddrGroup grp = new PIMAddrGroup(jpg.getGroup());
        bb.put(grp.serialize());
        // put the number of joins and prunes
        bb.putShort((short) jpg.getJoins().size());
        bb.putShort((short) jpg.getPrunes().size());
        // Set all of the joins
        for (IpPrefix spfx : jpg.getJoins().values()) {
            PIMAddrSource src = new PIMAddrSource(spfx);
            bb.put(src.serialize());
        }
        // Set all of the prunes
        for (IpPrefix spfx : jpg.getPrunes().values()) {
            PIMAddrSource src = new PIMAddrSource(spfx);
            bb.put(src.serialize());
        }
    }
    int len = bb.position();
    byte[] data2 = new byte[len];
    bb = ByteBuffer.wrap(data2, 0, len);
    bb.put(data, 0, len);
    return data2;
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) ByteBuffer(java.nio.ByteBuffer)

Example 60 with IpPrefix

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

the class PIMJoinPrune method addJoinPrune.

/**
 * Add the specified s,g to join field.
 *
 * @param saddr the source address of the route
 * @param gaddr the group address of the route
 * @param join true for a join, false for a prune.
 */
public void addJoinPrune(String saddr, String gaddr, boolean join) {
    IpPrefix gpfx = IpPrefix.valueOf(gaddr);
    IpPrefix spfx = IpPrefix.valueOf(saddr);
    addJoinPrune(spfx, gpfx, join);
}
Also used : IpPrefix(org.onlab.packet.IpPrefix)

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