Search in sources :

Example 1 with BgpHeader

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

the class BgpNotificationMsgTest method bgpNotificationMessageTest3.

// Negative scenarios
/**
 * Notification message with wrong maker value.
 *
 * @throws BgpParseException while decoding and encoding notification message
 */
@Test(expected = BgpParseException.class)
public void bgpNotificationMessageTest3() throws BgpParseException {
    byte[] notificationMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x01, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x00, 0x15, 0x03, 0x02, 0x00 };
    byte[] testNotificationMsg = { 0 };
    ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
    buffer.writeBytes(notificationMsg);
    BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
    BgpMessage message = null;
    BgpHeader bgpHeader = new BgpHeader();
    message = reader.readFrom(buffer, bgpHeader);
    assertThat(message, instanceOf(BgpNotificationMsg.class));
    ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
    message.writeTo(buf);
    testNotificationMsg = buf.array();
    int iReadLen = buf.writerIndex() - 0;
    testNotificationMsg = new byte[iReadLen];
    buf.readBytes(testNotificationMsg, 0, iReadLen);
    assertThat(testNotificationMsg, is(notificationMsg));
}
Also used : BgpHeader(org.onosproject.bgpio.types.BgpHeader) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) Test(org.junit.Test)

Example 2 with BgpHeader

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

the class BgpNotificationMsgTest method bgpNotificationMessageTest2.

/**
 * Notification message without data.
 *
 * @throws BgpParseException  while decoding and encoding notification message
 */
@Test
public void bgpNotificationMessageTest2() throws BgpParseException {
    byte[] notificationMsg = 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, 0x15, 0x03, 0x02, 0x00 };
    byte[] testNotificationMsg = { 0 };
    ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
    buffer.writeBytes(notificationMsg);
    BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
    BgpMessage message = null;
    BgpHeader bgpHeader = new BgpHeader();
    message = reader.readFrom(buffer, bgpHeader);
    assertThat(message, instanceOf(BgpNotificationMsg.class));
    ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
    message.writeTo(buf);
    testNotificationMsg = buf.array();
    int iReadLen = buf.writerIndex() - 0;
    testNotificationMsg = new byte[iReadLen];
    buf.readBytes(testNotificationMsg, 0, iReadLen);
    assertThat(testNotificationMsg, is(notificationMsg));
}
Also used : BgpHeader(org.onosproject.bgpio.types.BgpHeader) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) Test(org.junit.Test)

Example 3 with BgpHeader

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

the class BgpUpdateMsg2Test method bgpUpdateMessage2Test4.

/**
 * This test case checks the changes made in.
 * LinkStateAttributes (For Link State Attribute Type 1173 i.e. Extended Administrative Group)
 * as bug fix for bug 8036
 */
@Test
public void bgpUpdateMessage2Test4() 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, (byte) 0x01, (byte) 0x19, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x90, (byte) 0x0e, (byte) 0x00, (byte) 0x6e, (byte) 0x40, (byte) 0x04, (byte) 0x47, (byte) 0x10, (byte) 0x20, (byte) 0x01, (byte) 0x05, (byte) 0xb0, (byte) 0x00, (byte) 0x08, (byte) 0x00, (byte) 0x00, (byte) 0x50, (byte) 0x54, (byte) 0x00, (byte) 0xff, (byte) 0xfe, (byte) 0xb8, (byte) 0x35, (byte) 0x2b, (byte) 0x00, (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x55, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x03, (byte) 0xe9, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x1a, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x64, (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x2b, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x1a, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x64, (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x1b, (byte) 0x01, (byte) 0x03, (byte) 0x00, (byte) 0x04, (byte) 0x70, (byte) 0x70, (byte) 0x70, (byte) 0xd5, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x04, (byte) 0x70, (byte) 0x70, (byte) 0x70, (byte) 0xd4, (byte) 0x40, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x40, (byte) 0x02, (byte) 0x00, (byte) 0x40, (byte) 0x05, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x64, (byte) 0x80, (byte) 0x1d, (byte) 0x7f, (byte) 0x04, (byte) 0x04, (byte) 0x00, (byte) 0x04, (byte) 0xc0, (byte) 0xa8, (byte) 0x07, (byte) 0xca, (byte) 0x04, (byte) 0x06, (byte) 0x00, (byte) 0x04, (byte) 0xc0, (byte) 0xa8, (byte) 0x07, (byte) 0xc9, (byte) 0x04, (byte) 0x40, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x41, (byte) 0x00, (byte) 0x04, (byte) 0x49, (byte) 0xb7, (byte) 0x1b, (byte) 0x00, (byte) 0x04, (byte) 0x42, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x43, (byte) 0x00, (byte) 0x20, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x44, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0a, (byte) 0x04, (byte) 0x47, (byte) 0x00, (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x0a, // ------------ BGP-LS ATTR_EXTNDED_ADMNSTRATIVE_GRP Attribute------------------------------------------
    (byte) 0x04, (byte) 0x95, (byte) 0x00, (byte) 0x20, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 // -----------------------------------------------------------------------------------------------------
    };
    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 receivedMsg = (BgpUpdateMsg) message;
    List<BgpValueType> pathAttr = receivedMsg.bgpPathAttributes().pathAttributes();
    ListIterator<BgpValueType> iterator = pathAttr.listIterator();
    while (iterator.hasNext()) {
        BgpValueType attr = iterator.next();
        if (attr instanceof LinkStateAttributes) {
            assertThat(((LinkStateAttributes) attr).linkStateAttributes().size(), is(9));
        }
    }
}
Also used : BgpValueType(org.onosproject.bgpio.types.BgpValueType) BgpHeader(org.onosproject.bgpio.types.BgpHeader) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) LinkStateAttributes(org.onosproject.bgpio.types.LinkStateAttributes) Test(org.junit.Test)

Example 4 with BgpHeader

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

the class BgpUpdateMsg2Test method bgpUpdateMessage2Test1.

/**
 * This test case checks the changes made in.
 * BgpLinkLSIdentifier
 * BgpAttrNodeMultiTopologyId
 * as bug fix for bug 8036
 */
@Test
public void bgpUpdateMessage2Test1() 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, (byte) 0x00, (byte) 0xe6, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xcf, (byte) 0x90, (byte) 0x0e, (byte) 0x00, (byte) 0xb3, (byte) 0x40, (byte) 0x04, (byte) 0x47, (byte) 0x10, (byte) 0x20, (byte) 0x01, (byte) 0x05, (byte) 0xb0, (byte) 0x00, (byte) 0x08, (byte) 0x00, (byte) 0x00, (byte) 0x50, (byte) 0x54, (byte) 0x00, (byte) 0xff, (byte) 0xfe, (byte) 0xb8, (byte) 0x35, (byte) 0x2b, (byte) 0x00, (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x4b, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x03, (byte) 0xe9, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x1a, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x64, (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x1b, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x1a, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x64, (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x2b, // ---------- BgpAttrNodeMultiTopologyId for Link 1-----------------------------------------------------
    (byte) 0x01, (byte) 0x07, (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x02, // -----------------------------------------------------------------------------------------------------
    (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x4b, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x03, (byte) 0xe9, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x1a, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x64, (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x2b, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x1a, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x64, (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x1b, // ------------ BgpAttrNodeMultiTopologyId for Link 2 --------------------------------------------------
    (byte) 0x01, (byte) 0x07, (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x02, // -----------------------------------------------------------------------------------------------------
    (byte) 0x40, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x40, (byte) 0x02, (byte) 0x00, (byte) 0x40, (byte) 0x05, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x64, (byte) 0x80, (byte) 0x1d, (byte) 0x07, (byte) 0x04, (byte) 0x47, (byte) 0x00, (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x0a };
    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 receivedMsg = (BgpUpdateMsg) message;
    List<BgpValueType> pathAttr = receivedMsg.bgpPathAttributes().pathAttributes();
    ListIterator<BgpValueType> iterator = pathAttr.listIterator();
    while (iterator.hasNext()) {
        BgpValueType attr = iterator.next();
        if (attr instanceof MpReachNlri) {
            List<BgpLSNlri> nlri = ((MpReachNlri) attr).mpReachNlri();
            ListIterator<BgpLSNlri> listIterator = nlri.listIterator();
            while (listIterator.hasNext()) {
                BgpLSNlri nlriInfo = listIterator.next();
                if (nlriInfo instanceof BgpLinkLsNlriVer4) {
                    List<BgpValueType> tlvs = ((BgpLinkLsNlriVer4) nlriInfo).getLinkIdentifier().linkDescriptors();
                    for (BgpValueType tlv : tlvs) {
                        if (tlv instanceof BgpAttrNodeMultiTopologyId) {
                            assertThat(((BgpAttrNodeMultiTopologyId) tlv).attrMultiTopologyId().size(), is(1));
                            assertThat(((BgpAttrNodeMultiTopologyId) tlv).attrMultiTopologyId().get(0), is((short) 2));
                        }
                    }
                }
            }
        }
    }
}
Also used : BgpValueType(org.onosproject.bgpio.types.BgpValueType) BgpHeader(org.onosproject.bgpio.types.BgpHeader) BgpAttrNodeMultiTopologyId(org.onosproject.bgpio.types.attr.BgpAttrNodeMultiTopologyId) BgpLinkLsNlriVer4(org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) MpReachNlri(org.onosproject.bgpio.types.MpReachNlri) Test(org.junit.Test)

Example 5 with BgpHeader

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

the class BgpUpdateMsg2Test method bgpUpdateMessage2Test2.

/**
 * This test case checks the changes made in.
 * BgpPrefixLSIdentifier
 * MpReachNlri (read method AFI 16388/SAFI 71 if part)
 * BgpPrefixIPv4LSNlriVer4
 * LinkStateAttributes (ATTR_PREFIX_FLAGS check)
 * BgpAttrNodeMultiTopologyId
 * Validation
 * IPReachabilityInformationTlv
 * as bug fix for bug 8036
 */
@Test
public void bgpUpdateMessage2Test2() 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, (byte) 0x01, (byte) 0x08, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xf1, (byte) 0x90, (byte) 0x0e, (byte) 0x00, (byte) 0xcf, (byte) 0x40, (byte) 0x04, (byte) 0x47, (byte) 0x10, // ------------ MpReachNlri Nexthop --------------------------------------------------------------------
    (byte) 0x20, (byte) 0x01, (byte) 0x05, (byte) 0xb0, (byte) 0x00, (byte) 0x08, (byte) 0x00, (byte) 0x00, (byte) 0x50, // -----------------------------------------------------------------------------------------------------
    (byte) 0x54, (byte) 0x00, (byte) 0xff, (byte) 0xfe, (byte) 0xb8, (byte) 0x35, (byte) 0x2b, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x3a, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x03, (byte) 0xe9, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x1a, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x64, (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x2b, // ------------ BgpAttrNodeMultiTopologyId for Prefix 1-------------------------------------------------
    (byte) 0x01, (byte) 0x07, (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x02, // ------------ IPReachabilityInformationTlv for Prefix 1-----------------------------------------------
    (byte) 0x01, (byte) 0x09, (byte) 0x00, (byte) 0x09, (byte) 0x40, (byte) 0x20, (byte) 0x01, (byte) 0x05, (byte) 0xb0, (byte) 0x43, (byte) 0x21, (byte) 0x00, (byte) 0x00, // -----------------------------------------------------------------------------------------------------
    (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x3a, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x03, (byte) 0xe9, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x1a, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x64, (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x1b, // ------------ BgpAttrNodeMultiTopologyId for Prefix 2-------------------------------------------------
    (byte) 0x01, (byte) 0x07, (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x02, // ------------ IPReachabilityInformationTlv for Prefix 2-----------------------------------------------
    (byte) 0x01, (byte) 0x09, (byte) 0x00, (byte) 0x09, (byte) 0x40, (byte) 0x20, (byte) 0x01, (byte) 0x05, (byte) 0xb0, (byte) 0x43, (byte) 0x21, (byte) 0x00, (byte) 0x00, // -----------------------------------------------------------------------------------------------------
    (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x3a, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x03, (byte) 0xe9, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x1a, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x64, (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x1b, // ------------ BgpAttrNodeMultiTopologyId for Prefix 3-------------------------------------------------
    (byte) 0x01, (byte) 0x07, (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x02, // ------------ IPReachabilityInformationTlv for Prefix 3-----------------------------------------------
    (byte) 0x01, (byte) 0x09, (byte) 0x00, (byte) 0x09, (byte) 0x40, (byte) 0x20, (byte) 0x01, (byte) 0x05, (byte) 0xb0, (byte) 0x00, (byte) 0x08, (byte) 0x00, (byte) 0x00, // -----------------------------------------------------------------------------------------------------
    (byte) 0x40, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x40, (byte) 0x02, (byte) 0x00, (byte) 0x40, (byte) 0x05, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x64, (byte) 0x80, (byte) 0x1d, (byte) 0x0d, (byte) 0x04, (byte) 0x83, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0a, // ------------ BGP-LS ATTR_PREFIX_FLAGS Attribute-----------------------------------------------
    (byte) 0x04, (byte) 0x92, (byte) 0x00, (byte) 0x01, (byte) 0x00 // -----------------------------------------------------------------------------------------------------
    };
    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 receivedMsg = (BgpUpdateMsg) message;
    List<BgpValueType> pathAttr = receivedMsg.bgpPathAttributes().pathAttributes();
    ListIterator<BgpValueType> iterator = pathAttr.listIterator();
    short count = 0;
    while (iterator.hasNext()) {
        BgpValueType attr = iterator.next();
        if (attr instanceof MpReachNlri) {
            List<BgpLSNlri> nlri = ((MpReachNlri) attr).mpReachNlri();
            assertThat(((MpReachNlri) attr).nexthop().toString(), is("2001:5b0:8:0:5054:ff:feb8:352b"));
            ListIterator<BgpLSNlri> listIterator = nlri.listIterator();
            while (listIterator.hasNext()) {
                BgpLSNlri nlriInfo = listIterator.next();
                assertThat(nlriInfo, instanceOf(BgpPrefixIPv4LSNlriVer4.class));
                if (nlriInfo instanceof BgpPrefixIPv4LSNlriVer4) {
                    List<BgpValueType> tlvs = ((BgpPrefixIPv4LSNlriVer4) nlriInfo).getPrefixIdentifier().getPrefixdescriptor();
                    for (BgpValueType tlv : tlvs) {
                        if (tlv instanceof BgpAttrNodeMultiTopologyId) {
                            assertThat(((BgpAttrNodeMultiTopologyId) tlv).attrMultiTopologyId().size(), is(1));
                            assertThat(((BgpAttrNodeMultiTopologyId) tlv).attrMultiTopologyId().get(0), is((short) 2));
                        } else if (tlv instanceof IPReachabilityInformationTlv) {
                            if (count == 0) {
                                assertThat(((IPReachabilityInformationTlv) tlv).getPrefixValue().toString(), is("2001:5b0:4321::/64"));
                            } else if (count == 1) {
                                assertThat(((IPReachabilityInformationTlv) tlv).getPrefixValue().toString(), is("2001:5b0:4321::/64"));
                            } else {
                                assertThat(((IPReachabilityInformationTlv) tlv).getPrefixValue().toString(), is("2001:5b0:8::/64"));
                            }
                            count++;
                        }
                    }
                }
            }
        } else if (attr instanceof LinkStateAttributes) {
            assertThat(((LinkStateAttributes) attr).linkStateAttributes().size(), is(2));
        }
    }
}
Also used : BgpValueType(org.onosproject.bgpio.types.BgpValueType) BgpHeader(org.onosproject.bgpio.types.BgpHeader) BgpAttrNodeMultiTopologyId(org.onosproject.bgpio.types.attr.BgpAttrNodeMultiTopologyId) IPReachabilityInformationTlv(org.onosproject.bgpio.types.IPReachabilityInformationTlv) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) LinkStateAttributes(org.onosproject.bgpio.types.LinkStateAttributes) BgpPrefixIPv4LSNlriVer4(org.onosproject.bgpio.protocol.linkstate.BgpPrefixIPv4LSNlriVer4) MpReachNlri(org.onosproject.bgpio.types.MpReachNlri) Test(org.junit.Test)

Aggregations

BgpHeader (org.onosproject.bgpio.types.BgpHeader)84 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)83 Test (org.junit.Test)83 BgpValueType (org.onosproject.bgpio.types.BgpValueType)33 LinkedList (java.util.LinkedList)27 BgpPathAttributes (org.onosproject.bgpio.protocol.ver4.BgpPathAttributes)26 AsPath (org.onosproject.bgpio.types.AsPath)26 MpReachNlri (org.onosproject.bgpio.types.MpReachNlri)26 Origin (org.onosproject.bgpio.types.Origin)26 OriginType (org.onosproject.bgpio.types.Origin.OriginType)26 Med (org.onosproject.bgpio.types.Med)25 ProtocolType (org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType)24 LinkStateAttributes (org.onosproject.bgpio.types.LinkStateAttributes)23 IpPrefix (org.onlab.packet.IpPrefix)22 Ip4Address (org.onlab.packet.Ip4Address)12 NodeDescriptors (org.onosproject.bgpio.protocol.linkstate.NodeDescriptors)4 AutonomousSystemTlv (org.onosproject.bgpio.types.AutonomousSystemTlv)4 BgpLSIdentifierTlv (org.onosproject.bgpio.types.BgpLSIdentifierTlv)4 IsIsNonPseudonode (org.onosproject.bgpio.types.IsIsNonPseudonode)4 BgpAttrNodeMultiTopologyId (org.onosproject.bgpio.types.attr.BgpAttrNodeMultiTopologyId)4