Search in sources :

Example 71 with BgpHeader

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

the class BgpUpdateMsgTest method bgpUpdateMessageTest18.

/**
 * This test case checks update message with node NLRI.
 */
@Test
public void bgpUpdateMessageTest18() 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
    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 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
    0x00, 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) 96));
    BgpValueType testPathAttribute;
    Origin origin;
    AsPath asPath;
    Med med;
    MpReachNlri mpReach;
    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();
    mpReach = (MpReachNlri) testPathAttribute;
    assertThat(mpReach.mpReachNlriLen(), is((int) 52));
    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.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) 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) 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) MpReachNlri(org.onosproject.bgpio.types.MpReachNlri) Test(org.junit.Test)

Example 72 with BgpHeader

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

the class BgpUpdateMsgTest method bgpUpdateMessageTest33.

/**
 * This test case checks update message with invalid prefix nlri length in input.
 */
@Test(expected = BgpParseException.class)
public void bgpUpdateMessageTest33() 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) 0xd6, 0x02, 0x00, 0x04, // withdrawn routes
    0x18, // withdrawn routes
    0x0a, // withdrawn routes
    0x01, // withdrawn routes
    0x01, // path attribute len
    0x00, // path attribute len
    (byte) 0xbb, // 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) 0x90, // mpreach
    0x0e, // mpreach
    0x00, // mpreach
    (byte) 0xa5, // mpreach
    0x40, // mpreach
    0x04, // mpreach
    0x47, // nexthop
    0x04, // nexthop
    0x04, // nexthop
    0x00, // nexthop
    0x00, // nexthop
    0x01, // reserved
    0x00, 0x00, 0x03, 0x00, 0x35, 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, 0x21, 0x68, 0x07, 0x70, 0x01, 0x01, 0x09, 0x00, 0x05, 0x20, (byte) 0xc0, (byte) 0xa8, 0x4d, 0x01, 0x00, 0x03, 0x00, 0x30, 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, 0x02, 0x50, 0x21, 0x01, 0x09, 0x00, 0x05, 0x20, 0x15, 0x15, 0x15, 0x15, 0x00, 0x03, 0x00, 0x30, 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, 0x02, 0x20, 0x22, 0x02, 0x20, 0x22, 0x01, 0x09, 0x00, 0x05, 0x20, 0x16, 0x16, 0x16, // prefix nlri
    0x16 };
    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)

Example 73 with BgpHeader

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

the class BgpUpdateMsgTest method bgpUpdateMessageTest36.

/**
 * Wrong length BgpLinkAttrIGPMetric.
 */
@Test(expected = BgpParseException.class)
public void bgpUpdateMessageTest36() 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) 0x95, 0x02, 0x00, 0x04, // withdrawn routes
    0x18, // withdrawn routes
    0x0a, // withdrawn routes
    0x01, // withdrawn routes
    0x01, // path attribute len
    0x00, // path attribute len
    0x7A, // 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
    0x0f, // BgpAttrRouterIdV4
    0x04, // BgpAttrRouterIdV4
    0x04, // BgpAttrRouterIdV4
    0x00, // BgpAttrRouterIdV4
    0x04, // BgpAttrRouterIdV4
    (byte) 0xbd, // BgpAttrRouterIdV4
    0x59, // BgpAttrRouterIdV4
    0x4c, // BgpAttrRouterIdV4
    0x62, 0x04, 0x47, 0x00, 0x02, 0x00, 0x00, // BgpLinkAttrIGPMetric
    0x0a };
    ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
    buffer.writeBytes(updateMsg);
    BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
    BgpHeader bgpHeader = new BgpHeader();
    reader.readFrom(buffer, bgpHeader);
}
Also used : BgpHeader(org.onosproject.bgpio.types.BgpHeader) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) Test(org.junit.Test)

Example 74 with BgpHeader

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

the class BgpUpdateMsgTest method bgpUpdateMessageTest15.

/**
 * In this test case, Invalid SAFI is given as input and expecting
 * an exception.
 */
@Test(expected = BgpParseException.class)
public void bgpUpdateMessageTest15() 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
    0x49, // nexthop
    0x04, // nexthop
    0x04, // nexthop
    0x00, // nexthop
    0x00, // nexthop
    0x01, // reserved
    0x00, 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)

Example 75 with BgpHeader

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

the class BgpUpdateMsgTest method bgpUpdateMessageTest28.

/**
 * In this test case, withdrawn routes with prefix length 0 is given as input and expecting
 * an exception.
 */
@Test
public void bgpUpdateMessageTest28() 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, // marker
    (byte) 0xff, // marker
    (byte) 0xff, 0x00, 0x18, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00 };
    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