Search in sources :

Example 26 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 27 with BgpHeader

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

the class BgpOpenMsgTest method openMessageTest5.

/**
 * In this test case, Invalid version is given as input and expecting
 * an exception.
 */
@Test(expected = BgpParseException.class)
public void openMessageTest5() throws BgpParseException {
    // OPEN Message with invalid version number.
    byte[] openMsg = 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, 0x1d, 0x01, 0X05, (byte) 0xfe, 0x09, 0x00, (byte) 0xb4, (byte) 0xc0, (byte) 0xa8, 0x00, 0x0f, 0x00 };
    ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
    buffer.writeBytes(openMsg);
    BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
    BgpMessage message;
    BgpHeader bgpHeader = new BgpHeader();
    message = reader.readFrom(buffer, bgpHeader);
    assertThat(message, instanceOf(BgpOpenMsg.class));
}
Also used : BgpHeader(org.onosproject.bgpio.types.BgpHeader) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) Test(org.junit.Test)

Example 28 with BgpHeader

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

the class BgpOpenMsgTest method openMessageTest10.

/**
 * In this test case, Invalid multiprotocol capability length is given as input and expecting an exception.
 */
@Test(expected = BgpParseException.class)
public void openMessageTest10() throws BgpParseException {
    // OPEN Message with invalid message type.
    byte[] openMsg = 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, 0x3d, 0x01, 0x04, 0x00, (byte) 0xc8, 0x00, (byte) 0xb4, (byte) 0xc0, (byte) 0xa8, 0x07, 0x35, 0x20, 0x02, 0x1e, 0x01, 0x04, 00, 0x01, 0x00, 0x01, 0x41, 0x04, 0x00, 0x00, 0x00, (byte) 0xc8, 0x01, 0x04, 0x40, 0x04, 0x00, 0x47, 0x01, 0x04, 0x00, 0x01, 0x00, (byte) 0x85, (byte) 0x81, 0x05, 0x00, 0x01, (byte) 0x85, // RPD capability
    0x01 };
    ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
    buffer.writeBytes(openMsg);
    BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
    BgpMessage message;
    BgpHeader bgpHeader = new BgpHeader();
    message = reader.readFrom(buffer, bgpHeader);
    assertThat(message, instanceOf(BgpOpenMsg.class));
}
Also used : BgpHeader(org.onosproject.bgpio.types.BgpHeader) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) Test(org.junit.Test)

Example 29 with BgpHeader

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

the class BgpOpenMsgTest method openMessageTest2.

/**
 * This test case checks open message with Multiprotocol extension
 * capability.
 */
@Test
public void openMessageTest2() throws BgpParseException {
    // OPEN Message (MultiProtocolExtension-CAPABILITY).
    byte[] openMsg = 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, 0x25, // BGP Header
    0x01, // Version
    0X04, // AS Number
    (byte) 0x00, // AS Number
    (byte) 0xc8, // Hold time
    0x00, // Hold time
    (byte) 0xb4, (byte) 0xb6, (byte) 0x02, 0x5d, // BGP Identifier
    (byte) 0xc8, // Opt Parameter length
    0x08, // Opt Parameter length
    0x02, // Opt Parameter length
    0x06, 0x01, 0x04, 0x00, 0x00, 0x00, // Multiprotocol CAPABILITY
    (byte) 0xc8 };
    byte[] testOpenMsg;
    ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
    buffer.writeBytes(openMsg);
    BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
    BgpMessage message;
    BgpHeader bgpHeader = new BgpHeader();
    message = reader.readFrom(buffer, bgpHeader);
    assertThat(message, instanceOf(BgpOpenMsg.class));
    ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
    message.writeTo(buf);
    int readLen = buf.writerIndex();
    testOpenMsg = new byte[readLen];
    buf.readBytes(testOpenMsg, 0, readLen);
    assertThat(testOpenMsg, is(openMsg));
}
Also used : BgpHeader(org.onosproject.bgpio.types.BgpHeader) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) Test(org.junit.Test)

Example 30 with BgpHeader

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

the class BgpOpenMsgTest method openMessageTest11.

/**
 * This test case checks the changes made in.
 * BgpOpenMsg
 * BgpOpenMsgVer4
 * BgpChannelHandler
 * as bug fix for bug 8036
 */
@Test
public void openMessageTest11() throws BgpParseException {
    /*
            Open message received after implementing the changes for the fix. Here we are considering connection type
            as IPV4_IPV6.
        */
    byte[] openMsg = 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) 0x3d, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x64, (byte) 0x00, (byte) 0xb4, (byte) 0xc0, (byte) 0xa8, (byte) 0x07, (byte) 0x93, (byte) 0x20, (byte) 0x02, (byte) 0x1e, // ------------ IPV4 Multiprotocol Extensions Capability -----------------------------------------------
    (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x01, // ------------ IPV6 Multiprotocol Extensions Capability -----------------------------------------------
    (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x01, // -----------------------------------------------------------------------------------------------------
    (byte) 0x41, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x64, (byte) 0x01, (byte) 0x04, (byte) 0x40, (byte) 0x04, (byte) 0x00, (byte) 0x47, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x85 };
    ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
    buffer.writeBytes(openMsg);
    BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
    BgpMessage message;
    BgpHeader bgpHeader = new BgpHeader();
    message = reader.readFrom(buffer, bgpHeader);
    assertThat(message, instanceOf(BgpOpenMsg.class));
    BgpOpenMsg receivedMsg = (BgpOpenMsg) message;
    List<BgpValueType> capabilityTlvList = receivedMsg.getCapabilityTlv();
    ListIterator<BgpValueType> capabilityTlvListIterator = capabilityTlvList.listIterator();
    boolean isIPv4UnicastCapabilityPresent = false;
    boolean isIPv6UnicastCapabilityPresent = false;
    while (capabilityTlvListIterator.hasNext()) {
        BgpValueType bgpLSAttrib = capabilityTlvListIterator.next();
        if (bgpLSAttrib instanceof MultiProtocolExtnCapabilityTlv) {
            MultiProtocolExtnCapabilityTlv mltiPrtclExtnCapabilityTlv = ((MultiProtocolExtnCapabilityTlv) bgpLSAttrib);
            if (mltiPrtclExtnCapabilityTlv.getAfi() == 1 && mltiPrtclExtnCapabilityTlv.getSafi() == 1) {
                isIPv4UnicastCapabilityPresent = true;
            } else if (((MultiProtocolExtnCapabilityTlv) bgpLSAttrib).getAfi() == 2 && mltiPrtclExtnCapabilityTlv.getSafi() == 1) {
                isIPv6UnicastCapabilityPresent = true;
            }
        }
    }
    assertThat(isIPv4UnicastCapabilityPresent, is(true));
    assertThat(isIPv6UnicastCapabilityPresent, is(true));
}
Also used : BgpValueType(org.onosproject.bgpio.types.BgpValueType) MultiProtocolExtnCapabilityTlv(org.onosproject.bgpio.types.MultiProtocolExtnCapabilityTlv) 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