Mahesh Poojary S
Committed by Gerrit Code Review

[ONOS-2623] UT test cases for Open and Error messages.

Change-Id: I13736e921b0678573095c8a600b12af70dc524d1
......@@ -22,6 +22,10 @@ import org.onosproject.pcepio.protocol.PcepBandwidthObject;
import org.onosproject.pcepio.protocol.PcepCloseMsg;
import org.onosproject.pcepio.protocol.PcepEndPointsObject;
import org.onosproject.pcepio.protocol.PcepEroObject;
import org.onosproject.pcepio.protocol.PcepErrorInfo;
import org.onosproject.pcepio.protocol.PcepError;
import org.onosproject.pcepio.protocol.PcepErrorMsg;
import org.onosproject.pcepio.protocol.PcepErrorObject;
import org.onosproject.pcepio.protocol.PcepFactory;
import org.onosproject.pcepio.protocol.PcepInitiateMsg;
import org.onosproject.pcepio.protocol.PcepKeepaliveMsg;
......@@ -31,6 +35,8 @@ import org.onosproject.pcepio.protocol.PcepMessage;
import org.onosproject.pcepio.protocol.PcepMessageReader;
import org.onosproject.pcepio.protocol.PcepMetricObject;
import org.onosproject.pcepio.protocol.PcepMsgPath;
import org.onosproject.pcepio.protocol.PcepOpenMsg;
import org.onosproject.pcepio.protocol.PcepOpenObject;
import org.onosproject.pcepio.protocol.PcepSrpObject;
import org.onosproject.pcepio.protocol.PcepUpdateMsg;
import org.onosproject.pcepio.protocol.PcepUpdateRequest;
......@@ -41,15 +47,13 @@ public class PcepFactoryVer1 implements PcepFactory {
public static final PcepFactoryVer1 INSTANCE = new PcepFactoryVer1();
@Override
public org.onosproject.pcepio.protocol.PcepOpenMsg.Builder buildOpenMsg() {
// TODO Auto-generated method stub
return null;
public PcepOpenMsg.Builder buildOpenMsg() {
return new PcepOpenMsgVer1.Builder();
}
@Override
public org.onosproject.pcepio.protocol.PcepOpenObject.Builder buildOpenObject() {
// TODO Auto-generated method stub
return null;
public PcepOpenObject.Builder buildOpenObject() {
return new PcepOpenObjectVer1.Builder();
}
@Override
......@@ -180,15 +184,13 @@ public class PcepFactoryVer1 implements PcepFactory {
}
@Override
public org.onosproject.pcepio.protocol.PcepErrorMsg.Builder buildPcepErrorMsg() {
// TODO Auto-generated method stub
return null;
public PcepErrorMsg.Builder buildPcepErrorMsg() {
return new PcepErrorMsgVer1.Builder();
}
@Override
public org.onosproject.pcepio.protocol.PcepErrorObject.Builder buildPcepErrorObject() {
// TODO Auto-generated method stub
return null;
public PcepErrorObject.Builder buildPcepErrorObject() {
return new PcepErrorObjectVer1.Builder();
}
@Override
......@@ -198,15 +200,13 @@ public class PcepFactoryVer1 implements PcepFactory {
}
@Override
public org.onosproject.pcepio.protocol.PcepErrorInfo.Builder buildPcepErrorInfo() {
// TODO Auto-generated method stub
return null;
public PcepErrorInfo.Builder buildPcepErrorInfo() {
return new PcepErrorInfoVer1.Builder();
}
@Override
public org.onosproject.pcepio.protocol.PcepError.Builder buildPcepError() {
// TODO Auto-generated method stub
return null;
public PcepError.Builder buildPcepError() {
return new PcepErrorVer1.Builder();
}
@Override
......
......@@ -73,8 +73,7 @@ public abstract class PcepMessageVer1 {
case OPEN_MSG_TYPE:
log.debug("OPEN MESSAGE is received");
// message type value 1 means it is open message
// return
// TODO: Read open message from channel buffer.
return PcepOpenMsgVer1.READER.readFrom(cb.readBytes(length));
case KEEPALIVE_MSG_TYPE:
log.debug("KEEPALIVE MESSAGE is received");
// message type value 2 means it is Keepalive message
......@@ -82,8 +81,7 @@ public abstract class PcepMessageVer1 {
case ERROR_MSG_TYPE:
log.debug("ERROR MESSAGE is received");
// message type value 6 means it is error message
// return
// TODO: Read Error message from channel buffer.
return PcepErrorMsgVer1.READER.readFrom(cb.readBytes(length));
case REPORT_MSG_TYPE:
log.debug("REPORT MESSAGE is received");
// message type value 10 means it is Report message
......
/*
* Copyright 2014-2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.pcepio;
import java.util.Arrays;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.onosproject.pcepio.exceptions.PcepParseException;
import org.onosproject.pcepio.protocol.PcepErrorMsg;
import org.onosproject.pcepio.protocol.PcepFactories;
import org.onosproject.pcepio.protocol.PcepMessage;
import org.onosproject.pcepio.protocol.PcepMessageReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Test cases for PCEP ERROR Message.
*/
public class PcepErrorMsgTest {
protected static final Logger log = LoggerFactory.getLogger(PcepErrorMsgTest.class);
@Before
public void startUp() {
}
@After
public void tearDown() {
}
@Test
public void errorMessageTest1() throws PcepParseException {
/* PCEP-ERROR Object, OPEN Object (STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV,
* PCECC-CAPABILITY-TLV, TED Capability TLV)
*/
byte[] errorMsg = new byte[] {0x20, 0x06, 0x00, 0x34, // common header
0x0D, 0x10, 0x00, 0x08, // PCERR Object Header
0x00, 0x00, 0x01, 0x01, 0x01, 0x10, 0x00, 0x28, // OPEN object header
0x20, 0x05, 0x1E, 0x01, // OPEN object
0x00, 0x10, 0x00, 0x04, // STATEFUL-PCE-CAPABILITY
0x00, 0x00, 0x00, 0x05, 0x00, 0x0E, 0x00, 0x04, // GMPLS-CAPABILITY-TLV
0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, // PCECC-CAPABILITY-TLV
0x00, 0x00, 0x00, 0x03, 0x00, (byte) 0x84, 0x00, 0x04, // TED Capability TLV
0x00, 0x00, 0x00, 0x00 };
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(errorMsg);
PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
PcepMessage message = null;
try {
message = reader.readFrom(buffer);
} catch (PcepParseException e) {
e.printStackTrace();
}
byte[] testErrorMsg = {0};
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
if (message instanceof PcepErrorMsg) {
message.writeTo(buf);
int iReadLen = buf.writerIndex() - 0;
testErrorMsg = new byte[iReadLen];
buf.readBytes(testErrorMsg, 0, iReadLen);
if (Arrays.equals(errorMsg, testErrorMsg)) {
Assert.assertArrayEquals(errorMsg, testErrorMsg);
log.debug("Pcep Error Msg are Equal ");
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
}
@Test
public void errorMessageTest2() throws PcepParseException {
/* PCEP-ERROR Object, PCEP-ERROR Object, OPEN Object (STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV,
* PCECC-CAPABILITY-TLV, TED Capability TLV)
*/
byte[] errorMsg = new byte[] {0x20, 0x06, 0x00, 0x3C, // common header
0x0D, 0x10, 0x00, 0x08, // PCERR Object Header
0x00, 0x00, 0x01, 0x01, 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header
0x00, 0x00, 0x01, 0x03, 0x01, 0x10, 0x00, 0x28, // OPEN object header
0x20, 0x05, 0x1E, 0x01, // OPEN object
0x00, 0x10, 0x00, 0x04, // STATEFUL-PCE-CAPABILITY
0x00, 0x00, 0x00, 0x05, 0x00, 0x0E, 0x00, 0x04, // GMPLS-CAPABILITY-TLV
0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, // PCECC-CAPABILITY-TLV
0x00, 0x00, 0x00, 0x03, 0x00, (byte) 0x84, 0x00, 0x04, // TED Capability TLV
0x00, 0x00, 0x00, 0x00 };
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(errorMsg);
PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
PcepMessage message = null;
try {
message = reader.readFrom(buffer);
} catch (PcepParseException e) {
e.printStackTrace();
}
byte[] testErrorMsg = {0};
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
if (message instanceof PcepErrorMsg) {
message.writeTo(buf);
int iReadLen = buf.writerIndex() - 0;
testErrorMsg = new byte[iReadLen];
buf.readBytes(testErrorMsg, 0, iReadLen);
if (Arrays.equals(errorMsg, testErrorMsg)) {
Assert.assertArrayEquals(errorMsg, testErrorMsg);
log.debug("Pcep Error Msg are Equal ");
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
}
@Test
public void errorMessageTest3() throws PcepParseException {
/* PCEP-ERROR Object, PCEP-ERROR Object, OPEN Object (STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV,
* PCECC-CAPABILITY-TLV)
*/
byte[] errorMsg = new byte[] {0x20, 0x06, 0x00, 0x34, // common header
0x0D, 0x10, 0x00, 0x08, // PCERR Object Header
0x00, 0x00, 0x01, 0x01, 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header
0x00, 0x00, 0x01, 0x03, 0x01, 0x10, 0x00, 0x20, // OPEN object header
0x20, 0x05, 0x1E, 0x01, // OPEN object
0x00, 0x10, 0x00, 0x04, // STATEFUL-PCE-CAPABILITY
0x00, 0x00, 0x00, 0x05, 0x00, 0x0E, 0x00, 0x04, // GMPLS-CAPABILITY-TLV
0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, // PCECC-CAPABILITY-TLV
0x00, 0x00, 0x00, 0x03 };
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(errorMsg);
PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
PcepMessage message = null;
try {
message = reader.readFrom(buffer);
} catch (PcepParseException e) {
e.printStackTrace();
}
byte[] testErrorMsg = {0};
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
if (message instanceof PcepErrorMsg) {
message.writeTo(buf);
int iReadLen = buf.writerIndex() - 0;
testErrorMsg = new byte[iReadLen];
buf.readBytes(testErrorMsg, 0, iReadLen);
if (Arrays.equals(errorMsg, testErrorMsg)) {
Assert.assertArrayEquals(errorMsg, testErrorMsg);
log.debug("Pcep Error Msg are Equal ");
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
}
@Test
public void errorMessageTest4() throws PcepParseException {
//PCEP-ERROR Object, PCEP-ERROR Object, OPEN Object (STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV)
byte[] errorMsg = new byte[] {0x20, 0x06, 0x00, 0x2c, // common header
0x0D, 0x10, 0x00, 0x08, // PCERR Object Header
0x00, 0x00, 0x01, 0x01, 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header
0x00, 0x00, 0x01, 0x03, 0x01, 0x10, 0x00, 0x18, // OPEN object header
0x20, 0x05, 0x1E, 0x01, // OPEN object
0x00, 0x10, 0x00, 0x04, // STATEFUL-PCE-CAPABILITY
0x00, 0x00, 0x00, 0x05, 0x00, 0x0E, 0x00, 0x04, // GMPLS-CAPABILITY-TLV
0x00, 0x00, 0x00, 0x00 };
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(errorMsg);
PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
PcepMessage message = null;
try {
message = reader.readFrom(buffer);
} catch (PcepParseException e) {
e.printStackTrace();
}
byte[] testErrorMsg = {0};
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
if (message instanceof PcepErrorMsg) {
message.writeTo(buf);
int iReadLen = buf.writerIndex() - 0;
testErrorMsg = new byte[iReadLen];
buf.readBytes(testErrorMsg, 0, iReadLen);
if (Arrays.equals(errorMsg, testErrorMsg)) {
Assert.assertArrayEquals(errorMsg, testErrorMsg);
log.debug("Pcep Error Msg are Equal ");
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
}
@Test
public void errorMessageTest5() throws PcepParseException {
//PCEP-ERROR Object, PCEP-ERROR Object, OPEN Object (STATEFUL-PCE-CAPABILITY)
byte[] errorMsg = new byte[] {0x20, 0x06, 0x00, 0x24, // common header
0x0D, 0x10, 0x00, 0x08, // PCERR Object Header
0x00, 0x00, 0x01, 0x01, 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header
0x00, 0x00, 0x01, 0x03, 0x01, 0x10, 0x00, 0x10, // OPEN object header
0x20, 0x05, 0x1E, 0x01, // OPEN object
0x00, 0x10, 0x00, 0x04, // STATEFUL-PCE-CAPABILITY
0x00, 0x00, 0x00, 0x05 };
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(errorMsg);
PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
PcepMessage message = null;
try {
message = reader.readFrom(buffer);
} catch (PcepParseException e) {
e.printStackTrace();
}
byte[] testErrorMsg = {0};
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
if (message instanceof PcepErrorMsg) {
message.writeTo(buf);
int iReadLen = buf.writerIndex() - 0;
testErrorMsg = new byte[iReadLen];
buf.readBytes(testErrorMsg, 0, iReadLen);
if (Arrays.equals(errorMsg, testErrorMsg)) {
Assert.assertArrayEquals(errorMsg, testErrorMsg);
log.debug("Pcep Error Msg are Equal ");
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
}
@Test
public void errorMessageTest6() throws PcepParseException {
//PCEP-ERROR Object, PCEP-ERROR Object, OPEN Object
byte[] errorMsg = new byte[] {0x20, 0x06, 0x00, 0x1C, // common header
0x0D, 0x10, 0x00, 0x08, // PCERR Object Header
0x00, 0x00, 0x01, 0x01, 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header
0x00, 0x00, 0x01, 0x03, 0x01, 0x10, 0x00, 0x08, // OPEN object header
0x20, 0x05, 0x1E, 0x01 // OPEN object
};
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(errorMsg);
PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
PcepMessage message = null;
try {
message = reader.readFrom(buffer);
} catch (PcepParseException e) {
e.printStackTrace();
}
byte[] testErrorMsg = {0};
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
if (message instanceof PcepErrorMsg) {
message.writeTo(buf);
int iReadLen = buf.writerIndex() - 0;
testErrorMsg = new byte[iReadLen];
buf.readBytes(testErrorMsg, 0, iReadLen);
if (Arrays.equals(errorMsg, testErrorMsg)) {
Assert.assertArrayEquals(errorMsg, testErrorMsg);
log.debug("Pcep Error Msg are Equal ");
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
}
@Test
public void errorMessageTest7() throws PcepParseException {
//PCEP-ERROR Object, OPEN Object
byte[] errorMsg = new byte[] {0x20, 0x06, 0x00, 0x14, // common header
0x0D, 0x10, 0x00, 0x08, // PCERR Object Header
0x00, 0x00, 0x01, 0x01, 0x01, 0x10, 0x00, 0x08, // OPEN object header
0x20, 0x05, 0x1E, 0x01 // OPEN object
};
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(errorMsg);
PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
PcepMessage message = null;
try {
message = reader.readFrom(buffer);
} catch (PcepParseException e) {
e.printStackTrace();
}
byte[] testErrorMsg = {0};
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
if (message instanceof PcepErrorMsg) {
message.writeTo(buf);
int iReadLen = buf.writerIndex() - 0;
testErrorMsg = new byte[iReadLen];
buf.readBytes(testErrorMsg, 0, iReadLen);
if (Arrays.equals(errorMsg, testErrorMsg)) {
Assert.assertArrayEquals(errorMsg, testErrorMsg);
log.debug("Pcep Error Msg are Equal ");
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
}
@Test
public void errorMessageTest8() throws PcepParseException {
//PCEP-ERROR Object, RP Object, PCEP-ERROR Object
byte[] errorMsg = new byte[] {0x20, 0x06, 0x00, 0x20, // common header
0x0D, 0x10, 0x00, 0x08, // PCERR Object Header
0x00, 0x00, 0x01, 0x01,
0x02, 0x10, 0x00, 0x0C, // RP Object Header
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x03,
0x0D, 0x10, 0x00, 0x08, // PCERR Object Header
0x00, 0x00, 0x01, 0x03};
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(errorMsg);
PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
PcepMessage message = null;
try {
message = reader.readFrom(buffer);
} catch (PcepParseException e) {
e.printStackTrace();
}
byte[] testErrorMsg = {0};
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
if (message instanceof PcepErrorMsg) {
message.writeTo(buf);
int iReadLen = buf.writerIndex() - 0;
testErrorMsg = new byte[iReadLen];
buf.readBytes(testErrorMsg, 0, iReadLen);
if (Arrays.equals(errorMsg, testErrorMsg)) {
Assert.assertArrayEquals(errorMsg, testErrorMsg);
log.debug("Pcep Error Msg are Equal ");
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
}
@Test
public void errorMessageTest9() throws PcepParseException {
//PCEP-ERROR Object, PCEP-ERROR Object
byte[] errorMsg = new byte[] {0x20, 0x06, 0x00, 0x14, // common header
0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header
0x00, 0x00, 0x01, 0x01, 0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header
0x00, 0x00, 0x01, 0x01 };
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(errorMsg);
PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
PcepMessage message = null;
try {
message = reader.readFrom(buffer);
} catch (PcepParseException e) {
e.printStackTrace();
}
byte[] testErrorMsg = {0};
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
if (message instanceof PcepErrorMsg) {
message.writeTo(buf);
int iReadLen = buf.writerIndex() - 0;
testErrorMsg = new byte[iReadLen];
buf.readBytes(testErrorMsg, 0, iReadLen);
if (Arrays.equals(errorMsg, testErrorMsg)) {
Assert.assertArrayEquals(errorMsg, testErrorMsg);
log.debug("Pcep Error Msg are Equal ");
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
}
@Test
public void errorMessageTest10() throws PcepParseException {
//PCEP-ERROR Object, PCEP-ERROR Object
byte[] errorMsg = new byte[] {0x20, 0x06, 0x00, 0x14, // common header
0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header
0x00, 0x00, 0x01, 0x01, 0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header
0x00, 0x00, 0x01, 0x01 };
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(errorMsg);
PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
PcepMessage message = null;
try {
message = reader.readFrom(buffer);
} catch (PcepParseException e) {
e.printStackTrace();
}
byte[] testErrorMsg = {0};
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
if (message instanceof PcepErrorMsg) {
message.writeTo(buf);
int iReadLen = buf.writerIndex() - 0;
testErrorMsg = new byte[iReadLen];
buf.readBytes(testErrorMsg, 0, iReadLen);
if (Arrays.equals(errorMsg, testErrorMsg)) {
Assert.assertArrayEquals(errorMsg, testErrorMsg);
log.debug("Pcep Error Msg are Equal ");
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
}
@Test
public void errorMessageTest11() throws PcepParseException {
//TE Object, PCEP-ERROR Object
byte[] errorMsg = new byte[] {0x20, 0x06, 0x00, 0x18, // common header
0x65, 0x13, 0x00, 0x0C, // TE Object Header
0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, // TE-ID
0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header
0x00, 0x00, 0x01, 0x01 };
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(errorMsg);
PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
PcepMessage message = null;
try {
message = reader.readFrom(buffer);
} catch (PcepParseException e) {
e.printStackTrace();
}
byte[] testErrorMsg = {0};
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
if (message instanceof PcepErrorMsg) {
message.writeTo(buf);
int iReadLen = buf.writerIndex() - 0;
testErrorMsg = new byte[iReadLen];
buf.readBytes(testErrorMsg, 0, iReadLen);
if (Arrays.equals(errorMsg, testErrorMsg)) {
Assert.assertArrayEquals(errorMsg, testErrorMsg);
log.debug("Pcep Error Msg are Equal ");
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
}
@Test
public void errorMessageTest12() throws PcepParseException {
//RP Object, PCEP-ERROR Object
byte[] errorMsg = new byte[] {0x20, 0x06, 0x00, 0x18, // common header
0x02, 0x10, 0x00, 0x0C, // RP Object Header
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x03,
0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header
0x00, 0x00, 0x01, 0x01};
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(errorMsg);
PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
PcepMessage message = null;
try {
message = reader.readFrom(buffer);
} catch (PcepParseException e) {
e.printStackTrace();
}
byte[] testErrorMsg = {0};
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
if (message instanceof PcepErrorMsg) {
message.writeTo(buf);
int iReadLen = buf.writerIndex() - 0;
testErrorMsg = new byte[iReadLen];
buf.readBytes(testErrorMsg, 0, iReadLen);
if (Arrays.equals(errorMsg, testErrorMsg)) {
Assert.assertArrayEquals(errorMsg, testErrorMsg);
log.debug("Pcep Error Msg are Equal ");
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
}
@Test
public void errorMessageTest13() throws PcepParseException {
//RP Object, RP Object, PCEP-ERROR Object
byte[] errorMsg = new byte[] {0x20, 0x06, 0x00, 0x24, // common header
0x02, 0x10, 0x00, 0x0C, // RP Object Header
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x03,
0x02, 0x10, 0x00, 0x0C, // RP Object Header
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x04,
0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header
0x00, 0x00, 0x01, 0x01};
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(errorMsg);
PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
PcepMessage message = null;
try {
message = reader.readFrom(buffer);
} catch (PcepParseException e) {
e.printStackTrace();
}
byte[] testErrorMsg = {0};
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
if (message instanceof PcepErrorMsg) {
message.writeTo(buf);
int iReadLen = buf.writerIndex() - 0;
testErrorMsg = new byte[iReadLen];
buf.readBytes(testErrorMsg, 0, iReadLen);
if (Arrays.equals(errorMsg, testErrorMsg)) {
Assert.assertArrayEquals(errorMsg, testErrorMsg);
log.debug("Pcep Error Msg are Equal ");
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
}
@Test
public void errorMessageTest14() throws PcepParseException {
//TE Object, TE Object, PCEP-ERROR Object
byte[] errorMsg = new byte[] {0x20, 0x06, 0x00, 0x24, // common header
0x65, 0x10, 0x00, 0x0C, // TE Object Header
0x01, 0x00, 0x00, 0x03,
0x00, 0x00, 0x00, 0x10, // TE-ID
0x65, 0x10, 0x00, 0x0C, // TE Object Header
0x01, 0x00, 0x00, 0x03,
0x00, 0x00, 0x00, 0x11, // TE-ID
0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header
0x00, 0x00, 0x01, 0x01};
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(errorMsg);
PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
PcepMessage message = null;
try {
message = reader.readFrom(buffer);
} catch (PcepParseException e) {
e.printStackTrace();
}
byte[] testErrorMsg = {0};
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
if (message instanceof PcepErrorMsg) {
message.writeTo(buf);
int iReadLen = buf.writerIndex() - 0;
testErrorMsg = new byte[iReadLen];
buf.readBytes(testErrorMsg, 0, iReadLen);
if (Arrays.equals(errorMsg, testErrorMsg)) {
Assert.assertArrayEquals(errorMsg, testErrorMsg);
log.debug("Pcep Error Msg are Equal ");
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
}
@Test
public void errorMessageTest15() throws PcepParseException {
//PCEP-ERROR Object, TE Object, PCEP-ERROR Object
byte[] errorMsg = new byte[] {0x20, 0x06, 0x00, 0x20, // common header
0x0D, 0x10, 0x00, 0x08, // PCERR Object Header
0x00, 0x00, 0x01, 0x01,
0x65, 0x10, 0x00, 0x0C, // TE Object Header
0x01, 0x00, 0x00, 0x03,
0x00, 0x00, 0x00, 0x10, // TE-ID
0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header
0x00, 0x00, 0x01, 0x03};
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(errorMsg);
PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
PcepMessage message = null;
try {
message = reader.readFrom(buffer);
} catch (PcepParseException e) {
e.printStackTrace();
}
byte[] testErrorMsg = {0};
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
if (message instanceof PcepErrorMsg) {
message.writeTo(buf);
int iReadLen = buf.writerIndex() - 0;
testErrorMsg = new byte[iReadLen];
buf.readBytes(testErrorMsg, 0, iReadLen);
if (Arrays.equals(errorMsg, testErrorMsg)) {
Assert.assertArrayEquals(errorMsg, testErrorMsg);
log.debug("Pcep Error Msg are Equal ");
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
}
@Test
public void errorMessageTest16() throws PcepParseException {
//PCEP-ERROR Object, RP Object, RP Object, PCEP-ERROR Object
byte[] errorMsg = new byte[] {0x20, 0x06, 0x00, 0x2C, // common header
0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header
0x00, 0x00, 0x01, 0x01,
0x02, 0x10, 0x00, 0x0C, // RP Object Header
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x03,
0x02, 0x10, 0x00, 0x0C, // RP Object Header
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x04,
0x0D, 0x10, 0x00, 0x08, // PCERR Object Header
0x00, 0x00, 0x01, 0x03};
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(errorMsg);
PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
PcepMessage message = null;
try {
message = reader.readFrom(buffer);
} catch (PcepParseException e) {
e.printStackTrace();
}
byte[] testErrorMsg = {0};
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
if (message instanceof PcepErrorMsg) {
message.writeTo(buf);
int iReadLen = buf.writerIndex() - 0;
testErrorMsg = new byte[iReadLen];
buf.readBytes(testErrorMsg, 0, iReadLen);
if (Arrays.equals(errorMsg, testErrorMsg)) {
Assert.assertArrayEquals(errorMsg, testErrorMsg);
log.debug("Pcep Error Msg are Equal ");
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
}
@Test
public void errorMessageTest17() throws PcepParseException {
//PCEP-ERROR Object, TE Object, TE Object, PCEP-ERROR Object
byte[] errorMsg = new byte[] {0x20, 0x06, 0x00, 0x2C, // common header
0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header
0x00, 0x00, 0x01, 0x01,
0x65, 0x10, 0x00, 0x0C, // TE Object Header
0x01, 0x00, 0x00, 0x03,
0x00, 0x00, 0x00, 0x10, // TE-ID
0x65, 0x10, 0x00, 0x0C, // TE Object Header
0x01, 0x00, 0x00, 0x03,
0x00, 0x00, 0x00, 0x11, // TE-ID
0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header
0x00, 0x00, 0x01, 0x03};
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(errorMsg);
PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
PcepMessage message = null;
try {
message = reader.readFrom(buffer);
} catch (PcepParseException e) {
e.printStackTrace();
}
byte[] testErrorMsg = {0};
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
if (message instanceof PcepErrorMsg) {
message.writeTo(buf);
int iReadLen = buf.writerIndex() - 0;
testErrorMsg = new byte[iReadLen];
buf.readBytes(testErrorMsg, 0, iReadLen);
if (Arrays.equals(errorMsg, testErrorMsg)) {
Assert.assertArrayEquals(errorMsg, testErrorMsg);
log.debug("Pcep Error Msg are Equal ");
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
}
@Test
public void errorMessageTest18() throws PcepParseException {
//PCEP-ERROR Object, PCEP-ERROR Object, RP Object, RP Object, PCEP-ERROR Object, PCEP-ERROR Object
byte[] errorMsg = new byte[] {0x20, 0x06, 0x00, 0x3C, // common header
0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header
0x00, 0x00, 0x01, 0x01,
0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header
0x00, 0x00, 0x01, 0x03,
0x02, 0x10, 0x00, 0x0C, // RP Object Header
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x03,
0x02, 0x10, 0x00, 0x0C, // RP Object Header
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x04,
0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header
0x00, 0x00, 0x01, 0x04,
0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header
0x00, 0x00, 0x01, 0x06};
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(errorMsg);
PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
PcepMessage message = null;
try {
message = reader.readFrom(buffer);
} catch (PcepParseException e) {
e.printStackTrace();
}
byte[] testErrorMsg = {0};
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
if (message instanceof PcepErrorMsg) {
message.writeTo(buf);
int iReadLen = buf.writerIndex() - 0;
testErrorMsg = new byte[iReadLen];
buf.readBytes(testErrorMsg, 0, iReadLen);
if (Arrays.equals(errorMsg, testErrorMsg)) {
Assert.assertArrayEquals(errorMsg, testErrorMsg);
log.debug("Pcep Error Msg are Equal ");
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
}
@Test
public void errorMessageTest19() throws PcepParseException {
//PCEP-ERROR Object, PCEP-ERROR Object, TE Object, TE Object, PCEP-ERROR Object, PCEP-ERROR Object
byte[] errorMsg = new byte[] {0x20, 0x06, 0x00, 0x3C, // common header
0x0D, 0x10, 0x00, 0x08, // PCERR Object Header
0x00, 0x00, 0x01, 0x01,
0x0D, 0x10, 0x00, 0x08, // PCERR Object Header
0x00, 0x00, 0x01, 0x03,
0x65, 0x10, 0x00, 0x0C, // TE Object Header
0x01, 0x00, 0x00, 0x03,
0x00, 0x00, 0x00, 0x10, // TE-ID
0x65, 0x10, 0x00, 0x0C, // TE Object Header
0x01, 0x00, 0x00, 0x03,
0x00, 0x00, 0x00, 0x11, // TE-ID
0x0D, 0x10, 0x00, 0x08, // PCERR Object Header
0x00, 0x00, 0x01, 0x04,
0x0D, 0x10, 0x00, 0x08, // PCERR Object Header
0x00, 0x00, 0x01, 0x06};
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(errorMsg);
PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
PcepMessage message = null;
try {
message = reader.readFrom(buffer);
} catch (PcepParseException e) {
e.printStackTrace();
}
byte[] testErrorMsg = {0};
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
if (message instanceof PcepErrorMsg) {
message.writeTo(buf);
int iReadLen = buf.writerIndex() - 0;
testErrorMsg = new byte[iReadLen];
buf.readBytes(testErrorMsg, 0, iReadLen);
if (Arrays.equals(errorMsg, testErrorMsg)) {
Assert.assertArrayEquals(errorMsg, testErrorMsg);
log.debug("Pcep Error Msg are Equal ");
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
}
@Test
public void errorMessageTest20() throws PcepParseException {
/* PCEP-ERROR Object, RP Object, RP Object, PCEP-ERROR Object, PCEP-ERROR Object,
* TE Object, PCEP-ERROR Object
*/
byte[] errorMsg = new byte[] {0x20, 0x06, 0x00, 0x48, // common header
0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header
0x00, 0x00, 0x01, 0x01,
0x02, 0x10, 0x00, 0x0C, // RP Object Header
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x03,
0x02, 0x10, 0x00, 0x0C, // RP Object Header
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x04,
0x0D, 0x10, 0x00, 0x08, // PCERR Object Header
0x00, 0x00, 0x01, 0x04,
0x0D, 0x10, 0x00, 0x08, // PCERR Object Header
0x00, 0x00, 0x01, 0x06,
0x65, 0x10, 0x00, 0x0C, // TE Object Header
0x01, 0x00, 0x00, 0x03,
0x00, 0x00, 0x00, 0x10, // TE-ID
0x0D, 0x10, 0x00, 0x08, // PCERR Object Header
0x00, 0x00, 0x01, 0x06};
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(errorMsg);
PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
PcepMessage message = null;
try {
message = reader.readFrom(buffer);
} catch (PcepParseException e) {
e.printStackTrace();
}
byte[] testErrorMsg = {0};
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
if (message instanceof PcepErrorMsg) {
message.writeTo(buf);
int iReadLen = buf.writerIndex() - 0;
testErrorMsg = new byte[iReadLen];
buf.readBytes(testErrorMsg, 0, iReadLen);
if (Arrays.equals(errorMsg, testErrorMsg)) {
Assert.assertArrayEquals(errorMsg, testErrorMsg);
log.debug("Pcep Error Msg are Equal ");
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
}
}
/*
* Copyright 2014-2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.pcepio;
import java.util.Arrays;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.onosproject.pcepio.exceptions.PcepParseException;
import org.onosproject.pcepio.protocol.PcepFactories;
import org.onosproject.pcepio.protocol.PcepMessage;
import org.onosproject.pcepio.protocol.PcepMessageReader;
import org.onosproject.pcepio.protocol.PcepOpenMsg;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Test cases for PCEP OPEN Message.
*/
public class PcepOpenMsgTest {
protected static final Logger log = LoggerFactory.getLogger(PcepOpenMsgTest.class);
@Before
public void startUp() {
}
@After
public void tearDown() {
}
@Test
public void openMessageTest1() throws PcepParseException {
// OPEN OBJECT (STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, PCECC-CAPABILITY-TLV, )
byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x24, 0x01, 0x10, 0x00, 0x20, 0x20, 0x1e, 0x78, (byte) 0xbd,
0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0f, //STATEFUL-PCE-CAPABILITY
0x00, 0x0e, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, //GMPLS-CAPABILITY-TLV
0x00, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, //PCECC-CAPABILITY-TLV
};
byte[] testOpenMsg = {0};
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(openMsg);
PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
PcepMessage message = null;
try {
message = reader.readFrom(buffer);
} catch (PcepParseException e) {
e.printStackTrace();
}
if (message instanceof PcepOpenMsg) {
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
message.writeTo(buf);
testOpenMsg = buf.array();
int iReadLen = buf.writerIndex() - 0;
testOpenMsg = new byte[iReadLen];
buf.readBytes(testOpenMsg, 0, iReadLen);
if (Arrays.equals(openMsg, testOpenMsg)) {
Assert.assertArrayEquals(openMsg, testOpenMsg);
log.debug("openMsg are equal :" + openMsg);
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
}
@Test
public void openMessageTest2() throws PcepParseException {
// OPEN OBJECT (STATEFUL-PCE-CAPABILITY).
byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x14, // common header
0x01, 0x10, 0x00, 0x10, // common object header
0x20, 0x1E, 0x78, 0x01, // OPEN object
0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0f}; // STATEFUL-PCE-CAPABILITY
byte[] testOpenMsg = {0};
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(openMsg);
PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
PcepMessage message = null;
try {
message = reader.readFrom(buffer);
} catch (PcepParseException e) {
e.printStackTrace();
}
if (message instanceof PcepOpenMsg) {
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
message.writeTo(buf);
testOpenMsg = buf.array();
int iReadLen = buf.writerIndex() - 0;
testOpenMsg = new byte[iReadLen];
buf.readBytes(testOpenMsg, 0, iReadLen);
if (Arrays.equals(openMsg, testOpenMsg)) {
Assert.assertArrayEquals(openMsg, testOpenMsg);
log.debug("openMsg are equal :" + openMsg);
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
}
@Test
public void openMessageTest3() throws PcepParseException {
// OPEN OBJECT (GmplsCapability).
byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x14, // common header
0x01, 0x10, 0x00, 0x10, // common object header
0x20, 0x1E, 0x78, 0x01, // OPEN object
0x00, 0x0e, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00}; //GMPLS-CAPABILITY-TLV
byte[] testOpenMsg = {0};
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(openMsg);
PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
PcepMessage message = null;
try {
message = reader.readFrom(buffer);
} catch (PcepParseException e) {
e.printStackTrace();
}
if (message instanceof PcepOpenMsg) {
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
message.writeTo(buf);
testOpenMsg = buf.array();
int iReadLen = buf.writerIndex() - 0;
testOpenMsg = new byte[iReadLen];
buf.readBytes(testOpenMsg, 0, iReadLen);
if (Arrays.equals(openMsg, testOpenMsg)) {
Assert.assertArrayEquals(openMsg, testOpenMsg);
log.debug("openMsg are equal :" + openMsg);
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
}
@Test
public void openMessageTest4() throws PcepParseException {
// OPEN OBJECT (StatefulLspDbVerTlv).
byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x18,
0x01, 0x10, 0x00, 0x14, 0x20, 0x1e, 0x78, 0x20,
0x00, 0x17, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }; //StatefulLspDbVerTlv
byte[] testOpenMsg = {0};
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(openMsg);
PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
PcepMessage message = null;
try {
message = reader.readFrom(buffer);
} catch (PcepParseException e) {
e.printStackTrace();
}
if (message instanceof PcepOpenMsg) {
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
message.writeTo(buf);
testOpenMsg = buf.array();
int iReadLen = buf.writerIndex() - 0;
testOpenMsg = new byte[iReadLen];
buf.readBytes(testOpenMsg, 0, iReadLen);
if (Arrays.equals(openMsg, testOpenMsg)) {
Assert.assertArrayEquals(openMsg, testOpenMsg);
log.debug("openMsg are equal :" + openMsg);
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
}
@Test
public void openMessageTest5() throws PcepParseException {
// OPEN OBJECT (no Tlvs).
byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x0C,
0x01, 0x10, 0x00, 0x08, 0x20, 0x1e, 0x78, (byte) 0xbd }; // no Tlvs in open messsage
byte[] testOpenMsg = {0};
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(openMsg);
PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
PcepMessage message = null;
try {
message = reader.readFrom(buffer);
} catch (PcepParseException e) {
e.printStackTrace();
}
if (message instanceof PcepOpenMsg) {
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
message.writeTo(buf);
testOpenMsg = buf.array();
int iReadLen = buf.writerIndex() - 0;
testOpenMsg = new byte[iReadLen];
buf.readBytes(testOpenMsg, 0, iReadLen);
if (Arrays.equals(openMsg, testOpenMsg)) {
Assert.assertArrayEquals(openMsg, testOpenMsg);
log.debug("openMsg are equal :" + openMsg);
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
}
@Test
public void openMessageTest6() throws PcepParseException {
/* OPEN OBJECT (STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, PCECC-CAPABILITY-TLV) with
p bit not set & i bit set.
*/
byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x24, 0x01, 0x11, 0x00, 0x20, //p bit not set & i bit set
0x20, 0x1e, 0x78, (byte) 0xbd,
0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0f, // STATEFUL-PCE-CAPABILITY
0x00, 0x0e, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, //GMPLS-CAPABILITY-TLV
0x00, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, //PCECC-CAPABILITY-TLV
};
byte[] testOpenMsg = {0};
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(openMsg);
PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
PcepMessage message = null;
try {
message = reader.readFrom(buffer);
} catch (PcepParseException e) {
e.printStackTrace();
}
if (message instanceof PcepOpenMsg) {
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
message.writeTo(buf);
testOpenMsg = buf.array();
int iReadLen = buf.writerIndex() - 0;
testOpenMsg = new byte[iReadLen];
buf.readBytes(testOpenMsg, 0, iReadLen);
if (Arrays.equals(openMsg, testOpenMsg)) {
Assert.assertArrayEquals(openMsg, testOpenMsg);
log.debug("openMsg are equal :" + openMsg);
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
}
@Test
public void openMessageTest7() throws PcepParseException {
/* OPEN OBJECT (STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, PCECC-CAPABILITY-TLV)
with p bit set & i bit not set.
*/
byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x24, 0x01, 0x12, 0x00, 0x20, //p bit set & i bit not set
0x20, 0x1e, 0x78, (byte) 0xbd,
0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0f, //STATEFUL-PCE-CAPABILITY
0x00, 0x0e, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, //GMPLS-CAPABILITY-TLV
0x00, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, //PCECC-CAPABILITY-TLV
};
byte[] testOpenMsg = {0};
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(openMsg);
PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
PcepMessage message = null;
try {
message = reader.readFrom(buffer);
} catch (PcepParseException e) {
e.printStackTrace();
}
if (message instanceof PcepOpenMsg) {
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
message.writeTo(buf);
testOpenMsg = buf.array();
int iReadLen = buf.writerIndex() - 0;
testOpenMsg = new byte[iReadLen];
buf.readBytes(testOpenMsg, 0, iReadLen);
if (Arrays.equals(openMsg, testOpenMsg)) {
Assert.assertArrayEquals(openMsg, testOpenMsg);
log.debug("openMsg are equal :" + openMsg);
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
}
@Test
public void openMessageTest8() throws PcepParseException {
/* OPEN OBJECT (STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, PCECC-CAPABILITY-TLV)
with p bit set & i bit set.
*/
byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x24, 0x01, 0x13, 0x00, 0x20, //p bit set & i bit set
0x20, 0x1e, 0x78, (byte) 0xbd,
0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0f, //STATEFUL-PCE-CAPABILITY
0x00, 0x0e, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, //GMPLS-CAPABILITY-TLV
0x00, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, //PCECC-CAPABILITY-TLV
};
byte[] testOpenMsg = {0};
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(openMsg);
PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
PcepMessage message = null;
try {
message = reader.readFrom(buffer);
} catch (PcepParseException e) {
e.printStackTrace();
}
if (message instanceof PcepOpenMsg) {
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
message.writeTo(buf);
testOpenMsg = buf.array();
int iReadLen = buf.writerIndex() - 0;
testOpenMsg = new byte[iReadLen];
buf.readBytes(testOpenMsg, 0, iReadLen);
if (Arrays.equals(openMsg, testOpenMsg)) {
Assert.assertArrayEquals(openMsg, testOpenMsg);
log.debug("openMsg are equal :" + openMsg);
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
}
@Test
public void openMessageTest9() throws PcepParseException {
/* OPEN OBJECT (STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, PCECC-CAPABILITY-TLV)
with p bit set & i bit set.
*/
byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x24, 0x01, 0x13, 0x00, 0x20, //p bit set & i bit set
0x20, 0x1e, 0x78, 0x00, //invalid sessionID
0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0f, //STATEFUL-PCE-CAPABILITY
0x00, 0x0e, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, //GMPLS-CAPABILITY-TLV
0x00, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, //PCECC-CAPABILITY-TLV
};
byte[] testOpenMsg = {0};
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(openMsg);
PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
PcepMessage message = null;
try {
message = reader.readFrom(buffer);
} catch (PcepParseException e) {
e.printStackTrace();
}
if (message instanceof PcepOpenMsg) {
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
message.writeTo(buf);
testOpenMsg = buf.array();
int iReadLen = buf.writerIndex() - 0;
testOpenMsg = new byte[iReadLen];
buf.readBytes(testOpenMsg, 0, iReadLen);
if (Arrays.equals(openMsg, testOpenMsg)) {
Assert.assertArrayEquals(openMsg, testOpenMsg);
log.debug("openMsg are equal :" + openMsg);
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
}
@Test
public void openMessageTest10() throws PcepParseException {
//OPEN OBJECT (STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV).
byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x1C, // common header
0x01, 0x10, 0x00, 0x18, // common object header
0x20, 0x05, 0x1E, 0x01, // OPEN object
0x00, 0x10, 0x00, 0x04, // STATEFUL-PCE-CAPABILITY
0x00, 0x00, 0x00, 0x05,
0x00, 0x0E, 0x00, 0x04, // GMPLS-CAPABILITY-TLV
0x00, 0x00, 0x00, 0x00};
byte[] testOpenMsg = {0};
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(openMsg);
PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
PcepMessage message = null;
try {
message = reader.readFrom(buffer);
} catch (PcepParseException e) {
e.printStackTrace();
}
if (message instanceof PcepOpenMsg) {
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
message.writeTo(buf);
testOpenMsg = buf.array();
int iReadLen = buf.writerIndex() - 0;
testOpenMsg = new byte[iReadLen];
buf.readBytes(testOpenMsg, 0, iReadLen);
if (Arrays.equals(openMsg, testOpenMsg)) {
Assert.assertArrayEquals(openMsg, testOpenMsg);
log.debug("openMsg are equal :" + openMsg);
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
}
@Test
public void openMessageTest11() throws PcepParseException {
//OPEN OBJECT (STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, PCECC-CAPABILITY-TLV, TED Capability TLV).
byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x2C, // common header
0x01, 0x10, 0x00, 0x28, // common object header
0x20, 0x05, 0x1E, 0x01, // OPEN object
0x00, 0x10, 0x00, 0x04, // STATEFUL-PCE-CAPABILITY
0x00, 0x00, 0x00, 0x05, 0x00, 0x0E, 0x00, 0x04, // GMPLS-CAPABILITY-TLV
0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, // PCECC-CAPABILITY-TLV
0x00, 0x00, 0x00, 0x03, 0x00, (byte) 0x84, 0x00, 0x04, // TED Capability TLV
0x00, 0x00, 0x00, 0x00 };
byte[] testOpenMsg = {0};
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(openMsg);
PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
PcepMessage message = null;
try {
message = reader.readFrom(buffer);
} catch (PcepParseException e) {
e.printStackTrace();
}
if (message instanceof PcepOpenMsg) {
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
message.writeTo(buf);
testOpenMsg = buf.array();
int iReadLen = buf.writerIndex() - 0;
testOpenMsg = new byte[iReadLen];
buf.readBytes(testOpenMsg, 0, iReadLen);
if (Arrays.equals(openMsg, testOpenMsg)) {
Assert.assertArrayEquals(openMsg, testOpenMsg);
log.debug("openMsg are equal :" + openMsg);
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
}
@Test
public void openMessageTest12() throws PcepParseException {
//OPEN OBJECT (STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, PCECC-CAPABILITY-TLV).
byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x24, // common header
0x01, 0x10, 0x00, 0x20, // common object header
0x20, 0x05, 0x1E, 0x01, // OPEN object
0x00, 0x10, 0x00, 0x04, // STATEFUL-PCE-CAPABILITY
0x00, 0x00, 0x00, 0x05, 0x00, 0x0E, 0x00, 0x04, // GMPLS-CAPABILITY-TLV
0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, // PCECC-CAPABILITY-TLV
0x00, 0x00, 0x00, 0x03};
byte[] testOpenMsg = {0};
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(openMsg);
PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
PcepMessage message = null;
try {
message = reader.readFrom(buffer);
} catch (PcepParseException e) {
e.printStackTrace();
}
if (message instanceof PcepOpenMsg) {
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
message.writeTo(buf);
testOpenMsg = buf.array();
int iReadLen = buf.writerIndex() - 0;
testOpenMsg = new byte[iReadLen];
buf.readBytes(testOpenMsg, 0, iReadLen);
if (Arrays.equals(openMsg, testOpenMsg)) {
Assert.assertArrayEquals(openMsg, testOpenMsg);
log.debug("openMsg are equal :" + openMsg);
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
}
@Test
public void openMessageTest13() throws PcepParseException {
//OPEN OBJECT (STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV).
byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x1c, // common header
0x01, 0x10, 0x00, 0x18, // common object header
0x20, 0x05, 0x1E, 0x01, // OPEN object
0x00, 0x10, 0x00, 0x04, // STATEFUL-PCE-CAPABILITY
0x00, 0x00, 0x00, 0x05, 0x00, 0x0E, 0x00, 0x04, // GMPLS-CAPABILITY-TLV
0x00, 0x00, 0x00, 0x00};
byte[] testOpenMsg = {0};
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(openMsg);
PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
PcepMessage message = null;
try {
message = reader.readFrom(buffer);
} catch (PcepParseException e) {
e.printStackTrace();
}
if (message instanceof PcepOpenMsg) {
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
message.writeTo(buf);
testOpenMsg = buf.array();
int iReadLen = buf.writerIndex() - 0;
testOpenMsg = new byte[iReadLen];
buf.readBytes(testOpenMsg, 0, iReadLen);
if (Arrays.equals(openMsg, testOpenMsg)) {
Assert.assertArrayEquals(openMsg, testOpenMsg);
log.debug("openMsg are equal :" + openMsg);
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
} else {
Assert.fail("test case failed ");
log.debug("not equal");
}
}
@Test
public void openMessageTest14() throws PcepParseException {
//OPEN OBJECT (STATEFUL-PCE-CAPABILITY).
byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x14, // common header
0x01, 0x10, 0x00, 0x10, // common object header
0x20, 0x05, 0x1E, 0x01, // OPEN object
0x00, 0x10, 0x00, 0x04, // STATEFUL-PCE-CAPABILITY
0x00, 0x00, 0x00, 0x05};
byte[] testOpenMsg = {0};
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(openMsg);
PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
PcepMessage message = null;
try {
message = reader.readFrom(buffer);
} catch (PcepParseException e) {
e.printStackTrace();
}
if (message instanceof PcepOpenMsg) {
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
message.writeTo(buf);
testOpenMsg = buf.array();
int iReadLen = buf.writerIndex() - 0;
testOpenMsg = new byte[iReadLen];
buf.readBytes(testOpenMsg, 0, iReadLen);
if (Arrays.equals(openMsg, testOpenMsg)) {
Assert.assertArrayEquals(openMsg, testOpenMsg);
log.debug("openMsg are equal :" + openMsg);
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
}
@Test
public void openMessageTest15() throws PcepParseException {
// OPEN OBJECT.
byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x0c, // common header
0x01, 0x10, 0x00, 0x08, // common object header
0x20, 0x05, 0x1E, 0x01 // OPEN object
};
byte[] testOpenMsg = {0};
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(openMsg);
PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
PcepMessage message = null;
try {
message = reader.readFrom(buffer);
} catch (PcepParseException e) {
e.printStackTrace();
}
if (message instanceof PcepOpenMsg) {
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
message.writeTo(buf);
testOpenMsg = buf.array();
int iReadLen = buf.writerIndex() - 0;
testOpenMsg = new byte[iReadLen];
buf.readBytes(testOpenMsg, 0, iReadLen);
if (Arrays.equals(openMsg, testOpenMsg)) {
Assert.assertArrayEquals(openMsg, testOpenMsg);
log.debug("openMsg are equal :" + openMsg);
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
} else {
Assert.fail("test case failed");
log.debug("not equal");
}
}
}