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));
}
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));
}
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));
}
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));
}
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));
}
Aggregations