Search in sources :

Example 1 with NextHop

use of org.onosproject.bgpio.types.NextHop in project onos by opennetworkinglab.

the class BgpPathAttributes method write.

/**
 * Write path attributes to channelBuffer.
 *
 * @param cb channelBuffer
 * @return object of BgpPathAttributes
 * @throws BgpParseException while parsing BGP path attributes
 */
public int write(ChannelBuffer cb) throws BgpParseException {
    if (pathAttribute == null) {
        return 0;
    }
    int iLenStartIndex = cb.writerIndex();
    ListIterator<BgpValueType> iterator = pathAttribute.listIterator();
    int pathAttributeIndx = cb.writerIndex();
    cb.writeShort(0);
    while (iterator.hasNext()) {
        BgpValueType attr = iterator.next();
        switch(attr.getType()) {
            case Origin.ORIGIN_TYPE:
                Origin origin = (Origin) attr;
                origin.write(cb);
                break;
            case AsPath.ASPATH_TYPE:
                AsPath asPath = (AsPath) attr;
                asPath.write(cb);
                break;
            case As4Path.AS4PATH_TYPE:
                As4Path as4Path = (As4Path) attr;
                as4Path.write(cb);
                break;
            case NextHop.NEXTHOP_TYPE:
                NextHop nextHop = (NextHop) attr;
                nextHop.write(cb);
                break;
            case Med.MED_TYPE:
                Med med = (Med) attr;
                med.write(cb);
                break;
            case LocalPref.LOCAL_PREF_TYPE:
                LocalPref localPref = (LocalPref) attr;
                localPref.write(cb);
                break;
            case Constants.BGP_EXTENDED_COMMUNITY:
                BgpExtendedCommunity extendedCommunity = (BgpExtendedCommunity) attr;
                extendedCommunity.write(cb);
                break;
            case WideCommunity.TYPE:
                WideCommunity wideCommunity = (WideCommunity) attr;
                wideCommunity.write(cb);
                break;
            case MpReachNlri.MPREACHNLRI_TYPE:
                MpReachNlri mpReach = (MpReachNlri) attr;
                mpReach.write(cb);
                break;
            case MpUnReachNlri.MPUNREACHNLRI_TYPE:
                MpUnReachNlri mpUnReach = (MpUnReachNlri) attr;
                mpUnReach.write(cb);
                break;
            case LINK_STATE_ATTRIBUTE_TYPE:
                LinkStateAttributes linkState = (LinkStateAttributes) attr;
                linkState.write(cb);
                break;
            default:
                return cb.writerIndex() - iLenStartIndex;
        }
    }
    int pathAttrLen = cb.writerIndex() - pathAttributeIndx;
    cb.setShort(pathAttributeIndx, (short) (pathAttrLen - 2));
    return cb.writerIndex() - iLenStartIndex;
}
Also used : BgpValueType(org.onosproject.bgpio.types.BgpValueType) Origin(org.onosproject.bgpio.types.Origin) MpUnReachNlri(org.onosproject.bgpio.types.MpUnReachNlri) NextHop(org.onosproject.bgpio.types.NextHop) BgpExtendedCommunity(org.onosproject.bgpio.types.BgpExtendedCommunity) Med(org.onosproject.bgpio.types.Med) LinkStateAttributes(org.onosproject.bgpio.types.LinkStateAttributes) AsPath(org.onosproject.bgpio.types.AsPath) As4Path(org.onosproject.bgpio.types.As4Path) LocalPref(org.onosproject.bgpio.types.LocalPref) WideCommunity(org.onosproject.bgpio.types.attr.WideCommunity) MpReachNlri(org.onosproject.bgpio.types.MpReachNlri)

Example 2 with NextHop

use of org.onosproject.bgpio.types.NextHop in project onos by opennetworkinglab.

the class BgpUpdateMsgTest method bgpUpdateMessageTest07.

/**
 * This test case checks update message with path attributes.
 */
@Test
public void bgpUpdateMessageTest07() 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, 0x3f, 0x02, 0x00, 0x00, 0x00, 0x1c, 0x40, 0x01, 0x01, 0x00, 0x40, 0x02, 0x00, 0x40, 0x03, 0x04, 0x03, 0x03, 0x03, 0x03, (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x04, 0x00, 0x00, 0x00, 0x64, 0x18, 0x0a, 0x1e, 0x03, 0x18, 0x0a, 0x1e, 0x02, 0x18, 0x0a, 0x1e, 0x01 };
    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) 63));
    BgpValueType testPathAttribute;
    Origin origin;
    AsPath asPath;
    NextHop nexthop;
    Med med;
    LocalPref localPref;
    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));
    // AS PATH value is empty in hex dump
    testPathAttribute = listIterator.next();
    asPath = (AsPath) testPathAttribute;
    List<Short> asPathValues = asPath.asPathSeq();
    assertThat(asPathValues.isEmpty(), is(true));
    testPathAttribute = listIterator.next();
    nexthop = (NextHop) testPathAttribute;
    byte[] nextHopAddr = new byte[] { 0x03, 0x03, 0x03, 0x03 };
    assertThat(nexthop.nextHop().toOctets(), is(nextHopAddr));
    testPathAttribute = listIterator.next();
    med = (Med) testPathAttribute;
    assertThat(med.med(), is(0));
    testPathAttribute = listIterator.next();
    localPref = (LocalPref) testPathAttribute;
    assertThat(localPref.localPref(), is(100));
    ListIterator<IpPrefix> listIterator1 = other.nlri().listIterator();
    byte[] prefix = new byte[] { 0x0a, 0x1e, 0x03, 0x00 };
    IpPrefix testPrefixValue = listIterator1.next();
    assertThat(testPrefixValue.prefixLength(), is((int) 24));
    assertThat(testPrefixValue.address().toOctets(), is(prefix));
}
Also used : BgpValueType(org.onosproject.bgpio.types.BgpValueType) Origin(org.onosproject.bgpio.types.Origin) OriginType(org.onosproject.bgpio.types.Origin.OriginType) NextHop(org.onosproject.bgpio.types.NextHop) BgpHeader(org.onosproject.bgpio.types.BgpHeader) Med(org.onosproject.bgpio.types.Med) LinkedList(java.util.LinkedList) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) IpPrefix(org.onlab.packet.IpPrefix) AsPath(org.onosproject.bgpio.types.AsPath) BgpPathAttributes(org.onosproject.bgpio.protocol.ver4.BgpPathAttributes) LocalPref(org.onosproject.bgpio.types.LocalPref) Test(org.junit.Test)

Example 3 with NextHop

use of org.onosproject.bgpio.types.NextHop in project onos by opennetworkinglab.

the class BgpUpdateMsgTest method bgpUpdateMessageTest30.

/**
 * This test case checks update message with as4 path attribute.
 */
@Test
public void bgpUpdateMessageTest30() 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, 0x3a, 0x02, 0x00, 0x00, 0x00, 0x21, 0x40, 0x01, 0x01, 0x00, (byte) 0xc0, 0x11, 0x0a, 0x02, 0x02, 0x00, 0x0a, 0x00, 0x01, 0x00, 0x28, 0x00, 0x01, 0x40, 0x02, 0x06, 0x02, 0x02, 0x5b, (byte) 0xa0, 0x5b, (byte) 0xa0, 0x40, 0x03, 0x04, (byte) 0xac, 0x10, 0x03, 0x01, 0x08, 0x28 };
    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;
    assertThat(other.getHeader().getMarker(), is(MARKER));
    assertThat(other.getHeader().getType(), is(UPDATE_MSG_TYPE));
    assertThat(other.getHeader().getLength(), is((short) 58));
    BgpValueType testPathAttribute;
    Origin origin;
    As4Path as4Path;
    AsPath asPath;
    NextHop nextHop;
    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();
    as4Path = (As4Path) testPathAttribute;
    ListIterator<Integer> listIterator2 = as4Path.as4PathSeq().listIterator();
    assertThat(listIterator2.next(), is(655361));
    testPathAttribute = listIterator.next();
    asPath = (AsPath) testPathAttribute;
    ListIterator<Short> listIterator3 = asPath.asPathSeq().listIterator();
    assertThat(listIterator3.next(), is((short) 23456));
    testPathAttribute = listIterator.next();
    nextHop = (NextHop) testPathAttribute;
    byte[] nextHopAddr = new byte[] { (byte) 0xac, 0x10, 0x03, 0x01 };
    assertThat(nextHop.nextHop().toOctets(), is(nextHopAddr));
    ListIterator<IpPrefix> listIterator1 = other.nlri().listIterator();
    byte[] prefix = new byte[] { 0x28, 0x00, 0x00, 0x00 };
    IpPrefix testPrefixValue = listIterator1.next();
    assertThat(testPrefixValue.prefixLength(), is((int) 8));
    assertThat(testPrefixValue.address().toOctets(), is(prefix));
}
Also used : BgpValueType(org.onosproject.bgpio.types.BgpValueType) Origin(org.onosproject.bgpio.types.Origin) OriginType(org.onosproject.bgpio.types.Origin.OriginType) NextHop(org.onosproject.bgpio.types.NextHop) BgpHeader(org.onosproject.bgpio.types.BgpHeader) LinkedList(java.util.LinkedList) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) IpPrefix(org.onlab.packet.IpPrefix) AsPath(org.onosproject.bgpio.types.AsPath) BgpPathAttributes(org.onosproject.bgpio.protocol.ver4.BgpPathAttributes) As4Path(org.onosproject.bgpio.types.As4Path) Test(org.junit.Test)

Aggregations

AsPath (org.onosproject.bgpio.types.AsPath)3 BgpValueType (org.onosproject.bgpio.types.BgpValueType)3 NextHop (org.onosproject.bgpio.types.NextHop)3 Origin (org.onosproject.bgpio.types.Origin)3 LinkedList (java.util.LinkedList)2 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)2 Test (org.junit.Test)2 IpPrefix (org.onlab.packet.IpPrefix)2 BgpPathAttributes (org.onosproject.bgpio.protocol.ver4.BgpPathAttributes)2 As4Path (org.onosproject.bgpio.types.As4Path)2 BgpHeader (org.onosproject.bgpio.types.BgpHeader)2 LocalPref (org.onosproject.bgpio.types.LocalPref)2 Med (org.onosproject.bgpio.types.Med)2 OriginType (org.onosproject.bgpio.types.Origin.OriginType)2 BgpExtendedCommunity (org.onosproject.bgpio.types.BgpExtendedCommunity)1 LinkStateAttributes (org.onosproject.bgpio.types.LinkStateAttributes)1 MpReachNlri (org.onosproject.bgpio.types.MpReachNlri)1 MpUnReachNlri (org.onosproject.bgpio.types.MpUnReachNlri)1 WideCommunity (org.onosproject.bgpio.types.attr.WideCommunity)1