use of org.onosproject.bgpio.types.BgpHeader in project onos by opennetworkinglab.
the class BgpNotificationMsgTest method bgpNotificationMessageTest1.
/**
* Notification message with error code, error subcode and data.
*
* @throws BgpParseException while decoding and encoding notification message
*/
@Test
public void bgpNotificationMessageTest1() 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, 0x17, 0x03, 0x02, 0x02, (byte) 0xfe, (byte) 0xb0 };
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 BgpNotificationMsgTest method bgpNotificationMessageTest4.
/**
* Notification message without error subcode.
*
* @throws BgpParseException while decoding and encoding notification message
*/
@Test(expected = BgpParseException.class)
public void bgpNotificationMessageTest4() 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, 0x14, 0x03, 0x02 };
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 BgpNotificationMsgTest method bgpNotificationMessageTest5.
/**
* Notification message with wrong message length.
*
* @throws BgpParseException while decoding and encoding notification message
*/
@Test(expected = BgpParseException.class)
public void bgpNotificationMessageTest5() 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, 0x14, 0x03, 0x02, 0x02 };
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 openMessageTest1.
/**
* This test case checks open message without optional parameter.
*/
@Test
public void openMessageTest1() throws BgpParseException {
// Open message without optional parameter
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, 0X04, (byte) 0xfe, 0x09, 0x00, (byte) 0xb4, (byte) 0xc0, (byte) 0xa8, 0x00, 0x0f, 0x00 };
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 openMessageTest3.
/**
* This test case checks open message with Four-octet AS number
* capability.
*/
@Test
public void openMessageTest3() throws BgpParseException {
// OPEN Message (Four-Octet AS number 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, // BGPHeader
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, 0x41, 0x04, 0x00, 0x01, 0x00, // Four Octet AS Number-CAPABILITY-TLV
0x01 };
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));
}
Aggregations