Search in sources :

Example 61 with BgpHeader

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

the class BgpUpdateLinkStateAttrTest method bgpUpdateMessageTest7.

/**
 * Test for LinkStateattribute BgpAttrNodeRouterId and BgpAttrNodeMultiTopologyId.
 *
 * @throws BgpParseException while parsing update message
 */
@Test
public void bgpUpdateMessageTest7() 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) 0x96, 0x02, 0x00, 0x04, // withdrawn routes
    0x18, // withdrawn routes
    0x0a, // withdrawn routes
    0x01, // withdrawn routes
    0x01, // path attribute len
    0x00, // path attribute len
    0x7b, // 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
    0x10, // BgpAttrNodeRouterId
    0x04, // BgpAttrNodeRouterId
    0x04, // BgpAttrNodeRouterId
    0x00, // BgpAttrNodeRouterId
    0x04, // BgpAttrNodeRouterId
    (byte) 0x15, // BgpAttrNodeRouterId
    0x15, // BgpAttrNodeRouterId
    0x15, // BgpAttrNodeRouterId
    0x15, 0x01, 0x07, 0x00, 0x04, 0x00, 0x00, 0x00, // BgpAttrNodeMultiTopologyId
    0x02 };
    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) 150));
    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;
    byte[] linkAttrbs = new byte[] { (byte) 0x80, 0x1d, 0x10, 0x04, 0x04, 0x00, 0x04, (byte) 0x15, 0x15, 0x15, 0x15, 0x01, 0x07, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02 };
    ChannelBuffer cb = ChannelBuffers.dynamicBuffer();
    cb.writeBytes(linkAttrbs);
    LinkStateAttributes obj = LinkStateAttributes.read(cb);
    ListIterator<BgpValueType> list = obj.linkStateAttributes().listIterator();
    ListIterator<BgpValueType> list2 = linkStateAttr.linkStateAttributes().listIterator();
    assertThat(list.next(), is(list2.next()));
    assertThat(((BgpAttrNodeMultiTopologyId) list2.next()).attrMultiTopologyId(), is(((BgpAttrNodeMultiTopologyId) list.next()).attrMultiTopologyId()));
    assertThat(linkStateAttr.getType(), is((short) 29));
}
Also used : Origin(org.onosproject.bgpio.types.Origin) 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) BgpAttrNodeMultiTopologyId(org.onosproject.bgpio.types.attr.BgpAttrNodeMultiTopologyId) 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 62 with BgpHeader

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

the class BgpUpdateLinkStateAttrTest method bgpUpdateMessageTest6.

/**
 * Test for LinkStateattribute BgpAttrNodeRouterId and BgpAttrRouterIdV6.
 *
 * @throws BgpParseException while parsing update message
 */
@Test
public void bgpUpdateMessageTest6() 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) 0xA2, 0x02, 0x00, 0x04, // withdrawn routes
    0x18, // withdrawn routes
    0x0a, // withdrawn routes
    0x01, // withdrawn routes
    0x01, // path attribute len
    0x00, // path attribute len
    (byte) 0x87, // 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
    0x1C, // BgpAttrNodeRouterId
    0x04, // BgpAttrNodeRouterId
    0x04, // BgpAttrNodeRouterId
    0x00, // BgpAttrNodeRouterId
    0x04, // BgpAttrNodeRouterId
    0x15, // BgpAttrNodeRouterId
    0x15, // BgpAttrNodeRouterId
    0x15, // BgpAttrNodeRouterId
    0x15, 0x04, 0x05, 0x00, 0x10, 0x01, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // BgpAttrRouterIdV6
    0x01 };
    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) 162));
    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;
    byte[] linkAttrbs = new byte[] { (byte) 0x80, 0x1d, 0x1C, 0x04, 0x04, 0x00, 0x04, (byte) 0x15, 0x15, 0x15, 0x15, 0x04, 0x05, 0x00, 0x10, 0x01, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
    ChannelBuffer cb = ChannelBuffers.dynamicBuffer();
    cb.writeBytes(linkAttrbs);
    LinkStateAttributes obj = LinkStateAttributes.read(cb);
    assertThat(linkStateAttr.linkStateAttributes(), is(obj.linkStateAttributes()));
    assertThat(linkStateAttr.getType(), is((short) 29));
}
Also used : Origin(org.onosproject.bgpio.types.Origin) 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 63 with BgpHeader

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

the class BgpUpdateMsg2Test method bgpUpdateMessage2Test5.

/**
 * This test case checks the changes made in.
 * MpReachNlri (read method AFI 2/SAFI 1 else if part)
 * as bug fix for bug 8036
 */
@Test
public void bgpUpdateMessage2Test5() 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) 0x57, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40, (byte) 0x90, (byte) 0x0e, (byte) 0x00, (byte) 0x27, // ------------ AFI = 2 --------------------------------------------------------------------------------
    (byte) 0x00, (byte) 0x02, // ------------ SAFI = 1 -------------------------------------------------------------------------------
    (byte) 0x01, // -----------------------------------------------------------------------------------------------------
    (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) 0x40, (byte) 0x20, (byte) 0x01, (byte) 0x05, (byte) 0xb0, (byte) 0x43, (byte) 0x21, (byte) 0x00, (byte) 0x00, (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) 0x02, (byte) 0x40, (byte) 0x02, (byte) 0x00, (byte) 0x80, (byte) 0x04, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x64, (byte) 0x40, (byte) 0x05, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x64 };
    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) {
            assertThat(((MpReachNlri) attr).nexthop().toString(), is("2001:5b0:8:0:5054:ff:feb8:352b"));
            assertThat(((MpReachNlri) attr).getAfi(), is((short) 2));
            assertThat(((MpReachNlri) attr).getSafi(), is((byte) 1));
        }
    }
}
Also used : BgpValueType(org.onosproject.bgpio.types.BgpValueType) BgpHeader(org.onosproject.bgpio.types.BgpHeader) MpReachNlri(org.onosproject.bgpio.types.MpReachNlri) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) Test(org.junit.Test)

Example 64 with BgpHeader

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

the class BgpUpdateMsg2Test method bgpUpdateMessage2Test3.

/**
 * This test case checks the changes made in.
 * LinkStateAttributes (ATTR_NODE_MT_TOPOLOGY_ID check)
 * as bug fix for bug 8036
 */
@Test
public void bgpUpdateMessage2Test3() 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) 0x8e, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x77, (byte) 0x90, (byte) 0x0e, (byte) 0x00, (byte) 0x40, (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) 0x01, (byte) 0x00, (byte) 0x27, (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) 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) 0x22, // ------------ BGP-LS BgpAttrNodeMultiTopologyId Attribute---------------------------------------------
    (byte) 0x01, (byte) 0x07, (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x02, // -----------------------------------------------------------------------------------------------------
    (byte) 0x04, (byte) 0x02, (byte) 0x00, (byte) 0x11, (byte) 0x62, (byte) 0x67, (byte) 0x70, (byte) 0x5f, (byte) 0x6f, (byte) 0x6e, (byte) 0x6f, (byte) 0x73, (byte) 0x5f, (byte) 0x72, (byte) 0x6f, (byte) 0x75, (byte) 0x74, (byte) 0x65, (byte) 0x72, (byte) 0x2d, (byte) 0x32, (byte) 0x04, (byte) 0x03, (byte) 0x00, (byte) 0x03, (byte) 0x49, (byte) 0x00, (byte) 0x01 };
    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) {
            List<BgpValueType> linkStateAttribList = ((LinkStateAttributes) attr).linkStateAttributes();
            ListIterator<BgpValueType> listIterator = linkStateAttribList.listIterator();
            while (listIterator.hasNext()) {
                BgpValueType bgpLSAttrib = listIterator.next();
                if (bgpLSAttrib instanceof BgpAttrNodeMultiTopologyId) {
                    assertThat(((BgpAttrNodeMultiTopologyId) bgpLSAttrib).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) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) LinkStateAttributes(org.onosproject.bgpio.types.LinkStateAttributes) Test(org.junit.Test)

Example 65 with BgpHeader

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

the class BgpUpdateMsgTest method bgpUpdateMessageTest17.

/**
 * In this test case, Invalid res is given as input and expecting
 * an exception.
 */
@Test(expected = BgpParseException.class)
public void bgpUpdateMessageTest17() 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 len
    (byte) 0xff, // withdrawn len
    (byte) 0xff, // withdrawn len
    0x00, // withdrawn len
    0x60, // withdrawn len
    0x02, // withdrawn len
    0x00, // withdrawn len
    0x00, // path attribute len
    0x00, // path attribute len
    0x49, // origin
    (byte) 0xff, // 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 with safi = 71
    (byte) 0x80, // mpreach with safi = 71
    0x0e, // mpreach with safi = 71
    0x34, // mpreach with safi = 71
    0x40, // mpreach with safi = 71
    0x04, // mpreach with safi = 71
    0x47, // nexthop
    0x04, // nexthop
    0x04, // nexthop
    0x00, // nexthop
    0x00, // nexthop
    0x01, // reserved
    0x01, 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));
}
Also used : BgpHeader(org.onosproject.bgpio.types.BgpHeader) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) 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