Mahesh Poojary S
Committed by Gerrit Code Review

[ONOS-2363]Implementation of Open and Error messages.

Change-Id: Id4aa762caf1847a6b5e56517cb159608fd54eefb
Showing 83 changed files with 10916 additions and 0 deletions
/*
* Copyright 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.protocol.ver1;
import java.util.LinkedList;
import java.util.ListIterator;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.pcepio.exceptions.PcepParseException;
import org.onosproject.pcepio.protocol.PcepError;
import org.onosproject.pcepio.protocol.PcepErrorInfo;
import org.onosproject.pcepio.protocol.PcepErrorObject;
import org.onosproject.pcepio.protocol.PcepRPObject;
import org.onosproject.pcepio.protocol.PcepTEObject;
import org.onosproject.pcepio.types.PcepObjectHeader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
/**
* Provides PCEP Error Info.
* Reference :PCEP Extension for Transporting TE Data draft-dhodylee-pce-pcep-te-data-extn-02.
*/
public class PcepErrorInfoVer1 implements PcepErrorInfo {
protected static final Logger log = LoggerFactory.getLogger(PcepErrorInfoVer1.class);
//Error list is optional
private LinkedList<PcepError> errList;
/**
* Constructor to add PCEP error object to the list.
*
* @param llRPObjList list of PCEP RP object
* @param llTEObjList list of PCEP TE object
* @param llErrObjList list of PCEP error object
*/
public PcepErrorInfoVer1(LinkedList<PcepRPObject> llRPObjList, LinkedList<PcepTEObject> llTEObjList,
LinkedList<PcepErrorObject> llErrObjList) {
this.errList = new LinkedList<PcepError>();
if ((null != llErrObjList) && (!llErrObjList.isEmpty())) {
this.errList.add(new PcepErrorVer1(llRPObjList, llTEObjList, llErrObjList));
}
}
/**
* Constructor to initialize error info.
*
* @param errll linked list or pcep error
*/
public PcepErrorInfoVer1(LinkedList<PcepError> errll) {
this.errList = errll;
}
@Override
public boolean isErrorInfoPresent() {
return (!this.errList.isEmpty()) ? true : false;
}
@Override
public void read(ChannelBuffer cb) throws PcepParseException {
PcepObjectHeader tempObjHeader;
while (0 < cb.readableBytes()) {
cb.markReaderIndex();
tempObjHeader = PcepObjectHeader.read(cb);
cb.resetReaderIndex();
byte yObjClass = tempObjHeader.getObjClass();
if ((yObjClass != PcepRPObjectVer1.RP_OBJ_CLASS) && (yObjClass != PcepTEObjectVer1.TE_OBJ_CLASS)
&& (yObjClass != PcepErrorObjectVer1.ERROR_OBJ_CLASS)) {
throw new PcepParseException("Unknown Object is present in PCEP-ERROR. Object Class: " + yObjClass);
}
this.errList.add(PcepErrorVer1.read(cb));
}
}
@Override
public void write(ChannelBuffer cb) throws PcepParseException {
//write <error>
ListIterator<PcepError> listIterator = errList.listIterator();
while (listIterator.hasNext()) {
PcepError pcepError = listIterator.next();
//RP Object list is optional
LinkedList<PcepRPObject> llRPObjList = pcepError.getRPObjList();
if (llRPObjList != null) {
ListIterator<PcepRPObject> rpListIterator = llRPObjList.listIterator();
while (rpListIterator.hasNext()) {
rpListIterator.next().write(cb);
}
}
//TE Object list is optional
LinkedList<PcepTEObject> llTEObjList = pcepError.getTEObjList();
if (llTEObjList != null) {
ListIterator<PcepTEObject> teListIterator = llTEObjList.listIterator();
while (teListIterator.hasNext()) {
teListIterator.next().write(cb);
}
}
// <error-obj-list> is mandatory
boolean bIsErrorObjListFound = false;
LinkedList<PcepErrorObject> llErrObjList = pcepError.getErrorObjList();
if (llErrObjList != null) {
ListIterator<PcepErrorObject> errObjListIterator = llErrObjList.listIterator();
while (errObjListIterator.hasNext()) {
errObjListIterator.next().write(cb);
bIsErrorObjListFound = true;
}
}
if (!bIsErrorObjListFound) {
throw new PcepParseException("<error-obj-list> is mandatory.");
}
}
}
@Override
public LinkedList<Integer> getErrorType() {
LinkedList<Integer> errorType = new LinkedList<Integer>();
ListIterator<PcepError> listIterator = errList.listIterator();
PcepErrorObject errObj;
int error;
while (listIterator.hasNext()) {
PcepError pcepError = listIterator.next();
LinkedList<PcepErrorObject> llErrObjList = pcepError.getErrorObjList();
if (llErrObjList != null) {
ListIterator<PcepErrorObject> errObjListIterator = llErrObjList.listIterator();
while (errObjListIterator.hasNext()) {
errObj = errObjListIterator.next();
error = errObj.getErrorType();
errorType.add(error);
}
}
}
return errorType;
}
@Override
public LinkedList<Integer> getErrorValue() {
LinkedList<Integer> errorValue = new LinkedList<Integer>();
ListIterator<PcepError> listIterator = errList.listIterator();
PcepErrorObject errObj;
int error;
while (listIterator.hasNext()) {
PcepError pcepError = listIterator.next();
LinkedList<PcepErrorObject> llErrObjList = pcepError.getErrorObjList();
if (llErrObjList != null) {
ListIterator<PcepErrorObject> errObjListIterator = llErrObjList.listIterator();
while (errObjListIterator.hasNext()) {
errObj = errObjListIterator.next();
error = errObj.getErrorValue();
errorValue.add(error);
}
}
}
return errorValue;
}
/**
* Builder class for PCEP error info.
*/
public static class Builder implements PcepErrorInfo.Builder {
private LinkedList<PcepError> errll;
@Override
public PcepErrorInfo build() {
return new PcepErrorInfoVer1(errll);
}
@Override
public LinkedList<PcepError> getPcepErrorList() {
return this.errll;
}
@Override
public Builder setPcepErrorList(LinkedList<PcepError> errll) {
this.errll = errll;
return this;
}
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass()).add("ErrorList", errList).toString();
}
}
package org.onosproject.pcepio.protocol.ver1;
import java.util.LinkedList;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.pcepio.exceptions.PcepParseException;
import org.onosproject.pcepio.protocol.PcepErrorInfo;
import org.onosproject.pcepio.protocol.PcepErrorMsg;
import org.onosproject.pcepio.protocol.PcepErrorObject;
import org.onosproject.pcepio.protocol.PcepMessageReader;
import org.onosproject.pcepio.protocol.PcepMessageWriter;
import org.onosproject.pcepio.protocol.PcepOpenObject;
import org.onosproject.pcepio.protocol.PcepType;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.onosproject.pcepio.types.ErrorObjListWithOpen;
import org.onosproject.pcepio.types.PcepObjectHeader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;
public class PcepErrorMsgVer1 implements PcepErrorMsg {
/*
* PCE Error message format.
<PCErr Message> ::= <Common Header>
( <error-obj-list> [<Open>] ) | <error>
[<error-list>]
<error-obj-list> ::=<PCEP-ERROR>[<error-obj-list>]
<error> ::=[<request-id-list> | <te-id-list>]
<error-obj-list>
<request-id-list> ::=<RP>[<request-id-list>]
<te-id-list> ::=<TE>[<te-id-list>]
<error-list> ::=<error>[<error-list>]
*/
protected static final Logger log = LoggerFactory.getLogger(PcepOpenMsgVer1.class);
public static final byte PACKET_VERSION = 1;
public static final int PACKET_MINIMUM_LENGTH = 12;
public static final PcepType MSG_TYPE = PcepType.ERROR;
//Below either one should be present.
private ErrorObjListWithOpen errObjListWithOpen; //optional ( <error-obj-list> [<Open>] )
private PcepErrorInfo errInfo; //optional <error> [<error-list>]
public static final PcepErrorMsgVer1.Reader READER = new Reader();
/**
* constructor to initialize variables.
*/
public PcepErrorMsgVer1() {
errObjListWithOpen = null;
errInfo = null;
}
/**
* Constructor to initialize variables.
*
* @param errObjListWithOpen error-object-list with open object
* @param errInfo error information
*/
public PcepErrorMsgVer1(ErrorObjListWithOpen errObjListWithOpen, PcepErrorInfo errInfo) {
this.errObjListWithOpen = errObjListWithOpen;
this.errInfo = errInfo;
}
public static class Reader implements PcepMessageReader<PcepErrorMsg> {
ErrorObjListWithOpen errObjListWithOpen;
PcepErrorInfo errInfo;
PcepObjectHeader tempObjHeader;
@Override
public PcepErrorMsg readFrom(ChannelBuffer cb) throws PcepParseException {
errObjListWithOpen = null;
errInfo = null;
tempObjHeader = null;
if (cb.readableBytes() < PACKET_MINIMUM_LENGTH) {
throw new PcepParseException("Packet size is less than the minimum length.");
}
byte version = cb.readByte();
version = (byte) (version >> PcepMessageVer1.SHIFT_FLAG);
if (version != PACKET_VERSION) {
throw new PcepParseException("Wrong version: Expected=PcepVersion.PCEP_1(1), got=" + version);
}
// fixed value property type == 1
byte type = cb.readByte();
if (type != MSG_TYPE.getType()) {
throw new PcepParseException("Wrong type: Expected=PcepType.ERROR(6), got=" + type);
}
int length = cb.readShort();
if (length < PACKET_MINIMUM_LENGTH) {
throw new PcepParseException(
"Wrong length: Expected to be >= " + PACKET_MINIMUM_LENGTH + ", was: " + length);
}
//parse <PCErr Message>
parsePCErrMsg(cb);
// If other than RP or TE or PCEP-ERROR present then it is error.
if (0 < cb.readableBytes()) {
PcepObjectHeader tempObjHeader = PcepObjectHeader.read(cb);
throw new PcepParseException("Unexpected Object found. Object Class : " + tempObjHeader.getObjClass());
}
return new PcepErrorMsgVer1(errObjListWithOpen, errInfo);
}
/**
* Parsing PCErr Message.
*
* @param cb channel buffer.
* @throws PcepParseException if mandatory fields are missing
* output: this.errObjListWithOpen, this.errInfo
*/
public void parsePCErrMsg(ChannelBuffer cb) throws PcepParseException {
//If PCEP-ERROR list is followed by OPEN Object then store into ErrorObjListWithOpen.
// ( <error-obj-list> [<Open>]
//If PCEP-ERROR list is followed by RP or TE Object then store into errInfo. <error> [<error-list>]
//If only PCEP-ERROR list is present then store into ErrorObjListWithOpen.
PcepObjectHeader tempObjHeader;
LinkedList<PcepErrorObject> llErrObjList;
if (0 >= cb.readableBytes()) {
throw new PcepParseException("PCEP-ERROR message came with empty objects.");
}
//parse PCEP-ERROR list
llErrObjList = new LinkedList<PcepErrorObject>();
tempObjHeader = parseErrorObjectList(llErrObjList, cb);
//check whether OPEN-OBJECT is present.
if ((tempObjHeader instanceof PcepObjectHeader)
&& (tempObjHeader.getObjClass() == PcepOpenObjectVer1.OPEN_OBJ_CLASS)) {
if (llErrObjList.isEmpty()) {
throw new PcepParseException("<error-obj-list> should be present if OPEN-OBJECT exists");
}
PcepOpenObject pcepOpenObj = PcepOpenObjectVer1.read(cb);
this.errObjListWithOpen = new ErrorObjListWithOpen(llErrObjList, pcepOpenObj);
} else if ((tempObjHeader instanceof PcepObjectHeader) //check whether RP or TE Object is present.
&& ((tempObjHeader.getObjClass() == PcepRPObjectVer1.RP_OBJ_CLASS)
|| (tempObjHeader.getObjClass() == PcepTEObjectVer1.TE_OBJ_CLASS))) {
this.errInfo = new PcepErrorInfoVer1(null, null, llErrObjList);
this.errInfo.read(cb);
} else if ((null != llErrObjList) && (!llErrObjList.isEmpty())) {
//If only PCEP-ERROR list is present then store it in errObjListWithOpen.
this.errObjListWithOpen = new ErrorObjListWithOpen(llErrObjList);
} else {
throw new PcepParseException("Empty PCEP-ERROR message.");
}
}
/**
* Parse error-obj-list.
*
* @param llErrObjList error object list output
* @param cb channel buffer input
* @throws PcepParseException if mandatory fields are missing
* @return error object header
*/
public PcepObjectHeader parseErrorObjectList(LinkedList<PcepErrorObject> llErrObjList, ChannelBuffer cb)
throws PcepParseException {
PcepObjectHeader tempObjHeader = null;
while (0 < cb.readableBytes()) {
cb.markReaderIndex();
tempObjHeader = PcepObjectHeader.read(cb);
cb.resetReaderIndex();
if (tempObjHeader.getObjClass() == PcepErrorObjectVer1.ERROR_OBJ_CLASS) {
llErrObjList.add(PcepErrorObjectVer1.read(cb));
} else {
break;
}
}
return tempObjHeader;
}
}
/**
* Builder class for PCEP error message.
*/
public static class Builder implements PcepErrorMsg.Builder {
// Pcep error message fields
private ErrorObjListWithOpen errObjListWithOpen = null; //optional ( <error-obj-list> [<Open>] )
private PcepErrorInfo errInfo = null; //optional <error> [<error-list>]
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
@Override
public PcepType getType() {
return PcepType.ERROR;
}
@Override
public PcepErrorMsg build() {
return new PcepErrorMsgVer1(this.errObjListWithOpen, this.errInfo);
}
@Override
public ErrorObjListWithOpen getErrorObjListWithOpen() {
return this.errObjListWithOpen;
}
@Override
public Builder setErrorObjListWithOpen(ErrorObjListWithOpen errObjListWithOpen) {
this.errObjListWithOpen = errObjListWithOpen;
return this;
}
@Override
public PcepErrorInfo getPcepErrorInfo() {
return this.errInfo;
}
@Override
public Builder setPcepErrorInfo(PcepErrorInfo errInfo) {
this.errInfo = errInfo;
return this;
}
}
@Override
public void writeTo(ChannelBuffer cb) throws PcepParseException {
WRITER.write(cb, this);
}
public static final Writer WRITER = new Writer();
static class Writer implements PcepMessageWriter<PcepErrorMsgVer1> {
@Override
public void write(ChannelBuffer cb, PcepErrorMsgVer1 message) throws PcepParseException {
int startIndex = cb.writerIndex();
// first 3 bits set to version
cb.writeByte((byte) (PACKET_VERSION << PcepMessageVer1.SHIFT_FLAG));
// message type 0xC
cb.writeByte(MSG_TYPE.getType());
// length is length of variable message, will be updated at the end
// Store the position of message
// length in buffer
int msgLenIndex = cb.writerIndex();
cb.writeShort(0);
ErrorObjListWithOpen errObjListWithOpen = message.getErrorObjListWithOpen();
PcepErrorInfo errInfo = message.getPcepErrorInfo();
// write ( <error-obj-list> [<Open>] ) if exists.
// otherwise write <error> [<error-list>]
if ((errObjListWithOpen instanceof ErrorObjListWithOpen)
&& (errObjListWithOpen.isErrorObjListWithOpenPresent())) {
errObjListWithOpen.write(cb);
} else if ((errInfo instanceof PcepErrorInfo) && (errInfo.isErrorInfoPresent())) {
errInfo.write(cb);
} else {
throw new PcepParseException("Empty PCEP-ERROR message.");
}
// PcepErrorMessage message length field
int length = cb.writerIndex() - startIndex;
cb.setShort(msgLenIndex, (short) length);
}
}
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
@Override
public PcepType getType() {
return MSG_TYPE;
}
@Override
public ErrorObjListWithOpen getErrorObjListWithOpen() {
return this.errObjListWithOpen;
}
@Override
public void setErrorObjListWithOpen(ErrorObjListWithOpen errObjListWithOpen) {
this.errObjListWithOpen = errObjListWithOpen;
}
@Override
public PcepErrorInfo getPcepErrorInfo() {
return this.errInfo;
}
@Override
public void setPcepErrorInfo(PcepErrorInfo errInfo) {
this.errInfo = errInfo;
}
/**
* Return list of Error types.
*
* @return error types list
*/
public LinkedList<Integer> getErrorType() {
LinkedList<Integer> llErrorType = new LinkedList<Integer>();
if ((errObjListWithOpen instanceof ErrorObjListWithOpen)
&& (errObjListWithOpen.isErrorObjListWithOpenPresent())) {
llErrorType = errObjListWithOpen.getErrorType();
} else if ((errInfo instanceof PcepErrorInfo) && (errInfo.isErrorInfoPresent())) {
llErrorType = errInfo.getErrorType();
}
return llErrorType;
}
/**
* Return list of Error values.
*
* @return error value list
*/
public LinkedList<Integer> getErrorValue() {
LinkedList<Integer> llErrorValue = new LinkedList<Integer>();
if ((errObjListWithOpen instanceof ErrorObjListWithOpen)
&& (errObjListWithOpen.isErrorObjListWithOpenPresent())) {
llErrorValue = errObjListWithOpen.getErrorValue();
} else if ((errInfo instanceof PcepErrorInfo) && (errInfo.isErrorInfoPresent())) {
llErrorValue = errInfo.getErrorValue();
}
return llErrorValue;
}
@Override
public String toString() {
ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass());
if ((errObjListWithOpen instanceof ErrorObjListWithOpen)
&& (errObjListWithOpen.isErrorObjListWithOpenPresent())) {
toStrHelper.add("ErrorObjectListWithOpen", errObjListWithOpen);
}
if ((errInfo instanceof PcepErrorInfo) && (errInfo.isErrorInfoPresent())) {
toStrHelper.add("ErrorInfo", errInfo);
}
return toStrHelper.toString();
}
}
package org.onosproject.pcepio.protocol.ver1;
import java.util.LinkedList;
import java.util.ListIterator;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.pcepio.exceptions.PcepParseException;
import org.onosproject.pcepio.protocol.PcepErrorObject;
import org.onosproject.pcepio.types.PcepObjectHeader;
import org.onosproject.pcepio.types.PcepValueType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
/*
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Object-Class | OT |Res|P|I| Object Length (bytes) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Reserved | Flags | Error-Type | Error-value |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
// Optional TLVs //
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
public class PcepErrorObjectVer1 implements PcepErrorObject {
protected static final Logger log = LoggerFactory.getLogger(PcepErrorObjectVer1.class);
public static final byte ERROR_OBJ_TYPE = 1;
public static final byte ERROR_OBJ_CLASS = 13;
public static final byte ERROR_OBJECT_VERSION = 1;
//ERROR_OBJ_MINIMUM_LENGTH = CommonHeaderLen(4)+ErrorObjectHeaderLen(4)
public static final short ERROR_OBJ_MINIMUM_LENGTH = 8;
public static final int OBJECT_HEADER_LENGTH = 4;
public static final PcepObjectHeader DEFAULT_ERROR_OBJECT_HEADER = new PcepObjectHeader(ERROR_OBJ_CLASS,
ERROR_OBJ_TYPE, PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED,
ERROR_OBJ_MINIMUM_LENGTH);
private PcepObjectHeader errorObjHeader;
private byte yErrorType;
private byte yErrorValue;
private LinkedList<PcepValueType> llOptionalTlv; // Optional TLV
/**
* Constructor to initialize variables.
*
* @param errorObjHeader ERROR Object header
* @param yErrorType Error Type
* @param yErrorValue Error Value
* @param llOptionalTlv list of optional TLV
*/
public PcepErrorObjectVer1(PcepObjectHeader errorObjHeader, byte yErrorType, byte yErrorValue,
LinkedList<PcepValueType> llOptionalTlv) {
this.errorObjHeader = errorObjHeader;
this.yErrorType = yErrorType;
this.yErrorValue = yErrorValue;
this.llOptionalTlv = llOptionalTlv;
}
/**
* sets Object Header.
*
* @param obj Error-Object header
*/
public void setLspObjHeader(PcepObjectHeader obj) {
this.errorObjHeader = obj;
}
@Override
public void setErrorType(byte yErrorType) {
this.yErrorType = yErrorType;
}
@Override
public void setErrorValue(byte yErrorValue) {
this.yErrorValue = yErrorValue;
}
/**
* returns object header.
*
* @return errorObjHeader Error-Object header
*/
public PcepObjectHeader getErrorObjHeader() {
return this.errorObjHeader;
}
@Override
public int getErrorType() {
return this.yErrorType;
}
@Override
public byte getErrorValue() {
return this.yErrorValue;
}
@Override
public LinkedList<PcepValueType> getOptionalTlv() {
return this.llOptionalTlv;
}
@Override
public void setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) {
this.llOptionalTlv = llOptionalTlv;
}
/**
* Reads from channel buffer and returns object of PcepErrorObject.
*
* @param cb of channel buffer.
* @return object of PCEP-ERROR-OBJECT
*/
public static PcepErrorObject read(ChannelBuffer cb) {
PcepObjectHeader errorObjHeader;
byte yErrorType;
byte yErrorValue;
LinkedList<PcepValueType> llOptionalTlv;
errorObjHeader = PcepObjectHeader.read(cb);
//take only ErrorObject buffer.
ChannelBuffer tempCb = cb.readBytes(errorObjHeader.getObjLen() - OBJECT_HEADER_LENGTH);
tempCb.readByte(); //ignore Reserved
tempCb.readByte(); //ignore Flags
yErrorType = tempCb.readByte();
yErrorValue = tempCb.readByte();
llOptionalTlv = parseOptionalTlv(tempCb);
return new PcepErrorObjectVer1(errorObjHeader, yErrorType, yErrorValue, llOptionalTlv);
}
/**
* returns Linked list of optional tlvs.
*
* @param cb channel buffer.
* @return Linked list of optional tlvs
*/
protected static LinkedList<PcepValueType> parseOptionalTlv(ChannelBuffer cb) {
LinkedList<PcepValueType> llOutOptionalTlv = new LinkedList<PcepValueType>();
byte[] yTemp = new byte[cb.readableBytes()];
cb.readBytes(yTemp);
return llOutOptionalTlv;
}
@Override
public int write(ChannelBuffer cb) throws PcepParseException {
//write Object header
int objStartIndex = cb.writerIndex();
int objLenIndex = errorObjHeader.write(cb);
if (objLenIndex <= 0) {
throw new PcepParseException("While writing Error Object Header.");
}
//write Reserved
cb.writeByte(0);
//write Flags
cb.writeByte(0);
//write ErrorType and ErrorValue
cb.writeByte(this.yErrorType);
cb.writeByte(this.yErrorValue);
// Add optional TLV
packOptionalTlv(cb);
//Update object length now
int length = cb.writerIndex() - objStartIndex;
//will be helpful during print().
errorObjHeader.setObjLen((short) length);
// As per RFC the length of object should be
// multiples of 4
int pad = length % 4;
if (pad != 0) {
pad = 4 - pad;
for (int i = 0; i < pad; i++) {
cb.writeByte((byte) 0);
}
length = length + pad;
}
cb.setShort(objLenIndex, (short) length);
return length;
}
/**
* Pack the Optional tlvs.
*
* @param cb channel buffer.
* @return writer index.
*/
protected int packOptionalTlv(ChannelBuffer cb) {
ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator();
int startIndex = cb.writerIndex();
while (listIterator.hasNext()) {
PcepValueType tlv = listIterator.next();
if (null == tlv) {
log.debug("TLV is null from OptionalTlv list");
continue;
}
tlv.write(cb);
}
return cb.writerIndex() - startIndex;
}
/**
* Builder class for PCEP error object.
*/
public static class Builder implements PcepErrorObject.Builder {
private boolean bIsHeaderSet = false;
private PcepObjectHeader errorObjHeader;
private byte yErrorType;
private byte yErrorValue;
private boolean bIsPFlagSet = false;
private boolean bPFlag;
private boolean bIsIFlagSet = false;
private boolean bIFlag;
private LinkedList<PcepValueType> llOptionalTlv = new LinkedList<PcepValueType>();
@Override
public PcepErrorObject build() {
PcepObjectHeader errorObjHeader = this.bIsHeaderSet ? this.errorObjHeader : DEFAULT_ERROR_OBJECT_HEADER;
if (bIsPFlagSet) {
errorObjHeader.setPFlag(bPFlag);
}
if (bIsIFlagSet) {
errorObjHeader.setIFlag(bIFlag);
}
return new PcepErrorObjectVer1(errorObjHeader, yErrorType, yErrorValue, llOptionalTlv);
}
@Override
public PcepObjectHeader getErrorObjHeader() {
return this.errorObjHeader;
}
@Override
public Builder setErrorObjHeader(PcepObjectHeader obj) {
this.errorObjHeader = obj;
this.bIsHeaderSet = true;
return this;
}
@Override
public int getErrorType() {
return this.yErrorType;
}
@Override
public Builder setErrorType(byte value) {
this.yErrorType = value;
return this;
}
@Override
public byte getErrorValue() {
return this.yErrorValue;
}
@Override
public Builder setErrorValue(byte value) {
this.yErrorValue = value;
return this;
}
@Override
public Builder setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) {
this.llOptionalTlv = llOptionalTlv;
return this;
}
@Override
public LinkedList<PcepValueType> getOptionalTlv() {
return this.llOptionalTlv;
}
@Override
public Builder setPFlag(boolean value) {
this.bPFlag = value;
this.bIsPFlagSet = true;
return this;
}
@Override
public Builder setIFlag(boolean value) {
this.bIFlag = value;
this.bIsIFlagSet = true;
return this;
}
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass()).add("ObjectHeader", errorObjHeader).add("ErrorType", yErrorType)
.add("ErrorValue", yErrorValue).add("OptionalTlv", llOptionalTlv).toString();
}
}
/*
* Copyright 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.protocol.ver1;
import java.util.LinkedList;
import java.util.ListIterator;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.pcepio.exceptions.PcepParseException;
import org.onosproject.pcepio.protocol.PcepError;
import org.onosproject.pcepio.protocol.PcepErrorObject;
import org.onosproject.pcepio.protocol.PcepRPObject;
import org.onosproject.pcepio.protocol.PcepTEObject;
import org.onosproject.pcepio.types.PcepObjectHeader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;
/**
* Provides PcepError list which contains RP or TE objects.
* Reference:PCEP Extension for Transporting TE Data draft-dhodylee-pce-pcep-te-data-extn-02.
*/
public class PcepErrorVer1 implements PcepError {
/*
<error>::=[<request-id-list> | <te-id-list>]
<error-obj-list>
<request-id-list>::=<RP>[<request-id-list>]
<te-id-list>::=<TE>[<te-id-list>]
*/
protected static final Logger log = LoggerFactory.getLogger(PcepErrorVer1.class);
private boolean isErroInfoSet;
//PcepErrorObject list
private LinkedList<PcepErrorObject> llErrObjList;
//PcepRPObject list
private LinkedList<PcepRPObject> llRPObjList;
//PcepTEObject list
private LinkedList<PcepTEObject> llTEObjList;
private boolean isTEObjListSet;
public static final int OBJECT_HEADER_LENGTH = 4;
/**
* Constructor to initialize variable.
*/
public PcepErrorVer1() {
this.llRPObjList = null;
this.llTEObjList = null;
this.llErrObjList = null;
}
/**
* Constructor to initialize variable.
*
* @param llRPObjList list of PcepRPObject
* @param llTEObjList list of PcepTEObject
* @param llErrObjListObjList list of PcepErrorObject
*/
public PcepErrorVer1(LinkedList<PcepRPObject> llRPObjList, LinkedList<PcepTEObject> llTEObjList,
LinkedList<PcepErrorObject> llErrObjListObjList) {
this.llRPObjList = llRPObjList;
this.llTEObjList = llTEObjList;
this.llErrObjList = llErrObjListObjList;
}
/**
* Constructor to initialize PcepError.
*
* @param llErrObjList list of PcepErrorObject
*/
public PcepErrorVer1(LinkedList<PcepErrorObject> llErrObjList) {
this.llRPObjList = null;
this.llTEObjList = null;
this.llErrObjList = llErrObjList;
}
@Override
public LinkedList<PcepRPObject> getRPObjList() {
return this.llRPObjList;
}
@Override
public LinkedList<PcepTEObject> getTEObjList() {
return this.llTEObjList;
}
@Override
public LinkedList<PcepErrorObject> getErrorObjList() {
return this.llErrObjList;
}
/**
* Parse RP List from the channel buffer.
*
* @throws PcepParseException if mandatory fields are missing
* @param cb of type channel buffer
*/
public void parseRPList(ChannelBuffer cb) throws PcepParseException {
byte yObjClass;
byte yObjType;
llRPObjList = new LinkedList<PcepRPObject>();
// caller should verify for RP object
if (cb.readableBytes() < OBJECT_HEADER_LENGTH) {
log.debug("Unable to find RP Object");
return;
}
cb.markReaderIndex();
PcepObjectHeader tempObjHeader = PcepObjectHeader.read(cb);
cb.resetReaderIndex();
yObjClass = tempObjHeader.getObjClass();
yObjType = tempObjHeader.getObjType();
PcepRPObject rpObj;
while ((yObjClass == PcepRPObjectVer1.RP_OBJ_CLASS) && (yObjType == PcepRPObjectVer1.RP_OBJ_TYPE)) {
rpObj = PcepRPObjectVer1.read(cb);
llRPObjList.add(rpObj);
if (cb.readableBytes() > OBJECT_HEADER_LENGTH) {
cb.markReaderIndex();
tempObjHeader = PcepObjectHeader.read(cb);
cb.resetReaderIndex();
yObjClass = tempObjHeader.getObjClass();
yObjType = tempObjHeader.getObjType();
} else {
break;
}
}
}
/**
* Parse TE List from the channel buffer.
*
* @param cb of type channel buffer
* @throws PcepParseException if mandatory fields are missing
*/
public void parseTEList(ChannelBuffer cb) throws PcepParseException {
byte yObjClass;
byte yObjType;
llTEObjList = new LinkedList<PcepTEObject>();
// caller should verify for TE object
if (cb.readableBytes() < OBJECT_HEADER_LENGTH) {
log.debug("Unable to find TE Object");
return;
}
cb.markReaderIndex();
PcepObjectHeader tempObjHeader = PcepObjectHeader.read(cb);
cb.resetReaderIndex();
yObjClass = tempObjHeader.getObjClass();
yObjType = tempObjHeader.getObjType();
PcepTEObject teObj;
while ((yObjClass == PcepTEObjectVer1.TE_OBJ_CLASS) && ((yObjType == PcepTEObjectVer1.TE_OBJ_TYPE_NODE_VALUE)
|| (yObjType == PcepTEObjectVer1.TE_OBJ_TYPE_LINK_VALUE))) {
teObj = PcepTEObjectVer1.read(cb);
llTEObjList.add(teObj);
if (cb.readableBytes() > OBJECT_HEADER_LENGTH) {
cb.markReaderIndex();
tempObjHeader = PcepObjectHeader.read(cb);
cb.resetReaderIndex();
yObjClass = tempObjHeader.getObjClass();
yObjType = tempObjHeader.getObjType();
} else {
break;
}
}
}
/**
* parseErrObjList from the channel buffer.
*
* @param cb of type channel buffer
* @throws PcepParseException if mandatory fields are missing
*/
public void parseErrObjList(ChannelBuffer cb) throws PcepParseException {
byte yObjClass;
byte yObjType;
boolean bIsErrorObjFound = false;
llErrObjList = new LinkedList<PcepErrorObject>();
// caller should verify for RP object
if (cb.readableBytes() < OBJECT_HEADER_LENGTH) {
throw new PcepParseException("Unable to find PCEP-ERROR Object");
}
cb.markReaderIndex();
PcepObjectHeader tempObjHeader = PcepObjectHeader.read(cb);
cb.resetReaderIndex();
yObjClass = tempObjHeader.getObjClass();
yObjType = tempObjHeader.getObjType();
PcepErrorObject errorObject;
while ((yObjClass == PcepErrorObjectVer1.ERROR_OBJ_CLASS) && (yObjType == PcepErrorObjectVer1.ERROR_OBJ_TYPE)) {
errorObject = PcepErrorObjectVer1.read(cb);
llErrObjList.add(errorObject);
bIsErrorObjFound = true;
if (cb.readableBytes() > OBJECT_HEADER_LENGTH) {
cb.markReaderIndex();
tempObjHeader = PcepObjectHeader.read(cb);
cb.resetReaderIndex();
yObjClass = tempObjHeader.getObjClass();
yObjType = tempObjHeader.getObjType();
} else {
break;
}
}
if (!bIsErrorObjFound) {
throw new PcepParseException("At least one PCEP-ERROR Object should be present.");
}
}
/**
* Reads the byte stream of PcepError from channel buffer.
*
* @param cb of type channel buffer
* @return PcepError error part of PCEP-ERROR
* @throws PcepParseException if mandatory fields are missing
*/
public static PcepErrorVer1 read(ChannelBuffer cb) throws PcepParseException {
if (cb.readableBytes() < OBJECT_HEADER_LENGTH) {
throw new PcepParseException("Unknown Object");
}
PcepErrorVer1 pcepError = new PcepErrorVer1();
// check whether any PCEP Error Info is present
cb.markReaderIndex();
PcepObjectHeader tempObjHeader = PcepObjectHeader.read(cb);
cb.resetReaderIndex();
byte yObjClass = tempObjHeader.getObjClass();
//If RPlist present then store it.RPList and TEList are optional
if (yObjClass == PcepRPObjectVer1.RP_OBJ_CLASS) {
log.debug("RP_LIST");
pcepError.parseRPList(cb);
yObjClass = checkNextObject(cb);
} else if (yObjClass == PcepTEObjectVer1.TE_OBJ_CLASS) {
log.debug("TE_LIST");
pcepError.parseTEList(cb);
yObjClass = checkNextObject(cb);
}
if (yObjClass == PcepErrorObjectVer1.ERROR_OBJ_CLASS) {
log.debug("PCEP-ERROR obj list");
pcepError.parseErrObjList(cb);
yObjClass = checkNextObject(cb);
}
return pcepError;
}
/**
* Checks Next Object.
*
* @param cb of type channel buffer.
* @return object type class.
*/
private static byte checkNextObject(ChannelBuffer cb) {
if (cb.readableBytes() < OBJECT_HEADER_LENGTH) {
return 0;
}
cb.markReaderIndex();
PcepObjectHeader tempObjHeader = PcepObjectHeader.read(cb);
cb.resetReaderIndex();
return tempObjHeader.getObjClass();
}
/**
* Writes the byte stream of PCEP error to the channel buffer.
*
* @param cb of type channel buffer
* @return object length index
* @throws PcepParseException if mandatory fields are missing
*/
@Override
public int write(ChannelBuffer cb) throws PcepParseException {
int iLenStartIndex = cb.writerIndex();
// RPlist is optional
if (this.isErroInfoSet) {
ListIterator<PcepRPObject> rpObjlistIterator = this.llRPObjList.listIterator();
while (rpObjlistIterator.hasNext()) {
rpObjlistIterator.next().write(cb);
}
}
// TElist is optional
if (this.isTEObjListSet) {
ListIterator<PcepTEObject> teObjlistIterator = this.llTEObjList.listIterator();
while (teObjlistIterator.hasNext()) {
teObjlistIterator.next().write(cb);
}
}
//ErrList is mandatory
ListIterator<PcepErrorObject> errlistIterator = this.llErrObjList.listIterator();
while (errlistIterator.hasNext()) {
errlistIterator.next().write(cb);
}
return cb.writerIndex() - iLenStartIndex;
}
/**
* Builder for error part of PCEP-ERROR.
*/
public static class Builder implements PcepError.Builder {
private LinkedList<PcepRPObject> llRPObjList;
private LinkedList<PcepTEObject> llTEObjList;
private LinkedList<PcepErrorObject> llErrObjList;
@Override
public PcepError build() {
return new PcepErrorVer1(llRPObjList, llTEObjList, llErrObjList);
}
@Override
public LinkedList<PcepRPObject> getRPObjList() {
return this.llRPObjList;
}
@Override
public Builder setRPObjList(LinkedList<PcepRPObject> llRPObjList) {
this.llRPObjList = llRPObjList;
return this;
}
@Override
public LinkedList<PcepTEObject> getTEObjList() {
return this.llTEObjList;
}
@Override
public Builder setTEObjList(LinkedList<PcepTEObject> llTEObjList) {
this.llTEObjList = llTEObjList;
return this;
}
@Override
public LinkedList<PcepErrorObject> getErrorObjList() {
return this.llErrObjList;
}
@Override
public Builder setErrorObjList(LinkedList<PcepErrorObject> llErrObjList) {
this.llErrObjList = llErrObjList;
return this;
}
}
@Override
public void setRPObjList(LinkedList<PcepRPObject> llRPObjList) {
this.llRPObjList = llRPObjList;
}
@Override
public void setTEObjList(LinkedList<PcepTEObject> llTEObjList) {
this.llTEObjList = llTEObjList;
}
@Override
public void setErrorObjList(LinkedList<PcepErrorObject> llErrObjList) {
this.llErrObjList = llErrObjList;
}
@Override
public String toString() {
ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass());
//RP Object list is optional
if (null != llRPObjList) {
toStrHelper.add("RpObjectList", llRPObjList);
}
//TE Object list is optional
if (null != llTEObjList) {
toStrHelper.add("TeObjectList", llTEObjList);
}
//Error Object List is mandatory
return toStrHelper.add("ErrorObjectList", llErrObjList).toString();
}
}
/*
* Copyright 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.protocol.ver1;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.pcepio.exceptions.PcepParseException;
import org.onosproject.pcepio.protocol.PcepMessageReader;
import org.onosproject.pcepio.protocol.PcepMessageWriter;
import org.onosproject.pcepio.protocol.PcepOpenMsg;
import org.onosproject.pcepio.protocol.PcepOpenObject;
import org.onosproject.pcepio.protocol.PcepType;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.onosproject.pcepio.types.PcepErrorDetailInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
public class PcepOpenMsgVer1 implements PcepOpenMsg {
/*
* <Open Message>::= <Common Header> <OPEN>
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Ver | Flags | Message-Type | Message-Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Object-Class | OT |Res|P|I| Object Length (bytes) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Ver | Flags | Keepalive | DeadTimer | SID |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
// Optional TLVs //
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
protected static final Logger log = LoggerFactory.getLogger(PcepOpenMsgVer1.class);
public static final byte PACKET_VERSION = 1;
public static final int PACKET_MINIMUM_LENGTH = 12;
public static final PcepType MSG_TYPE = PcepType.OPEN;
private PcepOpenObject pcepOpenObj;
public static final PcepOpenMsgVer1.Reader READER = new Reader();
/**
* Constructor to initialize PcepOpenObject.
*
* @param pcepOpenObj PCEP-OPEN-OBJECT
*/
public PcepOpenMsgVer1(PcepOpenObject pcepOpenObj) {
this.pcepOpenObj = pcepOpenObj;
}
@Override
public PcepOpenObject getPcepOpenObject() {
return this.pcepOpenObj;
}
@Override
public void setPcepOpenObject(PcepOpenObject pcepOpenObj) {
this.pcepOpenObj = pcepOpenObj;
}
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
@Override
public PcepType getType() {
return MSG_TYPE;
}
public static class Reader implements PcepMessageReader<PcepOpenMsg> {
@Override
public PcepOpenMsg readFrom(ChannelBuffer cb) throws PcepParseException {
if (cb.readableBytes() < PACKET_MINIMUM_LENGTH) {
throw new PcepParseException("Packet size is less than the minimum length.");
}
byte version = cb.readByte();
version = (byte) (version >> PcepMessageVer1.SHIFT_FLAG);
if (version != PACKET_VERSION) {
log.error("[readFrom] Invalid version: " + version);
throw new PcepParseException(PcepErrorDetailInfo.ERROR_TYPE_1, PcepErrorDetailInfo.ERROR_VALUE_1);
}
// fixed value property type == 1
byte type = cb.readByte();
if (type != MSG_TYPE.getType()) {
log.error("[readFrom] Unexpected type: " + type);
throw new PcepParseException(PcepErrorDetailInfo.ERROR_TYPE_1, PcepErrorDetailInfo.ERROR_VALUE_1);
}
int length = cb.readShort();
if (length < PACKET_MINIMUM_LENGTH) {
throw new PcepParseException(
"Wrong length: Expected to be >= " + PACKET_MINIMUM_LENGTH + ", was: " + length);
}
return new PcepOpenMsgVer1(PcepOpenObjectVer1.read(cb));
}
}
/**
* Builder class for PCEP open message.
*/
static class Builder implements PcepOpenMsg.Builder {
private PcepOpenObject pcepOpenObj;
@Override
public PcepOpenMsg build() throws PcepParseException {
if (!(pcepOpenObj instanceof PcepOpenObjectVer1)) {
throw new NullPointerException("PcepOpenObject is null.");
}
return new PcepOpenMsgVer1(pcepOpenObj);
}
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
@Override
public PcepType getType() {
return PcepType.OPEN;
}
@Override
public PcepOpenObject getPcepOpenObj() {
return this.pcepOpenObj;
}
@Override
public Builder setPcepOpenObj(PcepOpenObject obj) {
this.pcepOpenObj = obj;
return this;
}
}
@Override
public void writeTo(ChannelBuffer cb) throws PcepParseException {
WRITER.write(cb, this);
}
public static final Writer WRITER = new Writer();
public static class Writer implements PcepMessageWriter<PcepOpenMsgVer1> {
@Override
public void write(ChannelBuffer cb, PcepOpenMsgVer1 message) throws PcepParseException {
int startIndex = cb.writerIndex();
// first 3 bits set to version
cb.writeByte((byte) (PACKET_VERSION << PcepMessageVer1.SHIFT_FLAG));
// message type
cb.writeByte(MSG_TYPE.getType());
// length is length of variable message, will be updated at the end
// Store the position of message
// length in buffer
int msgLenIndex = cb.writerIndex();
cb.writeShort(0);
message.getPcepOpenObject().write(cb);
// update message length field
int iLength = cb.writerIndex() - startIndex;
cb.setShort(msgLenIndex, (short) iLength);
}
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass()).add("OpenObject", pcepOpenObj).toString();
}
}
/*
* Copyright 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.protocol.ver1;
import java.util.LinkedList;
import java.util.ListIterator;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.pcepio.exceptions.PcepParseException;
import org.onosproject.pcepio.protocol.PcepOpenObject;
import org.onosproject.pcepio.protocol.PcepType;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.onosproject.pcepio.types.GmplsCapabilityTlv;
import org.onosproject.pcepio.types.PceccCapabilityTlv;
import org.onosproject.pcepio.types.PcepLabelDbVerTlv;
import org.onosproject.pcepio.types.PcepObjectHeader;
import org.onosproject.pcepio.types.PcepValueType;
import org.onosproject.pcepio.types.StatefulLspDbVerTlv;
import org.onosproject.pcepio.types.StatefulPceCapabilityTlv;
import org.onosproject.pcepio.types.TedCapabilityTlv;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
/*
message format.
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Object-Class | OT |Res|P|I| Object Length (bytes) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Ver | Flags | Keepalive | DeadTimer | SID |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
// Optional TLVs //
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
The OPEN Object format
*/
public class PcepOpenObjectVer1 implements PcepOpenObject {
protected static final Logger log = LoggerFactory.getLogger(PcepOpenObjectVer1.class);
public static final PcepType MSG_TYPE = PcepType.OPEN;
public static final byte OPEN_OBJECT_VERSION = 1;
public static final byte OPEN_OBJ_TYPE = 1;
public static final byte OPEN_OBJ_CLASS = 1;
public static final byte DEFAULT_KEEPALIVE_TIME = 30;
public static final byte DEFAULT_DEAD_TIME = 120;
public static final short OPEN_OBJ_MINIMUM_LENGTH = 8;
public static final int DEFAULT_GMPLS_CAPABILITY_TLV_IVALUE = 0X0;
public static final int DEFAULT_STATEFUL_PCE_CAPABILITY_TLV_IVALUE = 0xf;
public static final int DEFAULT_PCECC_CAPABILITY_TLV_IVALUE = 0x7;
public static final int DEFAULT_PCEP_LABEL_DB_VER_TLV_IVALUE = 0X0;
public static final PcepObjectHeader DEFAULT_OPEN_HEADER = new PcepObjectHeader(OPEN_OBJ_CLASS, OPEN_OBJ_TYPE,
PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, OPEN_OBJ_MINIMUM_LENGTH);
private PcepObjectHeader openObjHeader;
private byte keepAliveTime;
private byte deadTime;
private byte sessionId;
private LinkedList<PcepValueType> llOptionalTlv;
/**
* Default constructor.
*/
public PcepOpenObjectVer1() {
this.openObjHeader = null;
this.keepAliveTime = 0;
this.deadTime = 0;
this.sessionId = 0;
this.llOptionalTlv = null;
}
/**
* Constructor to initialize all member variables.
*
* @param openObjHeader Open Object Header
* @param keepAliveTime Keepalive timer value
* @param deadTime Dead timer value
* @param sessionID session id
* @param llOptionalTlv Optional TLV
*/
public PcepOpenObjectVer1(PcepObjectHeader openObjHeader, byte keepAliveTime, byte deadTime, byte sessionID,
LinkedList<PcepValueType> llOptionalTlv) {
this.openObjHeader = openObjHeader;
this.keepAliveTime = keepAliveTime;
this.deadTime = deadTime;
this.sessionId = sessionID;
this.llOptionalTlv = llOptionalTlv;
}
@Override
public PcepObjectHeader getOpenObjHeader() {
return this.openObjHeader;
}
@Override
public void setOpenObjHeader(PcepObjectHeader obj) {
this.openObjHeader = obj;
}
@Override
public byte getKeepAliveTime() {
return this.keepAliveTime;
}
@Override
public void setKeepAliveTime(byte value) {
this.keepAliveTime = value;
}
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
@Override
public byte getDeadTime() {
return this.deadTime;
}
@Override
public void setDeadTime(byte value) {
this.deadTime = value;
}
@Override
public byte getSessionId() {
return this.sessionId;
}
@Override
public void setSessionId(byte value) {
this.sessionId = value;
}
@Override
public LinkedList<PcepValueType> getOptionalTlv() {
return this.llOptionalTlv;
}
@Override
public void setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) {
this.llOptionalTlv = llOptionalTlv;
}
/**
* Reads from channel buffer and returns object of PcepOpenObject.
*
* @param cb of type channel buffer
* @return object of PcepOpenObject
* @throws PcepParseException if mandatory fields are missing
*/
public static PcepOpenObject read(ChannelBuffer cb) throws PcepParseException {
PcepObjectHeader openObjHeader;
byte version;
byte keepAliveTime;
byte deadTime;
byte sessionID;
LinkedList<PcepValueType> llOptionalTlv;
openObjHeader = PcepObjectHeader.read(cb);
version = cb.readByte();
version = (byte) (version >> PcepMessageVer1.SHIFT_FLAG);
if (version != OPEN_OBJECT_VERSION) {
throw new PcepParseException("Wrong version: Expected=PcepVersion.PCEP_1(1), got=" + version);
}
/* Keepalive */
keepAliveTime = cb.readByte();
/* DeadTimer */
deadTime = cb.readByte();
/* SID */
sessionID = cb.readByte();
// Optional TLV
llOptionalTlv = parseOptionalTlv(cb);
return new PcepOpenObjectVer1(openObjHeader, keepAliveTime, deadTime, sessionID, llOptionalTlv);
}
/**
* Returns linkedlist of optional tlvs.
*
* @param cb of type channel buffer
* @return llOptionalTlv Optional TLV
* @throws PcepParseException if mandatory fields are missing
*/
protected static LinkedList<PcepValueType> parseOptionalTlv(ChannelBuffer cb) throws PcepParseException {
LinkedList<PcepValueType> llOptionalTlv;
llOptionalTlv = new LinkedList<PcepValueType>();
while (4 <= cb.readableBytes()) {
PcepValueType tlv;
short hType = cb.readShort();
short hLength = cb.readShort();
switch (hType) {
case GmplsCapabilityTlv.TYPE:
log.debug("GmplsCapabilityTlv");
if (GmplsCapabilityTlv.LENGTH != hLength) {
throw new PcepParseException("Invalid length received for Gmpls_Capability_Tlv.");
}
int iValue = cb.readInt();
tlv = new GmplsCapabilityTlv(iValue);
break;
case StatefulPceCapabilityTlv.TYPE:
log.debug("StatefulPceCapabilityTlv");
if (StatefulPceCapabilityTlv.LENGTH != hLength) {
throw new PcepParseException("Invalid length received for StatefulPceCapabilityTlv.");
}
tlv = StatefulPceCapabilityTlv.read(cb);
break;
case PceccCapabilityTlv.TYPE:
log.debug("PceccCapabilityTlv");
if (PceccCapabilityTlv.LENGTH != hLength) {
throw new PcepParseException("Invalid length for PceccCapabilityTlv.");
}
iValue = cb.readInt();
tlv = new PceccCapabilityTlv(iValue);
break;
case StatefulLspDbVerTlv.TYPE:
log.debug("StatefulLspDbVerTlv");
if (StatefulLspDbVerTlv.LENGTH != hLength) {
throw new PcepParseException("Invalid length received for StatefulLspDbVerTlv.");
}
long lValue = cb.readLong();
tlv = new StatefulLspDbVerTlv(lValue);
break;
case TedCapabilityTlv.TYPE:
log.debug("TedCapabilityTlv");
if (TedCapabilityTlv.LENGTH != hLength) {
throw new PcepParseException("Invalid length received for TedCapabilityTlv.");
}
iValue = cb.readInt();
tlv = new TedCapabilityTlv(iValue);
break;
case PcepLabelDbVerTlv.TYPE:
log.debug("PcepLabelDbVerTlv");
if (PcepLabelDbVerTlv.LENGTH != hLength) {
throw new PcepParseException("Invalid length received for PcepLabelDbVerTlv.");
}
lValue = cb.readLong();
tlv = new PcepLabelDbVerTlv(lValue);
break;
default:
log.debug("Unsupported TLV: " + hType);
cb.skipBytes(hLength);
continue;
}
llOptionalTlv.add(tlv);
}
if (0 < cb.readableBytes()) {
throw new PcepParseException("Optional Tlv parsing error. Extra bytes received.");
}
return llOptionalTlv;
}
@Override
public int write(ChannelBuffer cb) throws PcepParseException {
int objStartIndex = cb.writerIndex();
//write common header
int objLenIndex = openObjHeader.write(cb);
if (objLenIndex <= 0) {
throw new PcepParseException("Unable to write Open object header.");
}
cb.writeByte((byte) (OPEN_OBJECT_VERSION << PcepMessageVer1.SHIFT_FLAG));
cb.writeByte(this.keepAliveTime);
cb.writeByte(this.deadTime);
cb.writeByte(this.sessionId);
//Pack optional TLV
packOptionalTlv(cb);
//now write OPEN Object Length
int length = cb.writerIndex() - objStartIndex;
cb.setShort(objLenIndex, (short) length);
//will be helpful during print().
this.openObjHeader.setObjLen((short) length);
return length;
}
/**
* Returns writer index.
*
* @param cb of type channel buffer.
* @return writer index
*/
protected int packOptionalTlv(ChannelBuffer cb) {
int startIndex = cb.writerIndex();
LinkedList<PcepValueType> llOptionalTlv = this.llOptionalTlv;
ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator();
while (listIterator.hasNext()) {
PcepValueType tlv = listIterator.next();
if (null == tlv) {
log.debug("TLV is null from OptionalTlv list");
continue;
}
tlv.write(cb);
// need to take care of padding
int pad = tlv.getLength() % 4;
if (0 != pad) {
pad = 4 - pad;
for (int i = 0; i < pad; ++i) {
cb.writeByte((byte) 0);
}
}
}
return cb.writerIndex() - startIndex;
}
public static class Builder implements PcepOpenObject.Builder {
// Pcep open message fields
private boolean bIsHeaderSet = false;
private PcepObjectHeader openObjHeader;
private boolean bIsKeepAliveTimeSet = false;
private byte keepAliveTime;
private boolean bIsDeadTimeSet = false;
private byte deadTime;
private boolean bIsSessionIDSet = false;
private byte sessionID;
private boolean bIsOptionalTlvSet = false;
private LinkedList<PcepValueType> llOptionalTlv = new LinkedList<PcepValueType>();
private boolean bIsPFlagSet = false;
private boolean bPFlag;
private boolean bIsIFlagSet = false;
private boolean bIFlag;
@Override
public PcepOpenObject build() throws PcepParseException {
PcepObjectHeader openObjHeader = this.bIsHeaderSet ? this.openObjHeader : DEFAULT_OPEN_HEADER;
byte keepAliveTime = this.bIsKeepAliveTimeSet ? this.keepAliveTime : DEFAULT_KEEPALIVE_TIME;
byte deadTime = this.bIsDeadTimeSet ? this.deadTime : DEFAULT_DEAD_TIME;
if (!this.bIsSessionIDSet) {
throw new PcepParseException("SessionID is not set (mandatory)");
}
if (!this.bIsOptionalTlvSet) {
//Add tlv to list
//Add GmplsCapabilityTlv
PcepValueType tlv;
int iValue = DEFAULT_GMPLS_CAPABILITY_TLV_IVALUE;
tlv = new GmplsCapabilityTlv(iValue);
this.llOptionalTlv.add(tlv);
//Add StatefulPceCapabilityTlv
iValue = DEFAULT_STATEFUL_PCE_CAPABILITY_TLV_IVALUE;
tlv = new StatefulPceCapabilityTlv(iValue);
this.llOptionalTlv.add(tlv);
}
if (bIsPFlagSet) {
openObjHeader.setPFlag(bPFlag);
}
if (bIsIFlagSet) {
openObjHeader.setIFlag(bIFlag);
}
return new PcepOpenObjectVer1(openObjHeader, keepAliveTime, deadTime, this.sessionID, this.llOptionalTlv);
}
@Override
public PcepObjectHeader getOpenObjHeader() {
return this.openObjHeader;
}
@Override
public Builder setOpenObjHeader(PcepObjectHeader obj) {
this.openObjHeader = obj;
this.bIsHeaderSet = true;
return this;
}
@Override
public byte getKeepAliveTime() {
return this.keepAliveTime;
}
@Override
public Builder setKeepAliveTime(byte value) {
this.keepAliveTime = value;
this.bIsKeepAliveTimeSet = true;
return this;
}
@Override
public byte getDeadTime() {
return this.deadTime;
}
@Override
public Builder setDeadTime(byte value) {
this.deadTime = value;
this.bIsDeadTimeSet = true;
return this;
}
@Override
public byte getSessionId() {
return this.sessionID;
}
@Override
public Builder setSessionId(byte value) {
this.sessionID = value;
this.bIsSessionIDSet = true;
return this;
}
@Override
public Builder setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) {
this.llOptionalTlv = llOptionalTlv;
this.bIsOptionalTlvSet = true;
return this;
}
@Override
public LinkedList<PcepValueType> getOptionalTlv() {
return this.llOptionalTlv;
}
@Override
public Builder setPFlag(boolean value) {
this.bPFlag = value;
this.bIsPFlagSet = true;
return this;
}
@Override
public Builder setIFlag(boolean value) {
this.bIFlag = value;
this.bIsIFlagSet = true;
return this;
}
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass()).add("ObjectHeader", openObjHeader)
.add("Keepalive", keepAliveTime).add("DeadTimer", deadTime).add("SessionId", sessionId)
.add("OptionalTlv", llOptionalTlv).toString();
}
}
/*
* Copyright 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.protocol.ver1;
import java.util.LinkedList;
import java.util.ListIterator;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.pcepio.exceptions.PcepParseException;
import org.onosproject.pcepio.protocol.PcepRPObject;
import org.onosproject.pcepio.types.PcepObjectHeader;
import org.onosproject.pcepio.types.PcepValueType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
public class PcepRPObjectVer1 implements PcepRPObject {
/*
* RP Object.
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Flags |O|B|R| Pri |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Request-ID-number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
// Optional TLVs //
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
protected static final Logger log = LoggerFactory.getLogger(PcepRPObjectVer1.class);
public static final byte RP_OBJ_TYPE = 1;
public static final byte RP_OBJ_CLASS = 2;
public static final byte RP_OBJECT_VERSION = 1;
public static final short RP_OBJ_MINIMUM_LENGTH = 12;
public static final int DEFAULT_REQUEST_ID_NUM = 0;
//Signalled , all default values to be checked.
public static final boolean DEFAULT_OFLAG = false;
public static final boolean DEFAULT_BFLAG = false;
public static final boolean DEFAULT_RFLAG = false;
public static final byte DEFAULT_PRIFLAG = 0;
public static final int OBJECT_HEADER_LENGTH = 4;
public static final int OFLAG_SHIFT_VALUE = 5;
public static final int BFLAG_SHIFT_VALUE = 4;
public static final int RFLAG_SHIFT_VALUE = 3;
public static final int OFLAG_TEMP_SHIFT_VALUE = 0x20;
public static final int BFLAG_TEMP_SHIFT_VALUE = 0x10;
public static final int RFLAG_TEMP_SHIFT_VALUE = 0x08;
public static final int PRIFLAG_TEMP_SHIFT_VALUE = 0x07;
public static final int BIT_SET = 1;
public static final int BIT_RESET = 0;
public static final int MINIMUM_COMMON_HEADER_LENGTH = 4;
public static final PcepObjectHeader DEFAULT_RP_OBJECT_HEADER = new PcepObjectHeader(RP_OBJ_CLASS, RP_OBJ_TYPE,
PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, RP_OBJ_MINIMUM_LENGTH);
private PcepObjectHeader rpObjHeader;
private int iRequestIdNum;
private boolean bOFlag;
private boolean bBFlag;
private boolean bRFlag;
private byte yPriFlag; // 3bytes
private LinkedList<PcepValueType> llOptionalTlv;
/**
* Constructor to initialize variables.
*
* @param rpObjHeader RP-OBJECT header
* @param iRequestIdNum Request-ID-number
* @param bOFlag O-flag
* @param bBFlag B-flag
* @param bRFlag R-flag
* @param yPriFlag Pri-flag
* @param llOptionalTlv linked list of Optional TLV
*/
public PcepRPObjectVer1(PcepObjectHeader rpObjHeader, int iRequestIdNum, boolean bOFlag, boolean bBFlag,
boolean bRFlag, byte yPriFlag, LinkedList<PcepValueType> llOptionalTlv) {
this.rpObjHeader = rpObjHeader;
this.iRequestIdNum = iRequestIdNum;
this.bOFlag = bOFlag;
this.bBFlag = bBFlag;
this.bRFlag = bRFlag;
this.yPriFlag = yPriFlag;
this.llOptionalTlv = llOptionalTlv;
}
/**
* Sets RP Object header.
*
* @param obj RP Object header
*/
public void setRPObjHeader(PcepObjectHeader obj) {
this.rpObjHeader = obj;
}
@Override
public void setRequestIdNum(int iRequestIdNum) {
this.iRequestIdNum = iRequestIdNum;
}
@Override
public void setOFlag(boolean bOFlag) {
this.bOFlag = bOFlag;
}
@Override
public void setBFlag(boolean bBFlag) {
this.bBFlag = bBFlag;
}
@Override
public void setRFlag(boolean bRFlag) {
this.bRFlag = bRFlag;
}
@Override
public void setPriFlag(byte yPriFlag) {
this.yPriFlag = yPriFlag;
}
/**
* Returns RP Object header.
*
* @return rpObjHeader
*/
public PcepObjectHeader getRPObjHeader() {
return this.rpObjHeader;
}
@Override
public int getRequestIdNum() {
return this.iRequestIdNum;
}
@Override
public boolean getOFlag() {
return this.bOFlag;
}
@Override
public boolean getBFlag() {
return this.bBFlag;
}
@Override
public boolean getRFlag() {
return this.bRFlag;
}
@Override
public byte getPriFlag() {
return this.yPriFlag;
}
/**
* Reads the channel buffer and returns the object of PcepRPObject.
*
* @param cb of type channel buffer
* @return the object of PcepRPObject
* @throws PcepParseException if mandatory fields are missing
*/
public static PcepRPObject read(ChannelBuffer cb) throws PcepParseException {
log.debug("read");
PcepObjectHeader rpObjHeader;
int iRequestIdNum;
boolean bOFlag;
boolean bBFlag;
boolean bRFlag;
byte yPriFlag; // 3bytes
LinkedList<PcepValueType> llOptionalTlv = new LinkedList<PcepValueType>();
rpObjHeader = PcepObjectHeader.read(cb);
//take only LspObject buffer.
ChannelBuffer tempCb = cb.readBytes(rpObjHeader.getObjLen() - OBJECT_HEADER_LENGTH);
int iTemp = tempCb.readInt();
yPriFlag = (byte) (iTemp & PRIFLAG_TEMP_SHIFT_VALUE);
bOFlag = (iTemp & OFLAG_TEMP_SHIFT_VALUE) == OFLAG_TEMP_SHIFT_VALUE ? true : false;
bBFlag = (iTemp & BFLAG_TEMP_SHIFT_VALUE) == BFLAG_TEMP_SHIFT_VALUE ? true : false;
bRFlag = (iTemp & RFLAG_TEMP_SHIFT_VALUE) == RFLAG_TEMP_SHIFT_VALUE ? true : false;
iRequestIdNum = tempCb.readInt();
// parse optional TLV
llOptionalTlv = parseOptionalTlv(tempCb);
return new PcepRPObjectVer1(rpObjHeader, iRequestIdNum, bOFlag, bBFlag, bRFlag, yPriFlag, llOptionalTlv);
}
@Override
public int write(ChannelBuffer cb) throws PcepParseException {
//write Object header
int objStartIndex = cb.writerIndex();
int objLenIndex = rpObjHeader.write(cb);
if (objLenIndex <= 0) {
throw new PcepParseException("ObjectLength Index is " + objLenIndex);
}
int iTemp;
iTemp = (yPriFlag);
iTemp = (bOFlag) ? (iTemp | OFLAG_SHIFT_VALUE) : iTemp;
iTemp = (bBFlag) ? (iTemp | BFLAG_SHIFT_VALUE) : iTemp;
iTemp = (bRFlag) ? (iTemp | RFLAG_SHIFT_VALUE) : iTemp;
cb.writeInt(iTemp);
cb.writeInt(iRequestIdNum);
// Add optional TLV
packOptionalTlv(cb);
//Update object length now
int length = cb.writerIndex() - objStartIndex;
//will be helpful during print().
rpObjHeader.setObjLen((short) length);
cb.setShort(objLenIndex, (short) length);
return cb.writerIndex();
}
/**
* Returns list of optional tlvs.
*
* @param cb of type channel buffer.
* @return llOutOptionalTlv linked list of Optional TLV
* @throws PcepParseException if mandatory fields are missing
*/
protected static LinkedList<PcepValueType> parseOptionalTlv(ChannelBuffer cb) throws PcepParseException {
LinkedList<PcepValueType> llOutOptionalTlv = new LinkedList<PcepValueType>();
//Currently no optional TLvs, will be added based on requirements.
return llOutOptionalTlv;
}
/**
* Returns optional tlvs.
*
* @param cb of type channel buffer
* @return llOptionalTlv linked list of Optional TLV
*/
protected int packOptionalTlv(ChannelBuffer cb) {
ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator();
while (listIterator.hasNext()) {
listIterator.next().write(cb);
}
return cb.writerIndex();
}
public static class Builder implements PcepRPObject.Builder {
private boolean bIsHeaderSet = false;
private boolean bIsRequestIdNumSet = false;
private boolean bIsOFlagSet = false;
private boolean bIsRFlagset = false;
private boolean bIsBFlagSet = false;
private boolean bIsPriFlagSet = false;
private PcepObjectHeader rpObjHeader;
private int requestIdNum;
private boolean bOFlag;
private boolean bBFlag;
private boolean bRFlag;
private byte yPriFlag;
private LinkedList<PcepValueType> llOptionalTlv = new LinkedList<PcepValueType>();
private boolean bIsPFlagSet = false;
private boolean bPFlag;
private boolean bIsIFlagSet = false;
private boolean bIFlag;
@Override
public PcepRPObject build() {
PcepObjectHeader lspObjHeader = this.bIsHeaderSet ? this.rpObjHeader : DEFAULT_RP_OBJECT_HEADER;
int requestIdNum = this.bIsRequestIdNumSet ? this.requestIdNum : DEFAULT_REQUEST_ID_NUM;
boolean bOFlag = this.bIsOFlagSet ? this.bOFlag : DEFAULT_OFLAG;
boolean bBFlag = this.bIsBFlagSet ? this.bBFlag : DEFAULT_BFLAG;
boolean bRFlag = this.bIsRFlagset ? this.bRFlag : DEFAULT_RFLAG;
byte yPriFlag = this.bIsPriFlagSet ? this.yPriFlag : DEFAULT_PRIFLAG;
if (bIsPFlagSet) {
lspObjHeader.setPFlag(bPFlag);
}
if (bIsIFlagSet) {
lspObjHeader.setIFlag(bIFlag);
}
return new PcepRPObjectVer1(lspObjHeader, requestIdNum, bOFlag, bBFlag, bRFlag, yPriFlag, llOptionalTlv);
}
@Override
public PcepObjectHeader getRPObjHeader() {
return this.rpObjHeader;
}
@Override
public Builder setRPObjHeader(PcepObjectHeader obj) {
this.rpObjHeader = obj;
this.bIsHeaderSet = true;
return this;
}
@Override
public int getRequestIdNum() {
return this.requestIdNum;
}
@Override
public Builder setRequestIdNum(int value) {
this.requestIdNum = value;
this.bIsRequestIdNumSet = true;
return this;
}
@Override
public Builder setOFlag(boolean value) {
this.bOFlag = value;
this.bIsOFlagSet = true;
return this;
}
@Override
public boolean getBFlag() {
return this.bBFlag;
}
@Override
public Builder setBFlag(boolean value) {
this.bBFlag = value;
this.bIsBFlagSet = true;
return this;
}
@Override
public boolean getRFlag() {
return this.bRFlag;
}
@Override
public Builder setRFlag(boolean value) {
this.bRFlag = value;
this.bIsRFlagset = true;
return this;
}
@Override
public byte getPriFlag() {
return this.yPriFlag;
}
@Override
public Builder setPriFlag(byte value) {
this.yPriFlag = value;
this.bIsPriFlagSet = true;
return this;
}
@Override
public Builder setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) {
this.llOptionalTlv = llOptionalTlv;
return this;
}
@Override
public LinkedList<PcepValueType> getOptionalTlv() {
return this.llOptionalTlv;
}
@Override
public Builder setPFlag(boolean value) {
this.bPFlag = value;
this.bIsPFlagSet = true;
return this;
}
@Override
public Builder setIFlag(boolean value) {
this.bIFlag = value;
this.bIsIFlagSet = true;
return this;
}
@Override
public boolean getOFlag() {
return this.bOFlag;
}
}
@Override
public LinkedList<PcepValueType> getOptionalTlv() {
return this.llOptionalTlv;
}
@Override
public void setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) {
this.llOptionalTlv = llOptionalTlv;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass()).add("ObjectHeader", rpObjHeader).add("OFlag", (bOFlag) ? 1 : 0)
.add("BFlag", (bBFlag) ? 1 : 0).add("RFlag", (bRFlag) ? 1 : 0).add("PriFlag", yPriFlag)
.add("RequestIdNumber", iRequestIdNum).add("OptionalTlv", llOptionalTlv).toString();
}
}
/*
* Copyright 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.protocol.ver1;
import java.util.LinkedList;
import java.util.ListIterator;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.pcepio.exceptions.PcepParseException;
import org.onosproject.pcepio.protocol.PcepTEObject;
import org.onosproject.pcepio.types.LocalTENodeDescriptorsTLV;
import org.onosproject.pcepio.types.PcepObjectHeader;
import org.onosproject.pcepio.types.PcepValueType;
import org.onosproject.pcepio.types.RemoteTENodeDescriptorsTLV;
import org.onosproject.pcepio.types.RoutingUniverseTLV;
import org.onosproject.pcepio.types.TELinkAttributesTlv;
import org.onosproject.pcepio.types.TELinkDescriptorsTLV;
import org.onosproject.pcepio.types.TENodeAttributesTlv;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
public class PcepTEObjectVer1 implements PcepTEObject {
/*
*
reference: PCEP Extension for Transporting TE Data draft-dhodylee-pce-pcep-te-data-extn-02.
TE Object-Class is [TBD6].
Two Object-Type values are defined for the TE object:
o TE Node: TE Object-Type is 1.
o TE Link: TE Object-Type is 2.
The format of the TE object body is as follows:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Protocol-ID | Flag |R|S|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| TE-ID |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// TLVs //
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
protected static final Logger log = LoggerFactory.getLogger(PcepTEObjectVer1.class);
public static final byte TE_OBJ_TYPE_NODE_VALUE = 1;
public static final byte TE_OBJ_TYPE_LINK_VALUE = 2;
public static final byte TE_OBJ_CLASS = 101; //TBD6 in RFC.
public static final byte TE_OBJECT_VERSION = 1;
// TE_OBJ_MINIMUM_LENGTH = TEObjectHeaderLen(4)+ TEObjectLen(8)
public static final short TE_OBJ_MINIMUM_LENGTH = 12;
// Signaled ,all default values to be checked.
public static final byte DEFAULT_PROTOCOL_ID = 1; //IS-IS Level 1
public static final boolean DEFAULT_R_FLAG = false;
public static final boolean DEFAULT_S_FLAG = false;
public static final int DEFAULT_TE_ID = 0;
public static final int OBJECT_HEADER_LENGTH = 4;
public static final int RIGHT_SHIFT_ONE = 1;
public static final int RIGHT_FIRST_FLAG = 0x1;
public static final int FLAG_SET_R_FLAG = 0x2;
public static final int FLAG_SET_S_FLAG = 0x1;
public static final int MINIMUM_COMMON_HEADER_LENGTH = 4;
public static final int MINIMUM_TLV_HEADER_LENGTH = 4;
public static final PcepObjectHeader DEFAULT_TE_OBJECT_HEADER = new PcepObjectHeader(TE_OBJ_CLASS,
TE_OBJ_TYPE_NODE_VALUE, PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED,
TE_OBJ_MINIMUM_LENGTH);
private PcepObjectHeader teObjHeader;
private byte yProtocolId;
// 2-flags
private boolean bRFlag;
private boolean bSFlag;
private int iTEId;
// Optional TLV
private LinkedList<PcepValueType> llOptionalTlv;
/**
* Constructor to initialize variables.
*
* @param teObjHeader TE Object header
* @param yProtocolId Protocol-ID
* @param bRFlag R-flag
* @param bSFlag S-flag
* @param iTEId TE-ID
* @param llOptionalTlv linked list of Optional TLV
*/
public PcepTEObjectVer1(PcepObjectHeader teObjHeader, byte yProtocolId, boolean bRFlag, boolean bSFlag, int iTEId,
LinkedList<PcepValueType> llOptionalTlv) {
this.teObjHeader = teObjHeader;
this.yProtocolId = yProtocolId;
this.bRFlag = bRFlag;
this.bSFlag = bSFlag;
this.iTEId = iTEId;
this.llOptionalTlv = llOptionalTlv;
}
@Override
public PcepObjectHeader getTEObjHeader() {
return this.teObjHeader;
}
@Override
public void setTEObjHeader(PcepObjectHeader obj) {
this.teObjHeader = obj;
}
@Override
public byte getProtocolId() {
return this.yProtocolId;
}
@Override
public void setProtocolId(byte yProtId) {
this.yProtocolId = yProtId;
}
@Override
public boolean getRFlag() {
return this.bRFlag;
}
@Override
public void setRFlag(boolean bRFlag) {
this.bRFlag = bRFlag;
}
@Override
public boolean getSFlag() {
return this.bSFlag;
}
@Override
public void setSFlag(boolean bSFlag) {
this.bSFlag = bSFlag;
}
@Override
public int getTEId() {
return this.iTEId;
}
@Override
public void setTEId(int iTEId) {
this.iTEId = iTEId;
}
@Override
public LinkedList<PcepValueType> getOptionalTlv() {
return this.llOptionalTlv;
}
@Override
public void setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) {
this.llOptionalTlv = llOptionalTlv;
}
/**
* Reads from the channel buffer and returns Object of PcepTEObject.
*
* @param cb of type channel buffer
* @return Object of PcepTEObject
* @throws PcepParseException if mandatory fields are missing
*/
public static PcepTEObject read(ChannelBuffer cb) throws PcepParseException {
log.debug("read");
PcepObjectHeader teObjHeader;
byte yProtocolId;
// 2-flags
boolean bRFlag;
boolean bSFlag;
int iTEId;
LinkedList<PcepValueType> llOptionalTlv;
teObjHeader = PcepObjectHeader.read(cb);
//take only TEObject buffer.
ChannelBuffer tempCb = cb.readBytes(teObjHeader.getObjLen() - OBJECT_HEADER_LENGTH);
yProtocolId = tempCb.readByte();
//ignore first two bytes of Flags
tempCb.readShort();
Integer iTemp = (int) tempCb.readByte(); //read 3rd byte Flag
bSFlag = ((iTemp & FLAG_SET_S_FLAG) == FLAG_SET_S_FLAG) ? true : false;
bRFlag = ((iTemp & FLAG_SET_R_FLAG) == FLAG_SET_R_FLAG) ? true : false;
iTEId = tempCb.readInt();
// parse optional TLV
llOptionalTlv = parseOptionalTlv(tempCb);
return new PcepTEObjectVer1(teObjHeader, yProtocolId, bRFlag, bSFlag, iTEId, llOptionalTlv);
}
@Override
public int write(ChannelBuffer cb) throws PcepParseException {
//write Object header
int objStartIndex = cb.writerIndex();
int objLenIndex = teObjHeader.write(cb);
if (objLenIndex <= 0) {
throw new PcepParseException("ObjectLength Index is " + objLenIndex);
}
//write Protocol ID
cb.writeByte(this.yProtocolId);
//write Flag
cb.writeShort(0);
byte bTemp = 0;
if (bSFlag) {
bTemp = FLAG_SET_S_FLAG;
}
if (bRFlag) {
bTemp = (byte) (bTemp | FLAG_SET_R_FLAG);
}
cb.writeByte(bTemp);
//write TEId
cb.writeInt(iTEId);
// Add optional TLV
packOptionalTlv(cb);
//Update object length now
int length = cb.writerIndex() - objStartIndex;
//will be helpful during print().
teObjHeader.setObjLen((short) length);
cb.setShort(objLenIndex, (short) length);
return cb.writerIndex();
}
/**
* Returns Linked list of PCEP Value Type.
*
* @param cb of channel buffer
* @return Linked list of PCEP Value Type
* @throws PcepParseException if mandatory fields are missing
*/
protected static LinkedList<PcepValueType> parseOptionalTlv(ChannelBuffer cb) throws PcepParseException {
LinkedList<PcepValueType> llOutOptionalTlv;
llOutOptionalTlv = new LinkedList<PcepValueType>();
while (MINIMUM_TLV_HEADER_LENGTH <= cb.readableBytes()) {
PcepValueType tlv;
short hType = cb.readShort();
short hLength = cb.readShort();
long lValue = 0;
switch (hType) {
case RoutingUniverseTLV.TYPE:
lValue = cb.readLong();
tlv = new RoutingUniverseTLV(lValue);
break;
case LocalTENodeDescriptorsTLV.TYPE:
tlv = LocalTENodeDescriptorsTLV.read(cb, hLength);
break;
case RemoteTENodeDescriptorsTLV.TYPE:
RemoteTENodeDescriptorsTLV.hLength = hLength;
tlv = RemoteTENodeDescriptorsTLV.read(cb);
break;
case TELinkDescriptorsTLV.TYPE:
tlv = TELinkDescriptorsTLV.read(cb, hLength);
break;
case TENodeAttributesTlv.TYPE:
tlv = TENodeAttributesTlv.read(cb, hLength);
break;
case TELinkAttributesTlv.TYPE:
tlv = TELinkAttributesTlv.read(cb, hLength);
break;
default:
throw new PcepParseException("Unsupported TLV type :" + hType);
}
// Check for the padding
int pad = hLength % 4;
if (0 < pad) {
pad = 4 - pad;
if (pad <= cb.readableBytes()) {
cb.skipBytes(pad);
}
}
llOutOptionalTlv.add(tlv);
}
if (0 < cb.readableBytes()) {
throw new PcepParseException("Optional Tlv parsing error. Extra bytes received.");
}
return llOutOptionalTlv;
}
/**
* Returns the writer index.
*
* @param cb of type channel buffer
* @return the writer index.
*/
protected int packOptionalTlv(ChannelBuffer cb) {
ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator();
while (listIterator.hasNext()) {
PcepValueType tlv = listIterator.next();
if (null == tlv) {
log.debug("TLV is null from OptionalTlv list");
continue;
}
tlv.write(cb);
// need to take care of padding
int pad = tlv.getLength() % 4;
if (0 != pad) {
pad = 4 - pad;
for (int i = 0; i < pad; ++i) {
cb.writeByte((byte) 0);
}
}
}
return cb.writerIndex();
}
public static class Builder implements PcepTEObject.Builder {
private boolean bIsHeaderSet = false;
private boolean bIsProtocolIdSet = false;
private boolean bIsRFlagSet = false;
private boolean bIsSFlagSet = false;
private boolean bIsTEIdSet = false;
private PcepObjectHeader teObjHeader;
private byte yProtocolId;
private boolean bRFlag;
private boolean bSFlag;
private int iTEId;
private LinkedList<PcepValueType> llOptionalTlv = new LinkedList<PcepValueType>();
private boolean bIsPFlagSet = false;
private boolean bPFlag;
private boolean bIsIFlagSet = false;
private boolean bIFlag;
@Override
public PcepTEObject build() {
PcepObjectHeader teObjHeader = this.bIsHeaderSet ? this.teObjHeader : DEFAULT_TE_OBJECT_HEADER;
byte yProtocolId = this.bIsProtocolIdSet ? this.yProtocolId : DEFAULT_PROTOCOL_ID;
boolean bRFlag = this.bIsRFlagSet ? this.bRFlag : DEFAULT_R_FLAG;
boolean bSFlag = this.bIsSFlagSet ? this.bSFlag : DEFAULT_S_FLAG;
int iTEId = this.bIsTEIdSet ? this.iTEId : DEFAULT_TE_ID;
if (bIsPFlagSet) {
teObjHeader.setPFlag(bPFlag);
}
if (bIsIFlagSet) {
teObjHeader.setIFlag(bIFlag);
}
return new PcepTEObjectVer1(teObjHeader, yProtocolId, bRFlag, bSFlag, iTEId, llOptionalTlv);
}
@Override
public PcepObjectHeader getTEObjHeader() {
return this.teObjHeader;
}
@Override
public Builder setTEObjHeader(PcepObjectHeader obj) {
this.teObjHeader = obj;
this.bIsHeaderSet = true;
return this;
}
@Override
public byte getProtocolId() {
return this.yProtocolId;
}
@Override
public Builder setProtocolId(byte yProtId) {
this.yProtocolId = yProtId;
this.bIsProtocolIdSet = true;
return this;
}
@Override
public boolean getRFlag() {
return this.bRFlag;
}
@Override
public Builder setRFlag(boolean bRFlag) {
this.bRFlag = bRFlag;
this.bIsRFlagSet = true;
return this;
}
@Override
public boolean getSFlag() {
return this.bSFlag;
}
@Override
public Builder setSFlag(boolean bSFlag) {
this.bSFlag = bSFlag;
this.bIsSFlagSet = true;
return this;
}
@Override
public int getTEId() {
return this.iTEId;
}
@Override
public Builder setTEId(int iTEId) {
this.iTEId = iTEId;
this.bIsTEIdSet = true;
return this;
}
@Override
public LinkedList<PcepValueType> getOptionalTlv() {
return this.llOptionalTlv;
}
@Override
public Builder setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) {
this.llOptionalTlv = llOptionalTlv;
return this;
}
@Override
public Builder setPFlag(boolean value) {
this.bPFlag = value;
this.bIsPFlagSet = true;
return this;
}
@Override
public Builder setIFlag(boolean value) {
this.bIFlag = value;
this.bIsIFlagSet = true;
return this;
}
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass()).add("ObjectHeader", teObjHeader).add("ProtocolId", yProtocolId)
.add("RFlag", (bRFlag) ? 1 : 0).add("SFlag", (bSFlag) ? 1 : 0).add("TeId", iTEId)
.add("OptionalTlv", llOptionalTlv).toString();
}
}
/*
* Copyright 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.types;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
/**
* Provides Administrative Group Tlv which contains value (32 Bit ).
*/
public class AdministrativeGroupTlv implements PcepValueType {
/* REFERENCE :[RFC5305]/3.1
* 0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type=[TDB33] | Length=4 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| value (32 Bit ) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
protected static final Logger log = LoggerFactory.getLogger(AdministrativeGroupTlv.class);
public static final short TYPE = 3; //TDB33
public static final short LENGTH = 4;
private final int rawValue;
/**
* Constructor to initialize rawValue.
*
* @param rawValue of Administrative-Group-Tlv.
*/
public AdministrativeGroupTlv(int rawValue) {
this.rawValue = rawValue;
}
/**
* Returns newly created AdministrativeGroupTlv object.
*
* @param raw value.
* @return object of Administrative-Group-Tlv
*/
public static AdministrativeGroupTlv of(final int raw) {
return new AdministrativeGroupTlv(raw);
}
/**
* Returns raw value.
*
* @return rawValue raw value
*/
public int getInt() {
return rawValue;
}
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
@Override
public short getType() {
return TYPE;
}
@Override
public short getLength() {
return LENGTH;
}
@Override
public int hashCode() {
return Objects.hash(rawValue);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof AdministrativeGroupTlv) {
AdministrativeGroupTlv other = (AdministrativeGroupTlv) obj;
return Objects.equals(rawValue, other.rawValue);
}
return false;
}
@Override
public int write(ChannelBuffer c) {
int iLenStartIndex = c.writerIndex();
c.writeShort(TYPE);
c.writeShort(LENGTH);
c.writeInt(rawValue);
return c.writerIndex() - iLenStartIndex;
}
/**
* Reads the channel buffer and returns object of Administrative-Group-Tlv.
*
* @param c input channel buffer
* @return object of Administrative-Group-Tlv
*/
public static AdministrativeGroupTlv read(ChannelBuffer c) {
return AdministrativeGroupTlv.of(c.readInt());
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH).add("Value", rawValue)
.toString();
}
}
/*
* Copyright 2014 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.types;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
/**
* Provides BGP LS identifier which contains opaque value (32 Bit ID).
*/
public class BGPLSidentifierTlv implements PcepValueType {
/* Reference :draft-ietf-idr-ls-distribution-10
* 0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type=[TBD11] | Length=4 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| opaque value (32 Bit ID). |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
protected static final Logger log = LoggerFactory.getLogger(BGPLSidentifierTlv.class);
public static final short TYPE = 17; //TODD:change this TBD11
public static final short LENGTH = 4;
private final int rawValue;
/**
* constructor to initialize rawValue.
*
* @param rawValue BGP LS identifier Tlv
*/
public BGPLSidentifierTlv(int rawValue) {
this.rawValue = rawValue;
}
/**
* Returns newly created BGPLSidentifierTlv object.
*
* @param raw value
* @return object of BGPLSidentifierTlv
*/
public static BGPLSidentifierTlv of(final int raw) {
return new BGPLSidentifierTlv(raw);
}
/**
* Returns opaque value.
*
* @return rawValue opaque value
*/
public int getInt() {
return rawValue;
}
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
@Override
public short getType() {
return TYPE;
}
@Override
public short getLength() {
return LENGTH;
}
@Override
public int hashCode() {
return Objects.hash(rawValue);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof BGPLSidentifierTlv) {
BGPLSidentifierTlv other = (BGPLSidentifierTlv) obj;
return Objects.equals(rawValue, other.rawValue);
}
return false;
}
@Override
public int write(ChannelBuffer c) {
int iLenStartIndex = c.writerIndex();
c.writeShort(TYPE);
c.writeShort(LENGTH);
c.writeInt(rawValue);
return c.writerIndex() - iLenStartIndex;
}
/**
* Reads the channel buffer and returns object of BGPLSidentifierTlv.
*
* @param c input channel buffer
* @return object of BGP LS identifier Tlv
*/
public static BGPLSidentifierTlv read(ChannelBuffer c) {
return BGPLSidentifierTlv.of(c.readInt());
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH).add("Value", rawValue)
.toString();
}
}
/*
* Copyright 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.types;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
/**
* Provides GMPLS Capability Tlv.
*/
public class GmplsCapabilityTlv implements PcepValueType {
/*
* GMPLS-CAPABILITY TLV format
* reference :draft-ietf-pce-gmpls-pcep-extensions -2.1.1
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type=14 | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Flags |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
protected static final Logger log = LoggerFactory.getLogger(GmplsCapabilityTlv.class);
public static final short TYPE = 14;
public static final short LENGTH = 4;
private final int rawValue;
/**
* Constructor to initialize raw value.
*
* @param rawValue of Gmpls-Capability-Tlv
*/
public GmplsCapabilityTlv(int rawValue) {
this.rawValue = rawValue;
}
/**
* Returns newly created GmplsCapabilityTlv object.
*
* @param raw Flags value
* @return object of Gmpls-Capability-Tlv
*/
public static GmplsCapabilityTlv of(final int raw) {
return new GmplsCapabilityTlv(raw);
}
/**
* Returns value of Flags.
*
* @return rawValue Flags
*/
public int getInt() {
return rawValue;
}
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
@Override
public short getType() {
return TYPE;
}
@Override
public short getLength() {
return LENGTH;
}
@Override
public int hashCode() {
return Objects.hash(rawValue);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof GmplsCapabilityTlv) {
GmplsCapabilityTlv other = (GmplsCapabilityTlv) obj;
return Objects.equals(rawValue, other.rawValue);
}
return false;
}
@Override
public int write(ChannelBuffer c) {
int iLenStartIndex = c.writerIndex();
c.writeShort(TYPE);
c.writeShort(LENGTH);
c.writeInt(rawValue);
return c.writerIndex() - iLenStartIndex;
}
/**
* Reads the channel buffer and returns object of Gmpls-Capability-Tlv.
*
* @param c input channel buffer
* @return object of Gmpls-Capability-Tlv
*/
public static GmplsCapabilityTlv read(ChannelBuffer c) {
return GmplsCapabilityTlv.of(c.readInt());
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH).add("Value", rawValue)
.toString();
}
}
/*
* Copyright 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.types;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;
/**
* Provides IGP Link Metric .
*/
public class IGPMetricTlv implements PcepValueType {
/* Reference :[I-D.ietf-idr-ls-distribution] /3.3.2.4
* 0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type=TDB40 | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// IGP Link Metric (variable length) //
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
protected static final Logger log = LoggerFactory.getLogger(IGPMetricTlv.class);
public static final short TYPE = 1095; //TODO:NEED TO HANDLE TDB40
private short hLength;
private final byte[] rawValue;
/**
* Constructor to initialize raw value.
*
* @param rawValue IGP Link Metric
* @param hLength length
*/
public IGPMetricTlv(byte[] rawValue, short hLength) {
this.rawValue = rawValue;
this.hLength = hLength;
}
/**
* Returns newly created IGPMetricTlv object.
*
* @param raw value of IGP Link Metric
* @param hLength length
* @return object of IGPMetricTlv
*/
public static IGPMetricTlv of(final byte[] raw, short hLength) {
return new IGPMetricTlv(raw, hLength);
}
/**
* Returns value of IGP Link Metric.
*
* @return rawValue of IGP Link Metric
*/
public byte[] getValue() {
return rawValue;
}
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
@Override
public short getType() {
return TYPE;
}
@Override
public short getLength() {
return hLength;
}
@Override
public int hashCode() {
return Objects.hash(rawValue);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof IGPMetricTlv) {
IGPMetricTlv other = (IGPMetricTlv) obj;
return Objects.equals(rawValue, other.rawValue);
}
return false;
}
@Override
public int write(ChannelBuffer c) {
int iLenStartIndex = c.writerIndex();
c.writeShort(TYPE);
c.writeShort(hLength);
c.writeBytes(rawValue);
return c.writerIndex() - iLenStartIndex;
}
/**
* Reads the channel buffer and returns object of IGPMetricTlv.
*
* @param c input channel buffer
* @param hLength length
* @return object of IGPMetricTlv
*/
public static PcepValueType read(ChannelBuffer c, short hLength) {
byte[] iIGPMetric = new byte[hLength];
c.readBytes(iIGPMetric, 0, hLength);
return new IGPMetricTlv(iIGPMetric, hLength);
}
@Override
public String toString() {
ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass());
toStrHelper.add("Type", TYPE);
toStrHelper.add("Length", hLength);
StringBuffer result = new StringBuffer();
for (byte b : rawValue) {
result.append(String.format("%02X ", b));
}
toStrHelper.add("Value", result);
return toStrHelper.toString();
}
}
/*
* Copyright 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.types;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
/**
* Provides IPv4 Interface Address .
*/
public class IPv4InterfaceAddressTlv implements PcepValueType {
/*
* reference :[RFC5305]/3.2
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type=6 | Length=4 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| IPv4 Interface Address |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
protected static final Logger log = LoggerFactory.getLogger(IPv4InterfaceAddressTlv.class);
public static final short TYPE = 6;
public static final short LENGTH = 4;
private final int rawValue;
/**
* Constructor to initialize rawValue.
*
* @param rawValue of IPv4-Interface-Address.
*/
public IPv4InterfaceAddressTlv(int rawValue) {
this.rawValue = rawValue;
}
/**
* Returns newly created IPv4InterfaceAddressTlv object.
*
* @param raw value of IPv4-Interface-Address
* @return object of IPv4-Interface-Address-Tlv
*/
public static IPv4InterfaceAddressTlv of(final int raw) {
return new IPv4InterfaceAddressTlv(raw);
}
/**
* Returns value of IPv4 Interface Address.
*
* @return rawValue IPv4 Interface Address
*/
public int getInt() {
return rawValue;
}
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
@Override
public short getType() {
return TYPE;
}
@Override
public short getLength() {
return LENGTH;
}
@Override
public int hashCode() {
return Objects.hash(rawValue);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof IPv4InterfaceAddressTlv) {
IPv4InterfaceAddressTlv other = (IPv4InterfaceAddressTlv) obj;
return Objects.equals(rawValue, other.rawValue);
}
return false;
}
@Override
public int write(ChannelBuffer c) {
int iLenStartIndex = c.writerIndex();
c.writeShort(TYPE);
c.writeShort(LENGTH);
c.writeInt(rawValue);
return c.writerIndex() - iLenStartIndex;
}
/**
* Reads the channel buffer and returns object of IPv4InterfaceAddressTlv.
*
* @param c input channel buffer
* @return object of IPv4-Interface-Address-Tlv
*/
public static IPv4InterfaceAddressTlv read(ChannelBuffer c) {
return IPv4InterfaceAddressTlv.of(c.readInt());
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH).add("Value", rawValue)
.toString();
}
}
\ No newline at end of file
/*
* Copyright 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.types;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
/**
* Provides IPv4 Neighbor Address .
*/
public class IPv4NeighborAddressTlv implements PcepValueType {
/* Reference :[RFC5305]/3.3
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type=8 | Length=4 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| IPv4 Neighbor Address |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
protected static final Logger log = LoggerFactory.getLogger(IPv4NeighborAddressTlv.class);
public static final short TYPE = 8;
public static final short LENGTH = 4;
private final int rawValue;
/**
* Constructor to initialize rawValue.
*
* @param rawValue IPv4-Neighbor-Address-Tlv
*/
public IPv4NeighborAddressTlv(int rawValue) {
log.debug("IPv4NeighborAddressTlv");
this.rawValue = rawValue;
}
/**
* Returns newly created IPv4NeighborAddressTlv object.
*
* @param raw value of IPv4-Neighbor-Address
* @return object of IPv4NeighborAddressTlv
*/
public static IPv4NeighborAddressTlv of(final int raw) {
return new IPv4NeighborAddressTlv(raw);
}
/**
* Returns value of IPv4 Neighbor Address.
*
* @return rawValue IPv4 Neighbor Address
*/
public int getInt() {
return rawValue;
}
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
@Override
public short getType() {
return TYPE;
}
@Override
public short getLength() {
return LENGTH;
}
@Override
public int hashCode() {
return Objects.hash(rawValue);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof IPv4NeighborAddressTlv) {
IPv4NeighborAddressTlv other = (IPv4NeighborAddressTlv) obj;
return Objects.equals(rawValue, other.rawValue);
}
return false;
}
@Override
public int write(ChannelBuffer c) {
int iLenStartIndex = c.writerIndex();
c.writeShort(TYPE);
c.writeShort(LENGTH);
c.writeInt(rawValue);
return c.writerIndex() - iLenStartIndex;
}
/**
* Reads the channel buffer and returns object of IPv4-Neighbor-Address-Tlv.
*
* @param c input channel buffer
* @return object of IPv4-Neighbor-Address-Tlv
*/
public static IPv4NeighborAddressTlv read(ChannelBuffer c) {
return IPv4NeighborAddressTlv.of(c.readInt());
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH).add("Value", rawValue)
.toString();
}
}
\ No newline at end of file
/*
* Copyright 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.types;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
/**
* Provides IPv4 TE Router Id Of Local Node.
*/
public class IPv4TERouterIdOfLocalNodeTlv implements PcepValueType {
/* Reference:[RFC5305]/4.3
* 0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type=[TDB25] | Length=4 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| IPv4 TE Router Id Of Local Node |
+-+-+-+-+-+-+-+-+-++-+-+-+-+-+-+-+-+-++-+-+-+-+-+-+-+-+-++-+-+-+-
*/
protected static final Logger log = LoggerFactory.getLogger(IPv4TERouterIdOfLocalNodeTlv.class);
public static final short TYPE = 134; //TDB25
public static final short LENGTH = 4;
private final int rawValue;
/**
* Constructor to initialize rawValue.
*
* @param rawValue IPv4-TE-RouterId-Of-Local-Node-Tlv
*/
public IPv4TERouterIdOfLocalNodeTlv(int rawValue) {
this.rawValue = rawValue;
}
/**
* Returns newly created IPv4TERouterIdOfLocalNodeTlv object.
*
* @param raw value of IPv4-TE-RouterId-Of-Local-Node
* @return object of IPv4TERouterIdOfLocalNodeTlv
*/
public static IPv4TERouterIdOfLocalNodeTlv of(final int raw) {
return new IPv4TERouterIdOfLocalNodeTlv(raw);
}
/**
* Returns value of IPv4 TE Router Id Of Local Node.
*
* @return rawValue IPv4 TE Router Id Of Local Node
*/
public int getInt() {
return rawValue;
}
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
@Override
public short getType() {
return TYPE;
}
@Override
public short getLength() {
return LENGTH;
}
@Override
public int hashCode() {
return Objects.hash(rawValue);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof IPv4TERouterIdOfLocalNodeTlv) {
IPv4TERouterIdOfLocalNodeTlv other = (IPv4TERouterIdOfLocalNodeTlv) obj;
return Objects.equals(rawValue, other.rawValue);
}
return false;
}
@Override
public int write(ChannelBuffer c) {
int iLenStartIndex = c.writerIndex();
c.writeShort(TYPE);
c.writeShort(LENGTH);
c.writeInt(rawValue);
return c.writerIndex() - iLenStartIndex;
}
/**
* Reads the channel buffer and returns object of IPv4TERouterIdOfLocalNodeTlv.
*
* @param c input channel buffer
* @return object of IPv4TERouterIdOfLocalNodeTlv
*/
public static IPv4TERouterIdOfLocalNodeTlv read(ChannelBuffer c) {
return IPv4TERouterIdOfLocalNodeTlv.of(c.readInt());
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH).add("Value", rawValue)
.toString();
}
}
/*
* Copyright 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.types;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
/**
* Provides IPv4 TE Router Id Of Remote Node.
*/
public class IPv4TERouterIdOfRemoteNodeTlv implements PcepValueType {
/* Reference :[RFC5305]/4.3
* 0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type=[TDB28] | Length=4 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| IPv4 TE Router Id Of Remote Node |
+-+-+-+-+-+-+-+-+-++-+-+-+-+-+-+-+-+-++-+-+-+-+-+-+-+-+-++-+-+-+-
*/
protected static final Logger log = LoggerFactory.getLogger(IPv4TERouterIdOfRemoteNodeTlv.class);
public static final short TYPE = 1340; //TDB28
public static final short LENGTH = 4;
private final int rawValue;
/**
* Constructor to initialize rawValue.
*
* @param rawValue IPv4 TE RouterId Of Remote Node Tlv
*/
public IPv4TERouterIdOfRemoteNodeTlv(int rawValue) {
log.debug("IPv4TERouterIdOfRemoteNodeTlv");
this.rawValue = rawValue;
}
/**
* Returns newly created IPv4TERouterIdOfRemoteNodeTlv object.
*
* @param raw IPv4 TE RouterId Of Remote Node
* @return object of IPv4TERouterIdOfRemoteNodeTlv
*/
public static IPv4TERouterIdOfRemoteNodeTlv of(final int raw) {
return new IPv4TERouterIdOfRemoteNodeTlv(raw);
}
/**
* Returns value of IPv4 TE Router Id Of Remote Node.
*
* @return rawValue IPv4 TE Router Id Of Remote Node
*/
public int getInt() {
return rawValue;
}
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
@Override
public short getType() {
return TYPE;
}
@Override
public short getLength() {
return LENGTH;
}
@Override
public int hashCode() {
return Objects.hash(rawValue);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof IPv4TERouterIdOfRemoteNodeTlv) {
IPv4TERouterIdOfRemoteNodeTlv other = (IPv4TERouterIdOfRemoteNodeTlv) obj;
return Objects.equals(rawValue, other.rawValue);
}
return false;
}
@Override
public int write(ChannelBuffer c) {
int iLenStartIndex = c.writerIndex();
c.writeShort(TYPE);
c.writeShort(LENGTH);
c.writeInt(rawValue);
return c.writerIndex() - iLenStartIndex;
}
/**
* Reads the channel buffer and returns object of IPv4TERouterIdOfRemoteNodeTlv.
*
* @param c input channel buffer
* @return object of IPv4TERouterIdOfRemoteNodeTlv
*/
public static IPv4TERouterIdOfRemoteNodeTlv read(ChannelBuffer c) {
return IPv4TERouterIdOfRemoteNodeTlv.of(c.readInt());
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH).add("Value", rawValue)
.toString();
}
}
/*
* Copyright 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.types;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;
/**
* Provides IPv6 Interface Address. REFERENCE :[RFC6119]/4.2.
*/
public class IPv6InterfaceAddressTlv implements PcepValueType {
protected static final Logger log = LoggerFactory.getLogger(IPv6InterfaceAddressTlv.class);
public static final short TYPE = 12; //TDB18
public static final short LENGTH = 20;
public static final byte VALUE_LENGTH = 18;
private static final byte[] NONE_VAL = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
public static final IPv6InterfaceAddressTlv NONE = new IPv6InterfaceAddressTlv(NONE_VAL);
private static final byte[] NO_MASK_VAL = {(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) 0xFF, (byte) 0xFF};
public static final IPv6InterfaceAddressTlv NO_MASK = new IPv6InterfaceAddressTlv(NO_MASK_VAL);
public static final IPv6InterfaceAddressTlv FULL_MASK = NONE;
private final byte[] rawValue;
/**
* Constructor to initialize rawValue.
*
* @param rawValue IPv6 Interface Address Tlv
*/
public IPv6InterfaceAddressTlv(byte[] rawValue) {
log.debug("IPv6InterfaceAddressTlv");
this.rawValue = rawValue;
}
/**
* Returns newly created IPv6InterfaceAddressTlv object.
*
* @param raw IPv6 Interface Address
* @return object of IPv6InterfaceAddressTlv
*/
public static IPv6InterfaceAddressTlv of(final byte[] raw) {
//check NONE_VAL
boolean bFoundNONE = true;
//value starts from 3rd byte.
for (int i = 2; i < 20; ++i) {
if (NONE_VAL[i] != raw[i]) {
bFoundNONE = false;
}
}
if (bFoundNONE) {
return NONE;
}
//check NO_MASK_VAL
boolean bFoundNoMask = true;
//value starts from 3rd byte.
for (int i = 2; i < 20; ++i) {
if (0xFF != raw[i]) {
bFoundNoMask = false;
}
}
if (bFoundNoMask) {
return NO_MASK;
}
return new IPv6InterfaceAddressTlv(raw);
}
/**
* Returns value of IPv6 Interface Address.
*
* @return rawValue raw value
*/
public byte[] getBytes() {
return rawValue;
}
/**
* Returns value of IPv6 Interface Address.
*
* @return rawValue raw value
*/
public byte[] getValue() {
return rawValue;
}
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
@Override
public short getType() {
return TYPE;
}
@Override
public short getLength() {
return LENGTH;
}
@Override
public int hashCode() {
return Objects.hash(rawValue);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof IPv6InterfaceAddressTlv) {
IPv6InterfaceAddressTlv other = (IPv6InterfaceAddressTlv) obj;
return Objects.equals(rawValue, other.rawValue);
}
return false;
}
@Override
public int write(ChannelBuffer c) {
int iLenStartIndex = c.writerIndex();
c.writeShort(TYPE);
c.writeShort(LENGTH);
c.writeBytes(rawValue);
return c.writerIndex() - iLenStartIndex;
}
/**
* Reads the channel buffer and returns object of IPv6InterfaceAddressTlv.
*
* @param c input channel buffer
* @return object of IPv6InterfaceAddressTlv
*/
public static IPv6InterfaceAddressTlv read20Bytes(ChannelBuffer c) {
byte[] yTemp = new byte[20];
c.readBytes(yTemp, 0, 20);
return IPv6InterfaceAddressTlv.of(yTemp);
}
@Override
public String toString() {
ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass());
toStrHelper.add("Type", TYPE);
toStrHelper.add("Length", LENGTH);
StringBuffer result = new StringBuffer();
for (byte b : rawValue) {
result.append(String.format("%02X ", b));
}
toStrHelper.add("Value", result);
return toStrHelper.toString();
}
}
/*
* Copyright 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.types;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;
/**
* Provides IPv6 Neighbor Address. Reference :[RFC6119]/4.3.
*/
public class IPv6NeighborAddressTlv implements PcepValueType {
protected static final Logger log = LoggerFactory.getLogger(IPv6NeighborAddressTlv.class);
public static final short TYPE = 13; // TDB19
public static final short LENGTH = 20;
public static final byte VALUE_LENGTH = 18;
private static final byte[] NONE_VAL = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
public static final IPv6NeighborAddressTlv NONE = new IPv6NeighborAddressTlv(NONE_VAL);
private static final byte[] NO_MASK_VAL = {(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) 0xFF, (byte) 0xFF};
public static final IPv6NeighborAddressTlv NO_MASK = new IPv6NeighborAddressTlv(NO_MASK_VAL);
public static final IPv6NeighborAddressTlv FULL_MASK = NONE;
private final byte[] rawValue;
/**
* Constructor to initialize rawValue.
*
* @param rawValue IPv6 Neighbor Address Tlv
*/
public IPv6NeighborAddressTlv(byte[] rawValue) {
this.rawValue = rawValue;
}
/**
* Returns newly created IPv6NeighborAddressTlv object.
*
* @param raw IPv6 Neighbor Address
* @return object of IPv6 Neighbor Address Tlv
*/
public static IPv6NeighborAddressTlv of(final byte[] raw) {
//check NONE_VAL
boolean bFoundNONE = true;
//value starts from 3rd byte.
for (int i = 2; i < 20; ++i) {
if (NONE_VAL[i] != raw[i]) {
bFoundNONE = false;
}
}
if (bFoundNONE) {
return NONE;
}
//check NO_MASK_VAL
boolean bFoundNoMask = true;
//value starts from 3rd byte.
for (int i = 2; i < 20; ++i) {
if (0xFF != raw[i]) {
bFoundNoMask = false;
}
}
if (bFoundNoMask) {
return NO_MASK;
}
return new IPv6NeighborAddressTlv(raw);
}
/**
* Returns value of IPv6 Neighbor Address.
*
* @return rawValue raw value
*/
public byte[] getBytes() {
return rawValue;
}
/**
* Returns value of IPv6 Neighbor Address.
*
* @return rawValue raw value
*/
public byte[] getValue() {
return rawValue;
}
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
@Override
public short getType() {
return TYPE;
}
@Override
public short getLength() {
return LENGTH;
}
@Override
public int hashCode() {
return Objects.hash(rawValue);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof IPv6NeighborAddressTlv) {
IPv6NeighborAddressTlv other = (IPv6NeighborAddressTlv) obj;
return Objects.equals(rawValue, other.rawValue);
}
return false;
}
@Override
public int write(ChannelBuffer c) {
int iStartIndex = c.writerIndex();
c.writeShort(TYPE);
c.writeShort(LENGTH);
c.writeBytes(rawValue);
return c.writerIndex() - iStartIndex;
}
/**
* Reads the channel buffer and returns object of IPv6NeighborAddressTlv.
*
* @param c input channel buffer
* @return object of IPv6NeighborAddressTlv
*/
public static IPv6NeighborAddressTlv read20Bytes(ChannelBuffer c) {
byte[] yTemp = new byte[20];
c.readBytes(yTemp, 0, 20);
return IPv6NeighborAddressTlv.of(yTemp);
}
@Override
public String toString() {
ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass());
toStrHelper.add("Type", TYPE);
toStrHelper.add("Length", LENGTH);
StringBuffer result = new StringBuffer();
for (byte b : rawValue) {
result.append(String.format("%02X ", b));
}
toStrHelper.add("Value", result);
return toStrHelper.toString();
}
}
/*
* Copyright 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.types;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;
/**
* Provides IPv6 TE Router Id of Local Node. Reference :[RFC6119]/4.1.
*/
public class IPv6TERouterIdofLocalNodeTlv implements PcepValueType {
protected static final Logger log = LoggerFactory.getLogger(IPv6TERouterIdofLocalNodeTlv.class);
public static final short TYPE = 140; //TDB26
public static final short LENGTH = 20;
public static final byte VALUE_LENGTH = 18;
private static final byte[] NONE_VAL = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
public static final IPv6TERouterIdofLocalNodeTlv NONE = new IPv6TERouterIdofLocalNodeTlv(NONE_VAL);
private static final byte[] NO_MASK_VAL = {(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) 0xFF, (byte) 0xFF };
public static final IPv6TERouterIdofLocalNodeTlv NO_MASK = new IPv6TERouterIdofLocalNodeTlv(NO_MASK_VAL);
public static final IPv6TERouterIdofLocalNodeTlv FULL_MASK = NONE;
private final byte[] rawValue;
/**
* Constructor to initialize rawValue.
*
* @param rawValue IPv6TERouterIdofLocalNodeTlv
*/
public IPv6TERouterIdofLocalNodeTlv(byte[] rawValue) {
this.rawValue = rawValue;
}
/**
* Returns newly created IPv6TERouterIdofLocalNodeTlv object.
*
* @param raw IPv6 TE Router Id of Local Node
* @return object of IPv6TERouterIdofLocalNodeTlv
*/
public static IPv6TERouterIdofLocalNodeTlv of(final byte[] raw) {
//check NONE_VAL
boolean bFoundNONE = true;
//value starts from 3rd byte.
for (int i = 2; i < 20; ++i) {
if (NONE_VAL[i] != raw[i]) {
bFoundNONE = false;
}
}
if (bFoundNONE) {
return NONE;
}
//check NO_MASK_VAL
boolean bFoundNoMask = true;
//value starts from 3rd byte.
for (int i = 2; i < 20; ++i) {
if (0xFF != raw[i]) {
bFoundNoMask = false;
}
}
if (bFoundNoMask) {
return NO_MASK;
}
return new IPv6TERouterIdofLocalNodeTlv(raw);
}
/**
* Returns value of IPv6 TE Router Id of Local Node.
*
* @return byte array value of rawValue
*/
public byte[] getBytes() {
return rawValue;
}
/**
* Returns value of IPv6 TE Router Id of Local Node.
*
* @return byte array value of rawValue
*/
public byte[] getValue() {
return rawValue;
}
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
@Override
public short getType() {
return TYPE;
}
@Override
public short getLength() {
return LENGTH;
}
@Override
public int hashCode() {
return Objects.hash(rawValue);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof IPv6TERouterIdofLocalNodeTlv) {
IPv6TERouterIdofLocalNodeTlv other = (IPv6TERouterIdofLocalNodeTlv) obj;
return Objects.equals(rawValue, other.rawValue);
}
return false;
}
@Override
public int write(ChannelBuffer c) {
int iStartIndex = c.writerIndex();
c.writeShort(TYPE);
c.writeShort(LENGTH);
c.writeBytes(rawValue);
return c.writerIndex() - iStartIndex;
}
/**
* Reads the channel buffer and returns object of IPv6TERouterIdofLocalNodeTlv.
*
* @param c input channel buffer
* @return object of IPv6TERouterIdofLocalNodeTlv
*/
public static IPv6TERouterIdofLocalNodeTlv read20Bytes(ChannelBuffer c) {
byte[] yTemp = new byte[20];
c.readBytes(yTemp, 0, 20);
return IPv6TERouterIdofLocalNodeTlv.of(yTemp);
}
@Override
public String toString() {
ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass());
toStrHelper.add("Type", TYPE);
toStrHelper.add("Length", LENGTH);
StringBuffer result = new StringBuffer();
for (byte b : rawValue) {
result.append(String.format("%02X ", b));
}
toStrHelper.add("Value", result);
return toStrHelper.toString();
}
}
/*
* Copyright 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.types;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;
/**
* Provides IPv6 TE Router Id of Remote Node. Reference :[RFC6119]/4.1.
*/
public class IPv6TERouterIdofRemoteNodeTlv implements PcepValueType {
protected static final Logger log = LoggerFactory.getLogger(IPv6TERouterIdofRemoteNodeTlv.class);
public static final short TYPE = 1400; //TDB29
public static final short LENGTH = 20;
public static final byte VALUE_LENGTH = 18;
private static final byte[] NONE_VAL = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
public static final IPv6TERouterIdofRemoteNodeTlv NONE = new IPv6TERouterIdofRemoteNodeTlv(NONE_VAL);
private static final byte[] NO_MASK_VAL = {(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) 0xFF, (byte) 0xFF};
public static final IPv6TERouterIdofRemoteNodeTlv NO_MASK = new IPv6TERouterIdofRemoteNodeTlv(NO_MASK_VAL);
public static final IPv6TERouterIdofRemoteNodeTlv FULL_MASK = NONE;
private final byte[] rawValue;
/**
* constructor to initialize rawValue.
*
* @param rawValue IPv6TERouterIdofRemoteNodeTlv
*/
public IPv6TERouterIdofRemoteNodeTlv(byte[] rawValue) {
log.debug("IPv6TERouterIdofRemoteNodeTlv");
this.rawValue = rawValue;
}
/**
* Returns newly created IPv6TERouterIdofRemoteNodeTlv object.
*
* @param raw IPv6 TE Router Id of RemoteNode
* @return object of IPv6TERouterIdofRemoteNodeTlv
*/
public static IPv6TERouterIdofRemoteNodeTlv of(final byte[] raw) {
//check NONE_VAL
boolean bFoundNONE = true;
//value starts from 3rd byte.
for (int i = 2; i < 20; ++i) {
if (NONE_VAL[i] != raw[i]) {
bFoundNONE = false;
}
}
if (bFoundNONE) {
return NONE;
}
//check NO_MASK_VAL
boolean bFoundNoMask = true;
//value starts from 3rd byte.
for (int i = 2; i < 20; ++i) {
if (0xFF != raw[i]) {
bFoundNoMask = false;
}
}
if (bFoundNoMask) {
return NO_MASK;
}
return new IPv6TERouterIdofRemoteNodeTlv(raw);
}
/**
* Returns value of IPv6 TE Router Id of Remote Node.
*
* @return byte array value of rawValue
*/
public byte[] getBytes() {
return rawValue;
}
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
@Override
public short getType() {
return TYPE;
}
@Override
public short getLength() {
return LENGTH;
}
@Override
public int hashCode() {
return Objects.hash(rawValue);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof IPv6TERouterIdofRemoteNodeTlv) {
IPv6TERouterIdofRemoteNodeTlv other = (IPv6TERouterIdofRemoteNodeTlv) obj;
return Objects.equals(rawValue, other.rawValue);
}
return false;
}
@Override
public int write(ChannelBuffer c) {
int iStartIndex = c.writerIndex();
c.writeShort(TYPE);
c.writeShort(LENGTH);
c.writeBytes(rawValue);
return c.writerIndex() - iStartIndex;
}
/**
* Reads the channel buffer and returns object of IPv6TERouterIdofRemoteNodeTlv.
*
* @param c input channel buffer
* @return object of IPv6TERouterIdofRemoteNodeTlv
*/
public static IPv6TERouterIdofRemoteNodeTlv read20Bytes(ChannelBuffer c) {
byte[] yTemp = new byte[20];
c.readBytes(yTemp, 0, 20);
return IPv6TERouterIdofRemoteNodeTlv.of(yTemp);
}
@Override
public String toString() {
ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass());
toStrHelper.add("Type", TYPE);
toStrHelper.add("Length", LENGTH);
StringBuffer result = new StringBuffer();
for (byte b : rawValue) {
result.append(String.format("%02X ", b));
}
toStrHelper.add("Value", result);
return toStrHelper.toString();
}
}
/*
* Copyright 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.types;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;
/**
* Provides ISIS Area Identifier.
*/
public class ISISAreaIdentifierTlv implements PcepValueType {
/* Reference :[I-D.ietf-idr- ls-distribution]/3.3.1.2
* 0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type=[TBD24] | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// Area Identifier (variable) //
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
protected static final Logger log = LoggerFactory.getLogger(ISISAreaIdentifierTlv.class);
public static final short TYPE = 107; //TODO:NEED TO HANDLE TBD24
private short hLength;
private final byte[] rawValue;
/**
* Constructor to initialize rawValue.
*
* @param rawValue ISIS-Area-Identifier
* @param hLength length
*/
public ISISAreaIdentifierTlv(byte[] rawValue, short hLength) {
log.debug("ISISAreaIdentifierTlv");
this.rawValue = rawValue;
if (0 == hLength) {
this.hLength = (short) rawValue.length;
} else {
this.hLength = hLength;
}
}
/**
* Returns newly created ISISAreaIdentifierTlv object.
*
* @param raw ISIS-Area-Identifier
* @param hLength length
* @return object of ISISAreaIdentifierTlv
*/
public static ISISAreaIdentifierTlv of(final byte[] raw, short hLength) {
return new ISISAreaIdentifierTlv(raw, hLength);
}
/**
* Returns value of ISIS-Area-Identifier.
*
* @return byte array of rawValue
*/
public byte[] getValue() {
return rawValue;
}
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
@Override
public short getType() {
return TYPE;
}
@Override
public short getLength() {
return hLength;
}
@Override
public int hashCode() {
return Objects.hash(rawValue);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof ISISAreaIdentifierTlv) {
ISISAreaIdentifierTlv other = (ISISAreaIdentifierTlv) obj;
return Objects.equals(hLength, other.hLength) && Objects.equals(rawValue, other.rawValue);
}
return false;
}
@Override
public int write(ChannelBuffer c) {
int iLenStartIndex = c.writerIndex();
c.writeShort(TYPE);
c.writeShort(hLength);
c.writeBytes(rawValue);
return c.writerIndex() - iLenStartIndex;
}
/**
* Reads the channel buffer and returns object of ISISAreaIdentifierTlv.
*
* @param c input channel buffer
* @param hLength length
* @return object of ISISAreaIdentifierTlv
*/
public static PcepValueType read(ChannelBuffer c, short hLength) {
byte[] iISISAreaIdentifier = new byte[hLength];
c.readBytes(iISISAreaIdentifier, 0, hLength);
return new ISISAreaIdentifierTlv(iISISAreaIdentifier, hLength);
}
@Override
public String toString() {
ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass());
toStrHelper.add("Type", TYPE);
toStrHelper.add("Length", hLength);
StringBuffer result = new StringBuffer();
for (byte b : rawValue) {
result.append(String.format("%02X ", b));
}
toStrHelper.add("Value", result);
return toStrHelper.toString();
}
}
/*
* Copyright 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.types;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
/**
* Provides Local and remote Link Identifiers.
*/
public class LinkLocalRemoteIdentifiersTlv implements PcepValueType {
/* Reference :RFC5307
* 0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type=4 | Length=8 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Link Local Identifier |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Link Remote Identifier |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
protected static final Logger log = LoggerFactory.getLogger(LinkLocalRemoteIdentifiersTlv.class);
public static final short TYPE = 4;
public static final short LENGTH = 8;
private final int iLinkLocalIdentifier;
private final int iLinkRemoteIdentifier;
/**
* Constructor to initialize iLinkLocalIdentifier , iLinkRemoteIdentifier.
*
* @param iLinkLocalIdentifier Link Local identifier
* @param iLinkRemoteIdentifier Link Remote identifier
*/
public LinkLocalRemoteIdentifiersTlv(int iLinkLocalIdentifier, int iLinkRemoteIdentifier) {
this.iLinkLocalIdentifier = iLinkLocalIdentifier;
this.iLinkRemoteIdentifier = iLinkRemoteIdentifier;
}
/**
* Retruns an object of Link Local Remote Identifiers Tlv.
*
* @param iLinkLocalIdentifier Link Local identifier
* @param iLinkRemoteIdentifier Link Remote identifier
* @return object of LinkLocalRemoteIdentifiersTlv
*/
public static LinkLocalRemoteIdentifiersTlv of(int iLinkLocalIdentifier, int iLinkRemoteIdentifier) {
return new LinkLocalRemoteIdentifiersTlv(iLinkLocalIdentifier, iLinkRemoteIdentifier);
}
/**
* Returns Link-Local-Identifier.
*
* @return iLinkLocalIdentifier Link Local Identifier
*/
public int getLinkLocalIdentifier() {
return iLinkLocalIdentifier;
}
/**
* Returns Link-Remote-Identifier.
*
* @return iLinkRemoteIdentifier Link Remote Identifier.
*/
public int getLinkRemoteIdentifier() {
return iLinkRemoteIdentifier;
}
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
@Override
public short getLength() {
return LENGTH;
}
@Override
public short getType() {
return TYPE;
}
@Override
public int hashCode() {
return Objects.hash(iLinkLocalIdentifier, iLinkRemoteIdentifier);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof LinkLocalRemoteIdentifiersTlv) {
LinkLocalRemoteIdentifiersTlv other = (LinkLocalRemoteIdentifiersTlv) obj;
return Objects.equals(iLinkLocalIdentifier, other.iLinkLocalIdentifier)
&& Objects.equals(iLinkRemoteIdentifier, other.iLinkRemoteIdentifier);
}
return false;
}
@Override
public int write(ChannelBuffer c) {
int iStartIndex = c.writerIndex();
c.writeShort(TYPE);
c.writeShort(LENGTH);
c.writeInt(iLinkLocalIdentifier);
c.writeInt(iLinkRemoteIdentifier);
return c.writerIndex() - iStartIndex;
}
/**
* Reads the channel buffer and returns object of LinkLocalRemoteIdentifiersTlv.
*
* @param c input channel buffer
* @return object of LinkLocalRemoteIdentifiersTlv
*/
public static PcepValueType read(ChannelBuffer c) {
int iLinkLocalIdentifier = c.readInt();
int iLinkRemoteIdentifier = c.readInt();
return new LinkLocalRemoteIdentifiersTlv(iLinkLocalIdentifier, iLinkRemoteIdentifier);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH)
.add("LinkLocalIdentifier", iLinkLocalIdentifier).add("LinkRemoteIdentifier", iLinkRemoteIdentifier)
.toString();
}
}
/*
* Copyright 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.types;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;
/**
* Provides the Link Name.
*/
public class LinkNameTlv implements PcepValueType {
/* Reference :[I-D.ietf-idr- ls-distribution] /3.3.2.7
* Link name tlv format.
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type=TDB43 | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// Link Name (variable) //
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
protected static final Logger log = LoggerFactory.getLogger(LinkNameTlv.class);
public static final short TYPE = 1098; //TODO:NEED TO HANDLE TDB43
private short hLength;
private final byte[] rawValue;
/**
* Constructor to initialize rawValue.
*
* @param rawValue Link-Name
* @param hLength length
*/
public LinkNameTlv(byte[] rawValue, short hLength) {
this.rawValue = rawValue;
if (0 == hLength) {
this.hLength = (short) rawValue.length;
} else {
this.hLength = hLength;
}
}
/**
* Returns newly created LinkNameTlv object.
*
* @param raw Link-Name
* @param hLength length
* @return object of LinkNameTlv
*/
public static LinkNameTlv of(final byte[] raw, short hLength) {
return new LinkNameTlv(raw, hLength);
}
/**
* Returns value of Link-Name.
*
* @return raw value
*/
public byte[] getValue() {
return rawValue;
}
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
@Override
public short getType() {
return TYPE;
}
@Override
public short getLength() {
return hLength;
}
@Override
public int hashCode() {
return Objects.hash(rawValue);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof LinkNameTlv) {
LinkNameTlv other = (LinkNameTlv) obj;
return Objects.equals(rawValue, other.rawValue);
}
return false;
}
@Override
public int write(ChannelBuffer c) {
int iLenStartIndex = c.writerIndex();
c.writeShort(TYPE);
c.writeShort(hLength);
c.writeBytes(rawValue);
return c.writerIndex() - iLenStartIndex;
}
/**
* Reads the channel buffer and returns object of LinkNameTlv.
*
* @param c input channel buffer
* @param hLength length
* @return object of LinkNameTlv
*/
public static PcepValueType read(ChannelBuffer c, short hLength) {
byte[] linkName = new byte[hLength];
c.readBytes(linkName, 0, hLength);
return new LinkNameTlv(linkName, hLength);
}
@Override
public String toString() {
ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass());
toStrHelper.add("Type", TYPE);
toStrHelper.add("Length", hLength);
StringBuffer result = new StringBuffer();
for (byte b : rawValue) {
result.append(String.format("%02X ", b));
}
toStrHelper.add("Value", result);
return toStrHelper.toString();
}
}
/*
* Copyright 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.types;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
/**
* Provide Link Protection Type.
*/
public class LinkProtectionTypeTlv implements PcepValueType {
/* Reference :[RFC5307]/1.2
* 0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type=[TDB38] | Length=2 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Protection Cap | Reserved |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
protected static final Logger log = LoggerFactory.getLogger(LinkProtectionTypeTlv.class);
public static final short TYPE = 20; //TDB38
public static final short LENGTH = 2;
private final byte protectionCap;
private final byte reserved;
/**
* Constructor to initialize protectionCap.
*
* @param protectionCap Protection Cap
*/
public LinkProtectionTypeTlv(byte protectionCap) {
this.protectionCap = protectionCap;
this.reserved = 0;
}
/**
* Constructor to initialize protectionCap, reserved.
*
* @param protectionCap Protection Cap
* @param reserved Reserved value
*/
public LinkProtectionTypeTlv(byte protectionCap, byte reserved) {
this.protectionCap = protectionCap;
this.reserved = reserved;
}
/**
* Returns Protection Cap.
*
* @return protectionCap Protection Cap
*/
public byte getProtectionCap() {
return protectionCap;
}
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
@Override
public short getType() {
return TYPE;
}
@Override
public short getLength() {
return LENGTH;
}
@Override
public int hashCode() {
return Objects.hash(protectionCap, reserved);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof LinkProtectionTypeTlv) {
LinkProtectionTypeTlv other = (LinkProtectionTypeTlv) obj;
return Objects.equals(protectionCap, other.protectionCap) && Objects.equals(reserved, other.reserved);
}
return false;
}
@Override
public int write(ChannelBuffer c) {
int iLenStartIndex = c.writerIndex();
c.writeShort(TYPE);
c.writeShort(LENGTH);
c.writeByte(protectionCap);
c.writeByte(reserved);
return c.writerIndex() - iLenStartIndex;
}
/**
* Reads the channel buffer and returns object of LinkProtectionTypeTlv.
*
* @param c input channel buffer
* @return object of LinkProtectionTypeTlv
*/
public static PcepValueType read(ChannelBuffer c) {
byte protectionCap = c.readByte();
byte reserved = c.readByte();
return new LinkProtectionTypeTlv(protectionCap, reserved);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH)
.add("ProtectionCap", protectionCap).toString();
}
}
\ No newline at end of file
/*
* Copyright 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.types;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.pcepio.exceptions.PcepParseException;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
/**
* Provides Local TE Node Descriptors TLV which contains Node Descriptor Sub-TLVs.
*/
public class LocalTENodeDescriptorsTLV implements PcepValueType {
/* REFERENCE :draft-ietf-idr-ls-distribution-10
* 0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type=[TBD8] | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
// Node Descriptor Sub-TLVs (variable) //
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Note: Length is including header here. Refer Routing Universe TLV.
*/
protected static final Logger log = LoggerFactory.getLogger(LocalTENodeDescriptorsTLV.class);
public static final short TYPE = 1637; //TODD:change this TBD8
public short hLength;
public static final int TLV_HEADER_LENGTH = 4;
// Node Descriptor Sub-TLVs (variable)
private LinkedList<PcepValueType> llNodeDescriptorSubTLVs;
/**
* Constructor to initialize llNodeDescriptorSubTLVs.
*
* @param llNodeDescriptorSubTLVs LinkedList of PcepValueType
*/
public LocalTENodeDescriptorsTLV(LinkedList<PcepValueType> llNodeDescriptorSubTLVs) {
this.llNodeDescriptorSubTLVs = llNodeDescriptorSubTLVs;
}
/**
* Returns a new object of LocalTENodeDescriptorsTLV.
*
* @param llNodeDescriptorSubTLVs linked list of Node Descriptor Sub TLVs
* @return object of LocalTENodeDescriptorsTLV
*/
public static LocalTENodeDescriptorsTLV of(final LinkedList<PcepValueType> llNodeDescriptorSubTLVs) {
return new LocalTENodeDescriptorsTLV(llNodeDescriptorSubTLVs);
}
/**
* Returns Linked List of tlvs.
*
* @return llNodeDescriptorSubTLVs linked list of Node Descriptor Sub TLV
*/
public LinkedList<PcepValueType> getllNodeDescriptorSubTLVs() {
return llNodeDescriptorSubTLVs;
}
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
@Override
public short getType() {
return TYPE;
}
@Override
public short getLength() {
return hLength;
}
@Override
public int hashCode() {
return Objects.hash(llNodeDescriptorSubTLVs.hashCode());
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
/*
* Here we have a list of Tlv so to compare each sub tlv between the object
* we have to take a list iterator so one by one we can get each sub tlv object
* and can compare them.
* it may be possible that the size of 2 lists is not equal so we have to first check
* the size, if both are same then we should check for the subtlv objects otherwise
* we should return false.
*/
if (obj instanceof LocalTENodeDescriptorsTLV) {
int countObjSubTlv = 0;
int countOtherSubTlv = 0;
boolean isCommonSubTlv = true;
LocalTENodeDescriptorsTLV other = (LocalTENodeDescriptorsTLV) obj;
Iterator<PcepValueType> objListIterator = ((LocalTENodeDescriptorsTLV) obj).llNodeDescriptorSubTLVs
.iterator();
countObjSubTlv = ((LocalTENodeDescriptorsTLV) obj).llNodeDescriptorSubTLVs.size();
countOtherSubTlv = other.llNodeDescriptorSubTLVs.size();
if (countObjSubTlv != countOtherSubTlv) {
return false;
} else {
while (objListIterator.hasNext() && isCommonSubTlv) {
PcepValueType subTlv = objListIterator.next();
isCommonSubTlv = Objects.equals(llNodeDescriptorSubTLVs.contains(subTlv),
other.llNodeDescriptorSubTLVs.contains(subTlv));
}
return isCommonSubTlv;
}
}
return false;
}
@Override
public int write(ChannelBuffer c) {
int tlvStartIndex = c.writerIndex();
c.writeShort(TYPE);
int tlvLenIndex = c.writerIndex();
hLength = 0;
c.writeShort(0);
ListIterator<PcepValueType> listIterator = llNodeDescriptorSubTLVs.listIterator();
while (listIterator.hasNext()) {
PcepValueType tlv = listIterator.next();
if (null == tlv) {
log.debug("TLV is null from subTlv list");
continue;
}
tlv.write(c);
// need to take care of padding
int pad = tlv.getLength() % 4;
if (0 != pad) {
pad = 4 - pad;
for (int i = 0; i < pad; ++i) {
c.writeByte((byte) 0);
}
}
}
hLength = (short) (c.writerIndex() - tlvStartIndex);
c.setShort(tlvLenIndex, hLength);
return c.writerIndex() - tlvStartIndex;
}
/**
* Reads the channel buffer and returns object of AutonomousSystemTlv.
*
* @param c input channel buffer
* @param hLength length of subtlvs.
* @return object of AutonomousSystemTlv
* @throws PcepParseException if mandatory fields are missing
*/
public static PcepValueType read(ChannelBuffer c, short hLength) throws PcepParseException {
// Node Descriptor Sub-TLVs (variable)
LinkedList<PcepValueType> llNodeDescriptorSubTLVs = new LinkedList<PcepValueType>();
ChannelBuffer tempCb = c.readBytes(hLength - TLV_HEADER_LENGTH);
while (TLV_HEADER_LENGTH <= tempCb.readableBytes()) {
PcepValueType tlv;
short hType = tempCb.readShort();
int iValue = 0;
short length = tempCb.readShort();
switch (hType) {
case AutonomousSystemTlv.TYPE:
iValue = tempCb.readInt();
tlv = new AutonomousSystemTlv(iValue);
break;
case BGPLSidentifierTlv.TYPE:
iValue = tempCb.readInt();
tlv = new BGPLSidentifierTlv(iValue);
break;
case OSPFareaIDsubTlv.TYPE:
iValue = tempCb.readInt();
tlv = new OSPFareaIDsubTlv(iValue);
break;
case RouterIDSubTlv.TYPE:
tlv = RouterIDSubTlv.read(tempCb, length);
break;
default:
throw new PcepParseException("Unsupported Sub TLV type :" + hType);
}
// Check for the padding
int pad = length % 4;
if (0 < pad) {
pad = 4 - pad;
if (pad <= tempCb.readableBytes()) {
tempCb.skipBytes(pad);
}
}
llNodeDescriptorSubTLVs.add(tlv);
}
if (0 < tempCb.readableBytes()) {
throw new PcepParseException("Sub Tlv parsing error. Extra bytes received.");
}
return new LocalTENodeDescriptorsTLV(llNodeDescriptorSubTLVs);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", hLength)
.add("NodeDescriptorSubTLVs", llNodeDescriptorSubTLVs).toString();
}
}
/*
* Copyright 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.types;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
/**
* Provides MPLS Protocol Mask.
*/
public class MPLSProtocolMaskTlv implements PcepValueType {
/* Reference :[I-D.ietf-idr-ls-distribution]/3.3.2.2
* 0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type=TDB39 | Length =1 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|L|R| Reserved |
+-+-+-+-+-+-+-+-+
*/
protected static final Logger log = LoggerFactory.getLogger(MPLSProtocolMaskTlv.class);
public static final short TYPE = 1094; //TDB39
public static final short LENGTH = 1;
public static final int SET = 1;
public static final byte LFLAG_SET = (byte) 0x80;
public static final byte RFLAG_SET = 0x40;
private final byte rawValue;
private final boolean bLFlag;
private final boolean bRFlag;
private final boolean isRawValueSet;
/**
* constructor to initialize rawValue.
*
* @param rawValue MPLS Protocol Mask Flag Bits
*/
public MPLSProtocolMaskTlv(byte rawValue) {
this.rawValue = rawValue;
isRawValueSet = true;
byte temp = rawValue;
if ((temp & LFLAG_SET) == SET) {
this.bLFlag = true;
} else {
this.bLFlag = false;
}
if ((temp & RFLAG_SET) == SET) {
this.bRFlag = true;
} else {
this.bRFlag = false;
}
}
/**
* constructor to initialize different Flags.
*
* @param bLFlag L-flag
* @param bRFlag R-flag
*/
public MPLSProtocolMaskTlv(boolean bLFlag, boolean bRFlag) {
this.bLFlag = bLFlag;
this.bRFlag = bRFlag;
this.rawValue = 0;
isRawValueSet = false;
}
/**
* Returns newly created MPLSProtocolMaskTlv object.
*
* @param raw MPLS Protocol Mask Tlv
* @return new object of MPLS Protocol Mask Tlv
*/
public static MPLSProtocolMaskTlv of(final byte raw) {
return new MPLSProtocolMaskTlv(raw);
}
/**
* Returns L-flag.
*
* @return bLFlag L-flag
*/
public boolean getbLFlag() {
return bLFlag;
}
/**
* Returns R-flag.
*
* @return bRFlag R-flag
*/
public boolean getbRFlag() {
return bRFlag;
}
/**
* Returns raw value.
*
* @return rawValue raw value
*/
public byte getByte() {
return rawValue;
}
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
@Override
public short getType() {
return TYPE;
}
@Override
public short getLength() {
return LENGTH;
}
@Override
public int hashCode() {
if (isRawValueSet) {
return Objects.hash(rawValue);
} else {
return Objects.hash(bLFlag, bRFlag);
}
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof MPLSProtocolMaskTlv) {
MPLSProtocolMaskTlv other = (MPLSProtocolMaskTlv) obj;
if (isRawValueSet) {
return Objects.equals(this.bLFlag, other.bLFlag) && Objects.equals(this.bRFlag, other.bRFlag);
} else {
return Objects.equals(this.rawValue, other.rawValue);
}
}
return false;
}
@Override
public int write(ChannelBuffer c) {
int iLenStartIndex = c.writerIndex();
c.writeShort(TYPE);
c.writeShort(LENGTH);
if (isRawValueSet) {
c.writeByte(rawValue);
} else {
byte temp = 0;
if (bLFlag) {
temp = (byte) (temp | LFLAG_SET);
}
if (bRFlag) {
temp = (byte) (temp | RFLAG_SET);
}
c.writeByte(temp);
}
return c.writerIndex() - iLenStartIndex;
}
/**
* Reads the channel buffer and returns object of MPLS Protocol Mask Tlv.
*
* @param c input channel buffer
* @return object of MPLS Protocol Mask Tlv
*/
public static PcepValueType read(ChannelBuffer c) {
byte temp = c.readByte();
boolean bLFlag;
boolean bRFlag;
if ((temp & LFLAG_SET) == SET) {
bLFlag = true;
} else {
bLFlag = false;
}
if ((temp & RFLAG_SET) == SET) {
bRFlag = true;
} else {
bRFlag = false;
}
return new MPLSProtocolMaskTlv(bLFlag, bRFlag);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH).add("Value", rawValue)
.toString();
}
}
/*
* Copyright 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.types;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
/**
* Provide the Maximum Link Bandwidth.
*/
public class MaximumLinkBandwidthTlv implements PcepValueType {
/* Reference :[RFC5305]/3.3.
* 0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type=[TDB34] | Length=4 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Maximum Link Bandwidth |
+-+-+-+-+-+-+-+-+-++-+-+-+-+-+-+-+-+-++-+-+-+-+-+-+-+-+-++-+-+-+-
*/
protected static final Logger log = LoggerFactory.getLogger(MaximumLinkBandwidthTlv.class);
public static final short TYPE = 9; //TDB34
public static final short LENGTH = 4;
private final int rawValue;
/**
* Constructor to initialize rawValue.
*
* @param rawValue Maximum-Link-Bandwidth
*/
public MaximumLinkBandwidthTlv(int rawValue) {
this.rawValue = rawValue;
}
/**
* Returns newly created MaximumLinkBandwidthTlv object.
*
* @param raw value of Maximum-Link-Bandwidth
* @return object of MaximumLinkBandwidthTlv
*/
public static MaximumLinkBandwidthTlv of(final int raw) {
return new MaximumLinkBandwidthTlv(raw);
}
/**
* Returns value of Maximum Link Bandwidth.
*
* @return rawValue Maximum Link Bandwidth
*/
public int getInt() {
return rawValue;
}
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
@Override
public short getType() {
return TYPE;
}
@Override
public short getLength() {
return LENGTH;
}
@Override
public int hashCode() {
return Objects.hash(rawValue);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof MaximumLinkBandwidthTlv) {
MaximumLinkBandwidthTlv other = (MaximumLinkBandwidthTlv) obj;
return Objects.equals(rawValue, other.rawValue);
}
return false;
}
@Override
public int write(ChannelBuffer c) {
int iLenStartIndex = c.writerIndex();
c.writeShort(TYPE);
c.writeShort(LENGTH);
c.writeInt(rawValue);
return c.writerIndex() - iLenStartIndex;
}
/**
* Reads the channel buffer and returns object of MaximumLinkBandwidthTlv.
*
* @param c input channel buffer
* @return object of MaximumLinkBandwidthTlv
*/
public static MaximumLinkBandwidthTlv read(ChannelBuffer c) {
return MaximumLinkBandwidthTlv.of(c.readInt());
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH).add("Value", rawValue)
.toString();
}
}
/*
* Copyright 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.types;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
/**
* Provide the Maximum Reservable Link Bandwidth.
*/
public class MaximumReservableLinkBandwidthTlv implements PcepValueType {
/* Reference :[RFC5305]/3.5.
* 0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type=[TDB35] | Length=4 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Maximum Reservable Link Bandwidth |
+-+-+-+-+-+-+-+-+-++-+-+-+-+-+-+-+-+-++-+-+-+-+-+-+-+-+-++-+-+-+-
*/
protected static final Logger log = LoggerFactory.getLogger(MaximumReservableLinkBandwidthTlv.class);
public static final short TYPE = 10; // TDB35
public static final short LENGTH = 4;
private final int rawValue;
/**
* constructor to initialize rawValue.
*
* @param rawValue MaximumReservableLinkBandwidth
*/
public MaximumReservableLinkBandwidthTlv(int rawValue) {
log.debug("MaximumReservableLinkBandwidthTlv");
this.rawValue = rawValue;
}
/**
* Returns newly created MaximumReservableLinkBandwidth object.
*
* @param raw MaximumReservableLinkBandwidth
* @return object of MaximumReservableLinkBandwidthTlv
*/
public static MaximumReservableLinkBandwidthTlv of(final int raw) {
return new MaximumReservableLinkBandwidthTlv(raw);
}
/**
* Returns value of Maximum Reservable Link Bandwidth.
* @return rawValue Maximum Reservable Link Bandwidth
*/
public int getInt() {
return rawValue;
}
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
@Override
public short getType() {
return TYPE;
}
@Override
public short getLength() {
return LENGTH;
}
@Override
public int hashCode() {
return Objects.hash(rawValue);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof MaximumReservableLinkBandwidthTlv) {
MaximumReservableLinkBandwidthTlv other = (MaximumReservableLinkBandwidthTlv) obj;
return Objects.equals(this.rawValue, other.rawValue);
}
return false;
}
@Override
public int write(ChannelBuffer c) {
int iLenStartIndex = c.writerIndex();
c.writeShort(TYPE);
c.writeShort(LENGTH);
c.writeInt(rawValue);
return c.writerIndex() - iLenStartIndex;
}
/**
* Reads the channel buffer and returns object of MaximumReservableLinkBandwidthTlv.
*
* @param c input channel buffer
* @return object of MaximumReservableLinkBandwidthTlv
*/
public static MaximumReservableLinkBandwidthTlv read(ChannelBuffer c) {
return MaximumReservableLinkBandwidthTlv.of(c.readInt());
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH).add("Value", rawValue)
.toString();
}
}
/*
* Copyright 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.types;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
/**
* Provide node Flags bits.
*/
public class NodeFlagBitsTlv implements PcepValueType {
/* Reference :[I-D.ietf-idr- ls-distribution] /3.3.1.1
* 0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type=[TBD21] | Length=1 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|O|T|E|B| Reserved|
+-+-+-+-+-+-+-+-+-+
*/
protected static final Logger log = LoggerFactory.getLogger(NodeFlagBitsTlv.class);
public static final short TYPE = 14;
public static final short LENGTH = 1;
public static final int SET = 1;
public static final byte OFLAG_SET = (byte) 0x80;
public static final byte TFLAG_SET = 0x40;
public static final byte EFLAG_SET = 0x20;
public static final byte BFLAG_SET = 0x10;
private final byte rawValue;
private final boolean bOFlag;
private final boolean bTFlag;
private final boolean bEFlag;
private final boolean bBFlag;
private final boolean isRawValueSet;
/**
* constructor to initialize rawValue.
*
* @param rawValue of Node Flag Bits TLV
*/
public NodeFlagBitsTlv(byte rawValue) {
this.rawValue = rawValue;
isRawValueSet = true;
byte temp = rawValue;
this.bOFlag = (temp & OFLAG_SET) == OFLAG_SET ? true : false;
this.bTFlag = (temp & TFLAG_SET) == TFLAG_SET ? true : false;
this.bEFlag = (temp & EFLAG_SET) == EFLAG_SET ? true : false;
this.bBFlag = (temp & BFLAG_SET) == BFLAG_SET ? true : false;
}
/**
* constructor to initialize different Flags.
*
* @param bOFlag O-flag
* @param bTFlag T-flag
* @param bEFlag E-flag
* @param bBFlag B-flag
*/
public NodeFlagBitsTlv(boolean bOFlag, boolean bTFlag, boolean bEFlag, boolean bBFlag) {
this.bOFlag = bOFlag;
this.bTFlag = bTFlag;
this.bEFlag = bEFlag;
this.bBFlag = bBFlag;
this.rawValue = 0;
this.isRawValueSet = false;
}
/**
* Returns newly created NodeFlagBitsTlv object.
*
* @param raw of Node Flag Bits TLV
* @return new object of NodeFlagBitsTlv
*/
public static NodeFlagBitsTlv of(final byte raw) {
return new NodeFlagBitsTlv(raw);
}
/**
* Returns raw value of NodeFlagBitsTlv.
*
* @return rawValue raw value
*/
public byte getbyte() {
return rawValue;
}
/**
* Returns O-flag.
*
* @return bOFlag O-flag
*/
public boolean getOFlag() {
return bOFlag;
}
/**
* Returns T-flag.
*
* @return bTFlag T-flag
*/
public boolean getTFlag() {
return bTFlag;
}
/**
* Returns E-flag.
*
* @return bEFlag E-flag
*/
public boolean getEFlag() {
return bEFlag;
}
/**
* Returns B-flag.
*
* @return bBFlag B-flag
*/
public boolean getBFlag() {
return bBFlag;
}
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
@Override
public short getType() {
return TYPE;
}
@Override
public short getLength() {
return LENGTH;
}
@Override
public int hashCode() {
if (isRawValueSet) {
return Objects.hash(rawValue);
} else {
return Objects.hash(bOFlag, bTFlag, bEFlag, bBFlag);
}
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof NodeFlagBitsTlv) {
NodeFlagBitsTlv other = (NodeFlagBitsTlv) obj;
if (isRawValueSet) {
return Objects.equals(this.bOFlag, other.bOFlag) && Objects.equals(this.bTFlag, other.bTFlag)
&& Objects.equals(this.bEFlag, other.bEFlag) && Objects.equals(this.bBFlag, other.bBFlag);
} else {
return Objects.equals(this.rawValue, other.rawValue);
}
}
return false;
}
@Override
public int write(ChannelBuffer c) {
int iLenStartIndex = c.writerIndex();
c.writeShort(TYPE);
c.writeShort(LENGTH);
if (isRawValueSet) {
c.writeByte(rawValue);
} else {
byte temp = 0;
if (bOFlag) {
temp = (byte) (temp | OFLAG_SET);
}
if (bTFlag) {
temp = (byte) (temp | TFLAG_SET);
}
if (bEFlag) {
temp = (byte) (temp | EFLAG_SET);
}
if (bBFlag) {
temp = (byte) (temp | BFLAG_SET);
}
c.writeByte(temp);
}
return c.writerIndex() - iLenStartIndex;
}
/**
* Reads the channel buffer and returns object of NodeFlagBitsTlv.
*
* @param c input channel buffer
* @return object of NodeFlagBitsTlv
*/
public static PcepValueType read(ChannelBuffer c) {
return NodeFlagBitsTlv.of(c.readByte());
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH)
.add("OFlag", (bOFlag) ? 1 : 0).add("TFlag", (bTFlag) ? 1 : 0).add("EFlag", (bEFlag) ? 1 : 0)
.add("BFlag", (bBFlag) ? 1 : 0).toString();
}
}
/*
* Copyright 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.types;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;
/**
* Provide the name for the node.
*/
public class NodeNameTlv implements PcepValueType {
/* reference :[I-D.ietf-idr-ls-distribution]/3.3.1.3
* 0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type=[TBD23] | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// Node Name (variable) //
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
protected static final Logger log = LoggerFactory.getLogger(NodeNameTlv.class);
public static final short TYPE = 1007; //TODO:check and change TBD23
public final short hLength;
private final byte[] rawValue;
/**
* constructor to initialize rawValue.
*
* @param rawValue of Node Name
* @param hLength length
*/
public NodeNameTlv(byte[] rawValue, short hLength) {
log.debug("NodeNameTlv");
this.rawValue = rawValue;
if (0 == hLength) {
this.hLength = (short) rawValue.length;
} else {
this.hLength = hLength;
}
}
/**
* Returns newly created NodeNameTlv object.
*
* @param raw of NodeName
* @param hLength length
* @return new object of Node Name Tlv
*/
public static NodeNameTlv of(final byte[] raw, short hLength) {
return new NodeNameTlv(raw, hLength);
}
/**
* Returns RawValue for NodeName.
*
* @return rawValue raw value
*/
public byte[] getValue() {
return rawValue;
}
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
@Override
public short getType() {
return TYPE;
}
@Override
public short getLength() {
return hLength;
}
@Override
public int hashCode() {
return Objects.hash(rawValue);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof NodeNameTlv) {
NodeNameTlv other = (NodeNameTlv) obj;
return Objects.equals(this.rawValue, other.rawValue);
}
return false;
}
@Override
public int write(ChannelBuffer c) {
int iLenStartIndex = c.writerIndex();
c.writeShort(TYPE);
c.writeShort(hLength);
c.writeBytes(rawValue);
return c.writerIndex() - iLenStartIndex;
}
/**
* Reads the channel buffer and returns object of NodeNameTlv.
*
* @param c input channel buffer
* @param hLength length
* @return object of Node Name TLV
*/
public static PcepValueType read(ChannelBuffer c, short hLength) {
byte[] iNodeName = new byte[hLength];
c.readBytes(iNodeName, 0, hLength);
return new NodeNameTlv(iNodeName, hLength);
}
@Override
public String toString() {
ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass());
toStrHelper.add("Type", TYPE);
toStrHelper.add("Length", hLength);
StringBuffer result = new StringBuffer();
for (byte b : rawValue) {
result.append(String.format("%02X ", b));
}
toStrHelper.add("Value", result);
return toStrHelper.toString();
}
}
/*
* Copyright 2014 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.types;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
/**
* Provides area ID for OSPF area.
*/
public class OSPFareaIDsubTlv implements PcepValueType {
/* Reference :draft-ietf-idr-ls-distribution-10.
* 0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type=[TBD12] | Length=4 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| opaque value (32 Bit AS Number) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
protected static final Logger log = LoggerFactory.getLogger(OSPFareaIDsubTlv.class);
public static final short TYPE = 600; //TODD:change this TBD12
public static final short LENGTH = 4;
private final int rawValue;
/**
* constructor to initialize rawValue.
*
* @param rawValue area ID for OSPF area.
*/
public OSPFareaIDsubTlv(int rawValue) {
this.rawValue = rawValue;
}
/**
* Returns newly created OSPFareaIDsubTlv object.
*
* @param raw opaque value of AreaID
* @return new object of OSPF area ID sub TLV
*/
public static OSPFareaIDsubTlv of(final int raw) {
return new OSPFareaIDsubTlv(raw);
}
/**
* Returns RawValue opaque value of AreaID.
*
* @return rawValue Area ID
*/
public int getInt() {
return rawValue;
}
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
@Override
public short getType() {
return TYPE;
}
@Override
public short getLength() {
return LENGTH;
}
@Override
public int hashCode() {
return Objects.hash(rawValue);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof OSPFareaIDsubTlv) {
OSPFareaIDsubTlv other = (OSPFareaIDsubTlv) obj;
return Objects.equals(this.rawValue, other.rawValue);
}
return false;
}
@Override
public int write(ChannelBuffer c) {
int iLenStartIndex = c.writerIndex();
c.writeShort(TYPE);
c.writeShort(LENGTH);
c.writeInt(rawValue);
return c.writerIndex() - iLenStartIndex;
}
/**
* Reads the channel buffer and returns object of OSPFAreaIdSubTlv.
*
* @param c input channel buffer
* @return object of OSPFAreaIdSubTlv
*/
public static OSPFareaIDsubTlv read(ChannelBuffer c) {
return OSPFareaIDsubTlv.of(c.readInt());
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH).add("Value", rawValue)
.toString();
}
}
/*
* Copyright 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.types;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;
/**
* Provides Opaque Link Attribute.
*/
public class OpaqueLinkAttributeTlv implements PcepValueType {
/*
* TLV format.
* Reference :[I-D.ietf-idr-attributesls-distribution] /3.3.2.6
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type=TBD42 | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// Opaque link attributes (variable) //
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
protected static final Logger log = LoggerFactory.getLogger(OpaqueLinkAttributeTlv.class);
public static final short TYPE = 1097; //TODO:NEED TO HANDLE TDB42
private final short hLength;
private final byte[] rawValue;
/**
* constructor to initialize rawValue.
*
* @param rawValue of Opaque Link Attribute
* @param hLength length
*/
public OpaqueLinkAttributeTlv(byte[] rawValue, short hLength) {
log.debug("OpaqueLinkAttributeTlv");
this.rawValue = rawValue;
if (0 == hLength) {
this.hLength = (short) rawValue.length;
} else {
this.hLength = hLength;
}
}
/**
* Returns newly created OpaqueLinkAttributeTlv object.
*
* @param raw of Opaque Link Attribute
* @param hLength length
* @return new object of OpaqueLinkAttributeTlv
*/
public static OpaqueLinkAttributeTlv of(final byte[] raw, short hLength) {
return new OpaqueLinkAttributeTlv(raw, hLength);
}
/**
* Returns raw value of Opaque Link Attribute Tlv.
* @return rawValue raw value
*/
public byte[] getValue() {
return rawValue;
}
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
@Override
public short getType() {
return TYPE;
}
@Override
public short getLength() {
return hLength;
}
@Override
public int hashCode() {
return Objects.hash(rawValue);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof OpaqueLinkAttributeTlv) {
OpaqueLinkAttributeTlv other = (OpaqueLinkAttributeTlv) obj;
return Objects.equals(this.rawValue, other.rawValue);
}
return false;
}
@Override
public int write(ChannelBuffer c) {
int iLenStartIndex = c.writerIndex();
c.writeShort(TYPE);
c.writeShort(hLength);
c.writeBytes(rawValue);
return c.writerIndex() - iLenStartIndex;
}
/**
* Reads the channel buffer and returns object of OpaqueLinkAttributeTlv.
*
* @param c input channel buffer
* @param hLength length
* @return object of Opaque Link Attribute Tlv
*/
public static PcepValueType read(ChannelBuffer c, short hLength) {
byte[] iOpaqueValue = new byte[hLength];
c.readBytes(iOpaqueValue, 0, hLength);
return new OpaqueLinkAttributeTlv(iOpaqueValue, hLength);
}
@Override
public String toString() {
ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass());
toStrHelper.add("Type", TYPE);
toStrHelper.add("Length", hLength);
StringBuffer result = new StringBuffer();
for (byte b : rawValue) {
result.append(String.format("%02X ", b));
}
toStrHelper.add("Value", result);
return toStrHelper.toString();
}
}
/*
* Copyright 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.types;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;
/**
* Provides Opaque node attributes.
*/
public class OpaqueNodeAttributeTlv implements PcepValueType {
/*
* Reference [I-D.ietf-idr-Properties ls-distribution] /3.3.1.5
* 0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type=[TBD22] | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// Opaque node attributes (variable) //
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
protected static final Logger log = LoggerFactory.getLogger(OpaqueNodeAttributeTlv.class);
public static final short TYPE = 1001;
private final short hLength;
private final byte[] rawValue;
/**
* constructor to initialize rawValue.
*
* @param rawValue Opaque Node Attribute
* @param hLength length
*/
public OpaqueNodeAttributeTlv(byte[] rawValue, short hLength) {
this.rawValue = rawValue;
if (0 == hLength) {
this.hLength = (short) rawValue.length;
} else {
this.hLength = hLength;
}
}
/**
* Returns newly created OpaqueNodeAttributeTlv object.
*
* @param raw value of Opaque Node Attribute
* @param hLength length
* @return new object of Opaque Node Attribute Tlv
*/
public static OpaqueNodeAttributeTlv of(final byte[] raw, short hLength) {
return new OpaqueNodeAttributeTlv(raw, hLength);
}
/**
* Returns raw value of Opaque Node Attribute Tlv.
*
* @return rawValue of Opaque Node Attribute
*/
public byte[] getValue() {
return rawValue;
}
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
@Override
public short getType() {
return TYPE;
}
@Override
public short getLength() {
return hLength;
}
@Override
public int hashCode() {
return Objects.hash(rawValue);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof OpaqueLinkAttributeTlv) {
OpaqueNodeAttributeTlv other = (OpaqueNodeAttributeTlv) obj;
return Objects.equals(this.rawValue, other.rawValue);
}
return false;
}
@Override
public int write(ChannelBuffer c) {
int iLenStartIndex = c.writerIndex();
c.writeShort(TYPE);
c.writeShort(hLength);
c.writeBytes(rawValue);
return c.writerIndex() - iLenStartIndex;
}
/**
* Reads the channel buffer and returns object of Opaque Node Attribute Tlv.
*
* @param c input channel buffer
* @param hLength length
* @return object of OpaqueNodeAttributeTlv
*/
public static PcepValueType read(ChannelBuffer c, short hLength) {
byte[] iOpaqueValue = new byte[hLength];
c.readBytes(iOpaqueValue, 0, hLength);
return new OpaqueNodeAttributeTlv(iOpaqueValue, hLength);
}
@Override
public String toString() {
ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass());
toStrHelper.add("Type", TYPE);
toStrHelper.add("Length", hLength);
StringBuffer result = new StringBuffer();
for (byte b : rawValue) {
result.append(String.format("%02X ", b));
}
toStrHelper.add("Value", result);
return toStrHelper.toString();
}
}
package org.onosproject.pcepio.types;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
/**
* Provides PceccCapabilityTlv.
*/
public class PceccCapabilityTlv implements PcepValueType {
/* PCECC CAPABILITY TLV
* Reference : draft-zhao-pce-pcep-extension-for-pce-controller-01, section-7.1.1
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type=32 | Length=4 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Flags |G|L|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
protected static final Logger log = LoggerFactory.getLogger(PceccCapabilityTlv.class);
public static final short TYPE = 32;
public static final short LENGTH = 4;
public static final int SET = 1;
public static final byte LFLAG_CHECK = 0x01;
public static final byte GFLAG_CHECK = 0x02;
private final boolean bGFlag;
private final boolean bLFlag;
private final int rawValue;
private final boolean isRawValueSet;
/**
* Constructor to initialize raw Value.
*
* @param rawValue raw value
*/
public PceccCapabilityTlv(final int rawValue) {
this.rawValue = rawValue;
this.isRawValueSet = true;
bLFlag = (rawValue & LFLAG_CHECK) == LFLAG_CHECK ? true : false;
bGFlag = (rawValue & GFLAG_CHECK) == GFLAG_CHECK ? true : false;
}
/**
* Constructor to initialize G-flag L-flag.
* @param bGFlag G-flag
* @param bLFlag L-flag
*/
public PceccCapabilityTlv(boolean bGFlag, boolean bLFlag) {
this.bGFlag = bGFlag;
this.bLFlag = bLFlag;
this.rawValue = 0;
this.isRawValueSet = false;
}
/**
* Returns newly created PceccCapabilityTlv object.
*
* @param raw value
* @return object of Pcecc Capability Tlv
*/
public static PceccCapabilityTlv of(final int raw) {
return new PceccCapabilityTlv(raw);
}
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
/**
* Returns G-flag.
* @return bGFlag G-flag
*/
public boolean getGFlag() {
return bGFlag;
}
/**
* Returns L-flag.
* @return bLFlag L-flag
*/
public boolean getLFlag() {
return bLFlag;
}
/**
* Returns the raw value.
* @return rawValue Flags
*/
public int getInt() {
return rawValue;
}
@Override
public short getType() {
return TYPE;
}
@Override
public short getLength() {
return LENGTH;
}
@Override
public int hashCode() {
if (isRawValueSet) {
return Objects.hash(rawValue);
} else {
return Objects.hash(bLFlag, bGFlag);
}
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof PceccCapabilityTlv) {
PceccCapabilityTlv other = (PceccCapabilityTlv) obj;
if (isRawValueSet) {
return Objects.equals(this.rawValue, other.rawValue);
} else {
return Objects.equals(this.bGFlag, other.bGFlag) && Objects.equals(this.bLFlag, other.bLFlag);
}
}
return false;
}
@Override
public int write(ChannelBuffer c) {
int iLenStartIndex = c.writerIndex();
int temp = 0;
c.writeShort(TYPE);
c.writeShort(LENGTH);
if (isRawValueSet) {
c.writeInt(rawValue);
} else {
if (bGFlag) {
temp = temp | GFLAG_CHECK;
}
if (bLFlag) {
temp = temp | LFLAG_CHECK;
}
c.writeInt(temp);
}
return c.writerIndex() - iLenStartIndex;
}
/**
* Reads channel buffer and returns object of PceccCapabilityTlv.
*
* @param c input channel buffer
* @return object of PceccCapabilityTlv
*/
public static PceccCapabilityTlv read(ChannelBuffer c) {
return PceccCapabilityTlv.of(c.readInt());
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH).add("Value", rawValue)
.toString();
}
}
package org.onosproject.pcepio.types;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
/**
* Provides CEP LABEL DB VERSION TLV which contains LSP State DB Version (32 Bit ).
*/
public class PcepLabelDbVerTlv implements PcepValueType {
/* PCEP LABEL DB VERSION TLV format
Reference : draft-ietf-pce-stateful-sync-optimizations-02, section 3.3.1
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type=23 | Length=8 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| LSP State DB Version |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
protected static final Logger log = LoggerFactory.getLogger(PcepLabelDbVerTlv.class);
public static final short TYPE = 34;
public static final short LENGTH = 8;
private final long rawValue;
/**
* constructor to initialize rawValue.
*
* @param rawValue of Pcep Label Db Version Tlv
*/
public PcepLabelDbVerTlv(final long rawValue) {
log.debug("PcepLabelDbVerTlv");
this.rawValue = rawValue;
}
/**
* Returns newly created PcepLabelDbVerTlv object.
*
* @param raw LSP State DB Version
* @return object of PcepLabelDbVerTlv
*/
public static PcepLabelDbVerTlv of(final long raw) {
return new PcepLabelDbVerTlv(raw);
}
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
/**
* Returns LSP State DB Version.
* @return raw value
*/
public long getLong() {
return rawValue;
}
@Override
public short getLength() {
return LENGTH;
}
@Override
public short getType() {
return TYPE;
}
@Override
public int hashCode() {
return Objects.hash(rawValue);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof PceccCapabilityTlv) {
PcepLabelDbVerTlv other = (PcepLabelDbVerTlv) obj;
return Objects.equals(this.rawValue, other.rawValue);
}
return false;
}
@Override
public int write(ChannelBuffer c) {
int iLenStartIndex = c.writerIndex();
c.writeShort(TYPE);
c.writeShort(LENGTH);
c.writeLong(rawValue);
return c.writerIndex() - iLenStartIndex;
}
/**
* Reads the channel buffer and returns object of PcepLabelDbVerTlv.
*
* @param c input channel buffer
* @return object of PcepLabelDbVerTlv
*/
public static PcepLabelDbVerTlv read(ChannelBuffer c) {
return PcepLabelDbVerTlv.of(c.readLong());
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH).add("Value", rawValue)
.toString();
}
}
/*
* Copyright 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.types;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.pcepio.exceptions.PcepParseException;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
/**
* Provides Remote TE Node Descriptors TLV.
*/
public class RemoteTENodeDescriptorsTLV implements PcepValueType {
/* Reference :PCEP Extension for Transporting TE Data
draft-dhodylee-pce-pcep-te-data-extn-02
*
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type=[TBD9] | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
// Node Descriptor Sub-TLVs (variable) //
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
protected static final Logger log = LoggerFactory.getLogger(RemoteTENodeDescriptorsTLV.class);
public static final short TYPE = 1003; //TODD:change this TBD9
public static short hLength;
public static final int TLV_HEADER_LENGTH = 4;
// Node Descriptor Sub-TLVs (variable)
private LinkedList<PcepValueType> llRemoteTENodeDescriptorSubTLVs;
/**
* Constructor to initialize llRemoteTENodeDescriptorSubTLVs.
*
* @param llRemoteTENodeDescriptorSubTLVs LinkedList of PcepValueType
*/
public RemoteTENodeDescriptorsTLV(LinkedList<PcepValueType> llRemoteTENodeDescriptorSubTLVs) {
this.llRemoteTENodeDescriptorSubTLVs = llRemoteTENodeDescriptorSubTLVs;
}
/**
* Returns object of Remote TE Node Descriptors TLV.
*
* @param llRemoteTENodeDescriptorSubTLVs LinkedList of PcepValueType
* @return object of RemoteTENodeDescriptorsTLV
*/
public static RemoteTENodeDescriptorsTLV of(final LinkedList<PcepValueType> llRemoteTENodeDescriptorSubTLVs) {
return new RemoteTENodeDescriptorsTLV(llRemoteTENodeDescriptorSubTLVs);
}
/**
* Returns Remote TE Node Descriptor Sub TLVs.
*
* @return llRemoteTENodeDescriptorSubTLVs
*/
public LinkedList<PcepValueType> getllRemoteTENodeDescriptorSubTLVs() {
return llRemoteTENodeDescriptorSubTLVs;
}
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
@Override
public short getType() {
return TYPE;
}
@Override
public short getLength() {
return hLength;
}
@Override
public int hashCode() {
return Objects.hash(llRemoteTENodeDescriptorSubTLVs.hashCode());
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
/*
* Here we have a list of Tlv so to compare each sub tlv between the object
* we have to take a list iterator so one by one we can get each sub tlv object
* and can compare them.
* it may be possible that the size of 2 lists is not equal so we have to first check
* the size, if both are same then we should check for the subtlv objects otherwise
* we should return false.
*/
if (obj instanceof RemoteTENodeDescriptorsTLV) {
int countObjSubTlv = 0;
int countOtherSubTlv = 0;
boolean isCommonSubTlv = true;
RemoteTENodeDescriptorsTLV other = (RemoteTENodeDescriptorsTLV) obj;
Iterator<PcepValueType> objListIterator = ((RemoteTENodeDescriptorsTLV) obj).llRemoteTENodeDescriptorSubTLVs
.iterator();
countObjSubTlv = ((RemoteTENodeDescriptorsTLV) obj).llRemoteTENodeDescriptorSubTLVs.size();
countOtherSubTlv = other.llRemoteTENodeDescriptorSubTLVs.size();
if (countObjSubTlv != countOtherSubTlv) {
return false;
} else {
while (objListIterator.hasNext() && isCommonSubTlv) {
PcepValueType subTlv = objListIterator.next();
isCommonSubTlv = Objects.equals(llRemoteTENodeDescriptorSubTLVs.contains(subTlv),
other.llRemoteTENodeDescriptorSubTLVs.contains(subTlv));
}
return isCommonSubTlv;
}
}
return false;
}
@Override
public int write(ChannelBuffer c) {
int tlvStartIndex = c.writerIndex();
c.writeShort(TYPE);
int tlvLenIndex = c.writerIndex();
hLength = 0;
c.writeShort(hLength);
ListIterator<PcepValueType> listIterator = llRemoteTENodeDescriptorSubTLVs.listIterator();
while (listIterator.hasNext()) {
PcepValueType tlv = listIterator.next();
if (null == tlv) {
log.debug("TLV is null from subTlv list");
continue;
}
tlv.write(c);
// need to take care of padding
int pad = tlv.getLength() % 4;
if (0 != pad) {
pad = 4 - pad;
for (int i = 0; i < pad; ++i) {
c.writeByte((byte) 0);
}
}
}
hLength = (short) (c.writerIndex() - tlvStartIndex);
c.setShort(tlvLenIndex, hLength);
return c.writerIndex() - tlvStartIndex;
}
/**
* Reads channel buffer and returns object of Remote TE Node Descriptors TLV.
*
* @param c input channel buffer
* @return object of RemoteTENodeDescriptorsTLV
* @throws PcepParseException if mandatory fields are missing
*/
public static PcepValueType read(ChannelBuffer c) throws PcepParseException {
// Node Descriptor Sub-TLVs (variable)
LinkedList<PcepValueType> llRemoteTENodeDescriptorSubTLVs = new LinkedList<PcepValueType>();
ChannelBuffer tempCb = c.readBytes(hLength - TLV_HEADER_LENGTH);
while (TLV_HEADER_LENGTH <= tempCb.readableBytes()) {
PcepValueType tlv;
short hType = tempCb.readShort();
int iValue = 0;
short hLength = tempCb.readShort();
switch (hType) {
case AutonomousSystemTlv.TYPE:
iValue = tempCb.readInt();
tlv = new AutonomousSystemTlv(iValue);
break;
case BGPLSidentifierTlv.TYPE:
iValue = tempCb.readInt();
tlv = new BGPLSidentifierTlv(iValue);
break;
case OSPFareaIDsubTlv.TYPE:
iValue = tempCb.readInt();
tlv = new OSPFareaIDsubTlv(iValue);
break;
case RouterIDSubTlv.TYPE:
tlv = RouterIDSubTlv.read(tempCb, hLength);
break;
default:
throw new PcepParseException("Unsupported Sub TLV type :" + hType);
}
// Check for the padding
int pad = hLength % 4;
if (0 < pad) {
pad = 4 - pad;
if (pad <= tempCb.readableBytes()) {
tempCb.skipBytes(pad);
}
}
llRemoteTENodeDescriptorSubTLVs.add(tlv);
}
if (0 < tempCb.readableBytes()) {
throw new PcepParseException("Sub Tlv parsing error. Extra bytes received.");
}
return new RemoteTENodeDescriptorsTLV(llRemoteTENodeDescriptorSubTLVs);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", hLength)
.add("RemoteTeNodeDescriptorSubTLVs", llRemoteTENodeDescriptorSubTLVs).toString();
}
}
/*
* Copyright 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.types;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;
/**
* Provides router id.
*/
public class RouterIDSubTlv implements PcepValueType {
/* reference :I-D.ietf-idr-ls-distribution.
* 0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type=[TBD13] | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| opaque value |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
protected static final Logger log = LoggerFactory.getLogger(RouterIDSubTlv.class);
public static final short TYPE = 1000; //TODD:change this TBD13
private final short hLength;
private final byte[] rawValue;
/**
* constructor to initialize rawValue.
*
* @param rawValue raw value
* @param hLength length
*/
public RouterIDSubTlv(byte[] rawValue, short hLength) {
this.rawValue = rawValue;
if (0 == hLength) {
this.hLength = (short) rawValue.length;
} else {
this.hLength = hLength;
}
}
/**
* Returns object of Router ID Sub Tlv.
*
* @param raw value
* @param hLength length
* @return object of Router ID Sub Tlv
*/
public static RouterIDSubTlv of(final byte[] raw, short hLength) {
return new RouterIDSubTlv(raw, hLength);
}
/**
* Returns raw value.
*
* @return rawValue value
*/
public byte[] getValue() {
return rawValue;
}
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
@Override
public short getType() {
return TYPE;
}
@Override
public short getLength() {
return hLength;
}
@Override
public int hashCode() {
return Objects.hash(rawValue);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof RouterIDSubTlv) {
RouterIDSubTlv other = (RouterIDSubTlv) obj;
return Objects.equals(this.rawValue, other.rawValue);
}
return false;
}
@Override
public int write(ChannelBuffer c) {
int iLenStartIndex = c.writerIndex();
c.writeShort(TYPE);
c.writeShort(hLength);
c.writeBytes(rawValue);
return c.writerIndex() - iLenStartIndex;
}
/**
* Reads channel buffer and returns object of RouterIDSubTlv.
*
* @param c input channel buffer
* @param hLength length
* @return object of RouterIDSubTlv
*/
public static PcepValueType read(ChannelBuffer c, short hLength) {
byte[] iOpaqueValue = new byte[hLength];
c.readBytes(iOpaqueValue, 0, hLength);
return new RouterIDSubTlv(iOpaqueValue, hLength);
}
@Override
public String toString() {
ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass());
toStrHelper.add("Type", TYPE);
toStrHelper.add("Length", hLength);
StringBuffer result = new StringBuffer();
for (byte b : rawValue) {
result.append(String.format("%02X ", b));
}
toStrHelper.add("Value", result);
return toStrHelper.toString();
}
}
/*
* Copyright 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.types;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
/**
* Provides RoutingUniverseTLV identifiers.
*/
public class RoutingUniverseTLV implements PcepValueType {
/*
* Reference : draft-dhodylee-pce-pcep-te-data-extn-02, section 9.2.1.
* 0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type=[TBD7] | Length=8 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Identifier |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
*
* +------------+---------------------+
| Identifier | Routing Universe |
+------------+---------------------+
| 0 | L3 packet topology |
| 1 | L1 optical topology |
+------------+---------------------+
*/
protected static final Logger log = LoggerFactory.getLogger(RoutingUniverseTLV.class);
public static final short TYPE = 14; // TODO:need to change TBD7
public static final short LENGTH = 8;
private final long rawValue;
/**
* Constructor to initialize raw value.
*
* @param rawValue raw value
*/
public RoutingUniverseTLV(long rawValue) {
this.rawValue = rawValue;
}
/**
* Returns object of RoutingUniverseTLV.
*
* @param raw value
* @return object of RoutingUniverseTLV
*/
public static RoutingUniverseTLV of(final long raw) {
return new RoutingUniverseTLV(raw);
}
/**
* Returns raw value as Identifier.
*
* @return rawValue Identifier
*/
public long getLong() {
return rawValue;
}
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
@Override
public short getType() {
return TYPE;
}
@Override
public short getLength() {
return LENGTH;
}
@Override
public int hashCode() {
return Objects.hash(rawValue);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof RoutingUniverseTLV) {
RoutingUniverseTLV other = (RoutingUniverseTLV) obj;
return Objects.equals(this.rawValue, other.rawValue);
}
return false;
}
@Override
public int write(ChannelBuffer c) {
int iLenStartIndex = c.writerIndex();
c.writeShort(TYPE);
c.writeShort(LENGTH);
c.writeLong(rawValue);
return c.writerIndex() - iLenStartIndex;
}
/**
* Reads from channel buffer and returns object of RoutingUniverseTLV.
*
* @param c input channel buffer
* @return object of RoutingUniverseTLV
*/
public static RoutingUniverseTLV read(ChannelBuffer c) {
return RoutingUniverseTLV.of(c.readLong());
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH).add("Value", rawValue)
.toString();
}
}
/*
* Copyright 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.types;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;
/**
* Provides SharedRiskLinkGroupTlv.
*/
public class SharedRiskLinkGroupTlv implements PcepValueType {
/*
* Reference :[I-D.ietf-idr- Group ls-distribution] /3.3.2.5
*
* 0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type =TDB41 | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Shared Risk Link Group Value |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// ............ //
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Shared Risk Link Group Value |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
protected static final Logger log = LoggerFactory.getLogger(SharedRiskLinkGroupTlv.class);
public static final short TYPE = 1096; //TODO:NEED TO HANDLE TDB41
private final short hLength;
private final int[] srlgValue;
/**
* Constructor to initialize SRLG value.
*
* @param srlgValue Shared Risk Link Group Value
* @param hLength length
*/
public SharedRiskLinkGroupTlv(int[] srlgValue, short hLength) {
this.srlgValue = srlgValue;
if (0 == hLength) {
this.hLength = (short) ((srlgValue.length) * 4);
} else {
this.hLength = hLength;
}
}
/**
* Returns object of SharedRiskLinkGroupTlv.
*
* @param raw value
* @param hLength length
* @return object of SharedRiskLinkGroupTlv
*/
public static SharedRiskLinkGroupTlv of(final int[] raw, short hLength) {
return new SharedRiskLinkGroupTlv(raw, hLength);
}
/**
* Returns SRLG Value.
*
* @return srlgValue
*/
public int[] getValue() {
return srlgValue;
}
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
@Override
public short getType() {
return TYPE;
}
@Override
public short getLength() {
return hLength;
}
@Override
public int hashCode() {
return Objects.hash(srlgValue);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof SharedRiskLinkGroupTlv) {
SharedRiskLinkGroupTlv other = (SharedRiskLinkGroupTlv) obj;
return Objects.equals(this.srlgValue, other.srlgValue);
}
return false;
}
@Override
public int write(ChannelBuffer c) {
int iLenStartIndex = c.writerIndex();
c.writeShort(TYPE);
c.writeShort(hLength);
for (int b : srlgValue) {
c.writeInt(b);
}
return c.writerIndex() - iLenStartIndex;
}
/**
* Reads from channel buffer and returns object of SharedRiskLinkGroupTlv.
*
* @param c input channel buffer
* @param hLength length
* @return object of SharedRiskLinkGroupTlv
*/
public static PcepValueType read(ChannelBuffer c, short hLength) {
int iLength = hLength / 4;
int[] iSharedRiskLinkGroup = new int[iLength];
for (int i = 0; i < iLength; i++) {
iSharedRiskLinkGroup[i] = c.readInt();
}
return new SharedRiskLinkGroupTlv(iSharedRiskLinkGroup, hLength);
}
@Override
public String toString() {
ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass());
toStrHelper.add("Type", TYPE);
toStrHelper.add("Length", hLength);
StringBuffer result = new StringBuffer();
for (int b : srlgValue) {
result.append(String.format("%02X ", b));
}
toStrHelper.add("Value", result);
return toStrHelper.toString();
}
}
/*
* Copyright 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.types;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
/**
* Provides StatefulLspDbVerTlv.
*/
public class StatefulLspDbVerTlv implements PcepValueType {
/* LSP-DB-VERSION TLV format
*
* Reference : Optimizations of Label Switched Path State Synchronization Procedures
for a Stateful PCE draft-ietf-pce-stateful-sync-optimizations-02
*
*
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type=23 | Length=8 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| LSP State DB Version |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
protected static final Logger log = LoggerFactory.getLogger(StatefulLspDbVerTlv.class);
public static final short TYPE = 23;
public static final short LENGTH = 8;
private final long rawValue;
/**
* Constructor to initialize rawValue.
*
* @param rawValue value
*/
public StatefulLspDbVerTlv(final long rawValue) {
this.rawValue = rawValue;
}
/**
* Returns object of StatefulLspDbVerTlv.
*
* @param raw is LSP State DB Version
* @return object of StatefulLspDbVerTlv
*/
public static StatefulLspDbVerTlv of(final long raw) {
return new StatefulLspDbVerTlv(raw);
}
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
/**
* Returns LSP State DB Version.
*
* @return rawValue value
*/
public long getLong() {
return rawValue;
}
@Override
public short getLength() {
return LENGTH;
}
@Override
public short getType() {
return TYPE;
}
@Override
public int hashCode() {
return Objects.hash(rawValue);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof StatefulLspDbVerTlv) {
StatefulLspDbVerTlv other = (StatefulLspDbVerTlv) obj;
return Objects.equals(this.rawValue, other.rawValue);
}
return false;
}
@Override
public int write(ChannelBuffer c) {
c.writeShort(TYPE);
c.writeShort(LENGTH);
c.writeLong(rawValue);
return c.writerIndex();
}
/**
* Reads the channel buffer and returns object of StatefulLspDbVerTlv.
*
* @param c input channel buffer
* @return object of StatefulLspDbVerTlv
*/
public static StatefulLspDbVerTlv read(ChannelBuffer c) {
return StatefulLspDbVerTlv.of(c.readLong());
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH).add("Value", rawValue)
.toString();
}
}
/*
* Copyright 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.types;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
/**
* Provides StatefulPceCapabilityTlv.
*/
public class StatefulPceCapabilityTlv implements PcepValueType {
/* STATEFUL-PCE-CAPABILITY TLV format
*
* Reference :PCEP Extensions for Stateful PCE draft-ietf-pce-stateful-pce-10
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type=16 | Length=4 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Flags |D|T|I|S|U|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
protected static final Logger log = LoggerFactory.getLogger(StatefulPceCapabilityTlv.class);
public static final short TYPE = 16;
public static final short LENGTH = 4;
public static final byte UFLAG_SET = 0x01;
public static final byte SFLAG_SET = 0x02;
public static final byte IFLAG_SET = 0x04;
public static final byte TFLAG_SET = 0x08;
public static final byte DFLAG_SET = 0x10;
public static final int SET = 1;
private final int rawValue;
private final boolean bDFlag;
private final boolean bTFlag;
private final boolean bIFlag;
private final boolean bSFlag;
private final boolean bUFlag;
private final boolean isRawValueSet;
/**
* Constructor to initialize variables.
*
* @param rawValue Flags
*/
public StatefulPceCapabilityTlv(int rawValue) {
this.rawValue = rawValue;
isRawValueSet = true;
this.bUFlag = (rawValue & UFLAG_SET) == UFLAG_SET ? true : false;
this.bSFlag = (rawValue & SFLAG_SET) == SFLAG_SET ? true : false;
this.bIFlag = (rawValue & IFLAG_SET) == IFLAG_SET ? true : false;
this.bTFlag = (rawValue & TFLAG_SET) == TFLAG_SET ? true : false;
this.bDFlag = (rawValue & DFLAG_SET) == DFLAG_SET ? true : false;
}
/**
* Constructor to initialize variables.
*
* @param bDFlag D-flag
* @param bTFlag T-flag
* @param bIFlag I-flag
* @param bSFlag S-flag
* @param bUFlag U-flag
*/
public StatefulPceCapabilityTlv(boolean bDFlag, boolean bTFlag, boolean bIFlag, boolean bSFlag, boolean bUFlag) {
this.bDFlag = bDFlag;
this.bTFlag = bTFlag;
this.bIFlag = bIFlag;
this.bSFlag = bSFlag;
this.bUFlag = bUFlag;
this.rawValue = 0;
isRawValueSet = false;
}
/**
* Returns object of StatefulPceCapabilityTlv.
*
* @param raw value Flags
* @return object of StatefulPceCapabilityTlv
*/
public static StatefulPceCapabilityTlv of(final int raw) {
return new StatefulPceCapabilityTlv(raw);
}
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
/**
* Returns D-flag.
*
* @return bDFlag D-flag
*/
public boolean getDFlag() {
return bDFlag;
}
/**
* Returns T-flag.
*
* @return bTFlag T-flag
*/
public boolean getTFlag() {
return bTFlag;
}
/**
* Returns I-flag.
*
* @return bIFlag I-flag
*/
public boolean getIFlag() {
return bIFlag;
}
/**
* Returns S-flag.
*
* @return bSFlag S-flag
*/
public boolean getSFlag() {
return bSFlag;
}
/**
* Returns U-flag.
*
* @return bUFlag U-flag
*/
public boolean getUFlag() {
return bUFlag;
}
/**
* Returns raw value Flags.
*
* @return rawValue Flags
*/
public int getInt() {
return rawValue;
}
@Override
public short getType() {
return TYPE;
}
@Override
public short getLength() {
return LENGTH;
}
@Override
public int hashCode() {
if (isRawValueSet) {
return Objects.hash(rawValue);
} else {
return Objects.hash(bDFlag, bTFlag, bIFlag, bSFlag, bUFlag);
}
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof StatefulPceCapabilityTlv) {
StatefulPceCapabilityTlv other = (StatefulPceCapabilityTlv) obj;
if (isRawValueSet) {
return Objects.equals(this.rawValue, other.rawValue);
} else {
return Objects.equals(this.bDFlag, other.bDFlag) && Objects.equals(this.bTFlag, other.bTFlag)
&& Objects.equals(this.bIFlag, other.bIFlag) && Objects.equals(this.bSFlag, other.bSFlag)
&& Objects.equals(this.bUFlag, other.bUFlag);
}
}
return false;
}
@Override
public int write(ChannelBuffer c) {
int iLenStartIndex = c.writerIndex();
c.writeShort(TYPE);
c.writeShort(LENGTH);
if (isRawValueSet) {
c.writeInt(rawValue);
} else {
int temp = 0;
if (bUFlag) {
temp = temp | UFLAG_SET;
}
if (bSFlag) {
temp = temp | SFLAG_SET;
}
if (bIFlag) {
temp = temp | IFLAG_SET;
}
if (bTFlag) {
temp = temp | TFLAG_SET;
}
if (bDFlag) {
temp = temp | DFLAG_SET;
}
c.writeInt(temp);
}
return c.writerIndex() - iLenStartIndex;
}
/**
* Reads from channel buffer and returns object of StatefulPceCapabilityTlv.
*
* @param c input channel buffer
* @return object of StatefulPceCapabilityTlv
*/
public static PcepValueType read(ChannelBuffer c) {
int temp = c.readInt();
boolean bDFlag;
boolean bTFlag;
boolean bIFlag;
boolean bSFlag;
boolean bUFlag;
bUFlag = (temp & UFLAG_SET) == UFLAG_SET ? true : false;
bSFlag = (temp & SFLAG_SET) == SFLAG_SET ? true : false;
bIFlag = (temp & IFLAG_SET) == IFLAG_SET ? true : false;
bTFlag = (temp & TFLAG_SET) == TFLAG_SET ? true : false;
bDFlag = (temp & DFLAG_SET) == DFLAG_SET ? true : false;
return new StatefulPceCapabilityTlv(bDFlag, bTFlag, bIFlag, bSFlag, bUFlag);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass()).add("type", TYPE).add("Length", LENGTH).add("DFlag", bDFlag)
.add("TFlag", bTFlag).add("IFlag", bIFlag).add("SFlag", bSFlag).add("UFlag", bUFlag).toString();
}
}
/*
* Copyright 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.types;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
/**
* Provides TEDefaultMetricTlv.
*/
public class TEDefaultMetricTlv implements PcepValueType {
/*
* Reference :| [I-D.ietf-idr- ls-distribution] /3.3.2.3
* 0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type=TDB37 | Length=4 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| TE Default Link Metric |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
protected static final Logger log = LoggerFactory.getLogger(TEDefaultMetricTlv.class);
public static final short TYPE = 13400; //TDB37
public static final short LENGTH = 4;
private final int rawValue;
/**
* Constructor to initialize rawValue.
*
* @param rawValue TE Default Link Metric
*/
public TEDefaultMetricTlv(int rawValue) {
this.rawValue = rawValue;
}
/**
* Returns newly created TEDefaultMetricTlv object.
*
* @param raw raw value
* @return object of TEDefaultMetricTlv.
*/
public static TEDefaultMetricTlv of(final int raw) {
return new TEDefaultMetricTlv(raw);
}
/**
* Returns raw value.
*
* @return rawValue TE Default Link Metric
*/
public int getInt() {
return rawValue;
}
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
@Override
public short getType() {
return TYPE;
}
@Override
public short getLength() {
return LENGTH;
}
@Override
public int hashCode() {
return Objects.hash(rawValue);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof TEDefaultMetricTlv) {
TEDefaultMetricTlv other = (TEDefaultMetricTlv) obj;
return Objects.equals(this.rawValue, other.rawValue);
}
return false;
}
@Override
public int write(ChannelBuffer c) {
int iLenStartIndex = c.writerIndex();
c.writeShort(TYPE);
c.writeShort(LENGTH);
c.writeInt(rawValue);
return c.writerIndex() - iLenStartIndex;
}
/**
* Reads channel buffer and returns object of TEDefaultMetricTlv.
*
* @param c input channel buffer
* @return object of TEDefaultMetricTlv
*/
public static TEDefaultMetricTlv read(ChannelBuffer c) {
return TEDefaultMetricTlv.of(c.readInt());
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH).add("Value", rawValue)
.toString();
}
}
/*
* Copyright 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.types;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.pcepio.exceptions.PcepParseException;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
/**
* Provides TELinkAttributesTlv.
*/
public class TELinkAttributesTlv implements PcepValueType {
/*
* Reference :PCEP Extension for Transporting TE Data draft-dhodylee-pce-pcep-te-data-extn-02
* 0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type=[TBD27] | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
// Link Attributes Sub-TLVs (variable) //
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
protected static final Logger log = LoggerFactory.getLogger(TELinkAttributesTlv.class);
public static final short TYPE = 1897; //TODD:change this TBD27
public short hLength;
public static final int TLV_HEADER_LENGTH = 4;
// LinkDescriptors Sub-TLVs (variable)
private LinkedList<PcepValueType> llLinkAttributesSubTLVs;
/**
* Constructor to initialize Link Attributes Sub TLVs.
*
* @param llLinkAttributesSubTLVs linked list of PcepValueType
*/
public TELinkAttributesTlv(LinkedList<PcepValueType> llLinkAttributesSubTLVs) {
this.llLinkAttributesSubTLVs = llLinkAttributesSubTLVs;
}
/**
* Returns object of TE Link Attributes TLV.
*
* @param llLinkAttributesSubTLVs linked list of Link Attribute of Sub TLV
* @return object of TELinkAttributesTlv
*/
public static TELinkAttributesTlv of(final LinkedList<PcepValueType> llLinkAttributesSubTLVs) {
return new TELinkAttributesTlv(llLinkAttributesSubTLVs);
}
/**
* Returns linked list of Link Attribute of Sub TLV.
*
* @return llLinkAttributesSubTLVs linked list of Link Attribute of Sub TLV
*/
public LinkedList<PcepValueType> getllLinkAttributesSubTLVs() {
return llLinkAttributesSubTLVs;
}
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
@Override
public short getType() {
return TYPE;
}
@Override
public short getLength() {
return hLength;
}
@Override
public int hashCode() {
return Objects.hash(llLinkAttributesSubTLVs.hashCode());
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
/*
* Here we have a list of Tlv so to compare each sub tlv between the object
* we have to take a list iterator so one by one we can get each sub tlv object
* and can compare them.
* it may be possible that the size of 2 lists is not equal so we have to first check
* the size, if both are same then we should check for the subtlv objects otherwise
* we should return false.
*/
if (obj instanceof TELinkAttributesTlv) {
int countObjSubTlv = 0;
int countOtherSubTlv = 0;
boolean isCommonSubTlv = true;
TELinkAttributesTlv other = (TELinkAttributesTlv) obj;
Iterator<PcepValueType> objListIterator = ((TELinkAttributesTlv) obj).llLinkAttributesSubTLVs.iterator();
countObjSubTlv = ((TELinkAttributesTlv) obj).llLinkAttributesSubTLVs.size();
countOtherSubTlv = other.llLinkAttributesSubTLVs.size();
if (countObjSubTlv != countOtherSubTlv) {
return false;
} else {
while (objListIterator.hasNext() && isCommonSubTlv) {
PcepValueType subTlv = objListIterator.next();
isCommonSubTlv = Objects.equals(llLinkAttributesSubTLVs.contains(subTlv),
other.llLinkAttributesSubTLVs.contains(subTlv));
}
return isCommonSubTlv;
}
}
return false;
}
@Override
public int write(ChannelBuffer c) {
int tlvStartIndex = c.writerIndex();
c.writeShort(TYPE);
int tlvLenIndex = c.writerIndex();
hLength = 0;
c.writeShort(hLength);
ListIterator<PcepValueType> listIterator = llLinkAttributesSubTLVs.listIterator();
while (listIterator.hasNext()) {
PcepValueType tlv = listIterator.next();
if (null == tlv) {
log.debug("TLV is null from subTlv list");
continue;
}
tlv.write(c);
// need to take care of padding
int pad = tlv.getLength() % 4;
if (0 != pad) {
pad = 4 - pad;
for (int i = 0; i < pad; ++i) {
c.writeByte((byte) 0);
}
}
}
hLength = (short) (c.writerIndex() - tlvStartIndex);
c.setShort(tlvLenIndex, hLength);
return c.writerIndex() - tlvStartIndex;
}
/**
* Reads channel buffer and returns object of TE Link Attributes TLV.
*
* @param c input channel buffer
* @param hLength length
* @return object of TELinkAttributesTlv
* @throws PcepParseException if mandatory fields are missing
*/
public static PcepValueType read(ChannelBuffer c, short hLength) throws PcepParseException {
// Node Descriptor Sub-TLVs (variable)
LinkedList<PcepValueType> llLinkAttributesSubTLVs = new LinkedList<PcepValueType>();
ChannelBuffer tempCb = c.readBytes(hLength - TLV_HEADER_LENGTH);
while (TLV_HEADER_LENGTH <= tempCb.readableBytes()) {
PcepValueType tlv;
short hType = tempCb.readShort();
int iValue = 0;
short length = tempCb.readShort();
switch (hType) {
case IPv4TERouterIdOfLocalNodeTlv.TYPE:
iValue = tempCb.readInt();
tlv = new IPv4TERouterIdOfLocalNodeTlv(iValue);
break;
case IPv6TERouterIdofLocalNodeTlv.TYPE:
byte[] ipv6LValue = new byte[IPv6TERouterIdofLocalNodeTlv.VALUE_LENGTH];
tempCb.readBytes(ipv6LValue, 0, IPv6TERouterIdofLocalNodeTlv.VALUE_LENGTH);
tlv = new IPv6TERouterIdofLocalNodeTlv(ipv6LValue);
break;
case IPv4TERouterIdOfRemoteNodeTlv.TYPE:
iValue = tempCb.readInt();
tlv = new IPv4TERouterIdOfRemoteNodeTlv(iValue);
break;
case IPv6TERouterIdofRemoteNodeTlv.TYPE:
byte[] ipv6RValue = new byte[IPv6TERouterIdofRemoteNodeTlv.VALUE_LENGTH];
tempCb.readBytes(ipv6RValue, 0, IPv6TERouterIdofRemoteNodeTlv.VALUE_LENGTH);
tlv = new IPv6TERouterIdofRemoteNodeTlv(ipv6RValue);
break;
case LinkLocalRemoteIdentifiersTlv.TYPE:
tlv = LinkLocalRemoteIdentifiersTlv.read(tempCb);
break;
case AdministrativeGroupTlv.TYPE:
iValue = tempCb.readInt();
tlv = new AdministrativeGroupTlv(iValue);
break;
case MaximumLinkBandwidthTlv.TYPE:
iValue = tempCb.readInt();
tlv = new MaximumLinkBandwidthTlv(iValue);
break;
case MaximumReservableLinkBandwidthTlv.TYPE:
iValue = tempCb.readInt();
tlv = new MaximumReservableLinkBandwidthTlv(iValue);
break;
case UnreservedBandwidthTlv.TYPE:
iValue = tempCb.readInt();
tlv = new UnreservedBandwidthTlv(iValue);
break;
case TEDefaultMetricTlv.TYPE:
iValue = tempCb.readInt();
tlv = new TEDefaultMetricTlv(iValue);
break;
case LinkProtectionTypeTlv.TYPE:
tlv = LinkProtectionTypeTlv.read(tempCb);
break;
case MPLSProtocolMaskTlv.TYPE:
byte cValue = tempCb.readByte();
tlv = new MPLSProtocolMaskTlv(cValue);
break;
case IGPMetricTlv.TYPE:
tlv = IGPMetricTlv.read(tempCb, length);
break;
case SharedRiskLinkGroupTlv.TYPE:
tlv = SharedRiskLinkGroupTlv.read(tempCb, length);
break;
case OpaqueLinkAttributeTlv.TYPE:
tlv = OpaqueLinkAttributeTlv.read(tempCb, length);
break;
case LinkNameTlv.TYPE:
tlv = LinkNameTlv.read(tempCb, length);
break;
default:
throw new PcepParseException("Unsupported Sub TLV type :" + hType);
}
// Check for the padding
int pad = length % 4;
if (0 < pad) {
pad = 4 - pad;
if (pad <= tempCb.readableBytes()) {
tempCb.skipBytes(pad);
}
}
llLinkAttributesSubTLVs.add(tlv);
}
if (0 < tempCb.readableBytes()) {
throw new PcepParseException("Sub Tlv parsing error. Extra bytes received.");
}
return new TELinkAttributesTlv(llLinkAttributesSubTLVs);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", hLength)
.add("LinkAttributesSubTLVs", llLinkAttributesSubTLVs).toString();
}
}
/*
* Copyright 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.types;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.pcepio.exceptions.PcepParseException;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
/**
* Provides TE Link Descriptors TLV.
*/
public class TELinkDescriptorsTLV implements PcepValueType {
/*
* Reference: PCEP Extension for Transporting TE Data draft-dhodylee-pce-pcep-te-data-extn-02
* 0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type=[TBD14] | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
// Link Descriptor Sub-TLVs (variable) //
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
protected static final Logger log = LoggerFactory.getLogger(TELinkDescriptorsTLV.class);
public static final short TYPE = 1070; //TODD:change this TBD14
public short hLength;
public static final int TLV_HEADER_LENGTH = 4;
// LinkDescriptors Sub-TLVs (variable)
private LinkedList<PcepValueType> llLinkDescriptorsSubTLVs;
/**
* Constructor to initialize llLinkDescriptorsSubTLVs.
*
* @param llLinkDescriptorsSubTLVs of PcepValueType
*/
public TELinkDescriptorsTLV(LinkedList<PcepValueType> llLinkDescriptorsSubTLVs) {
this.llLinkDescriptorsSubTLVs = llLinkDescriptorsSubTLVs;
}
/**
* Returns object of TELinkDescriptorsTLV.
*
* @param llLinkDescriptorsSubTLVs of PcepValueType
* @return object of TELinkDescriptorsTLV
*/
public static TELinkDescriptorsTLV of(final LinkedList<PcepValueType> llLinkDescriptorsSubTLVs) {
return new TELinkDescriptorsTLV(llLinkDescriptorsSubTLVs);
}
/**
* Returns linked list of Link Attribute of Sub TLV.
*
* @return llLinkDescriptorsSubTLVs linked list of Link Attribute of Sub TLV
*/
public LinkedList<PcepValueType> getllLinkDescriptorsSubTLVs() {
return llLinkDescriptorsSubTLVs;
}
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
@Override
public short getType() {
return TYPE;
}
@Override
public short getLength() {
return hLength;
}
@Override
public int hashCode() {
return Objects.hash(llLinkDescriptorsSubTLVs.hashCode());
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
/*
* Here we have a list of Tlv so to compare each sub tlv between the object
* we have to take a list iterator so one by one we can get each sub tlv object
* and can compare them.
* it may be possible that the size of 2 lists is not equal so we have to first check
* the size, if both are same then we should check for the subtlv objects otherwise
* we should return false.
*/
if (obj instanceof TELinkDescriptorsTLV) {
int countObjSubTlv = 0;
int countOtherSubTlv = 0;
boolean isCommonSubTlv = true;
TELinkDescriptorsTLV other = (TELinkDescriptorsTLV) obj;
Iterator<PcepValueType> objListIterator = ((TELinkDescriptorsTLV) obj).llLinkDescriptorsSubTLVs.iterator();
countObjSubTlv = ((TELinkDescriptorsTLV) obj).llLinkDescriptorsSubTLVs.size();
countOtherSubTlv = other.llLinkDescriptorsSubTLVs.size();
if (countObjSubTlv != countOtherSubTlv) {
return false;
} else {
while (objListIterator.hasNext() && isCommonSubTlv) {
PcepValueType subTlv = objListIterator.next();
isCommonSubTlv = Objects.equals(llLinkDescriptorsSubTLVs.contains(subTlv),
other.llLinkDescriptorsSubTLVs.contains(subTlv));
}
return isCommonSubTlv;
}
}
return false;
}
@Override
public int write(ChannelBuffer c) {
int tlvStartIndex = c.writerIndex();
c.writeShort(TYPE);
int tlvLenIndex = c.writerIndex();
hLength = 0;
c.writeShort(hLength);
ListIterator<PcepValueType> listIterator = llLinkDescriptorsSubTLVs.listIterator();
while (listIterator.hasNext()) {
PcepValueType tlv = listIterator.next();
tlv.write(c);
// need to take care of padding
int pad = tlv.getLength() % 4;
if (0 != pad) {
pad = 4 - pad;
for (int i = 0; i < pad; ++i) {
c.writeByte((byte) 0);
}
}
}
hLength = (short) (c.writerIndex() - tlvStartIndex);
c.setShort(tlvLenIndex, hLength);
return c.writerIndex() - tlvStartIndex;
}
/**
* Reads channel buffer and returns object of TELinkDescriptorsTLV.
*
* @param c input channel buffer
* @param length length
* @return object of TELinkDescriptorsTLV
* @throws PcepParseException if mandatory fields are missing
*/
public static PcepValueType read(ChannelBuffer c, short length) throws PcepParseException {
// Node Descriptor Sub-TLVs (variable)
LinkedList<PcepValueType> llLinkDescriptorsSubTLVs = new LinkedList<PcepValueType>();
ChannelBuffer tempCb = c.readBytes(length - TLV_HEADER_LENGTH);
while (TLV_HEADER_LENGTH <= tempCb.readableBytes()) {
PcepValueType tlv;
short hType = tempCb.readShort();
int iValue = 0;
short hLength = tempCb.readShort();
log.debug("sub Tlv Length" + hLength);
switch (hType) {
case LinkLocalRemoteIdentifiersTlv.TYPE:
tlv = LinkLocalRemoteIdentifiersTlv.read(tempCb);
break;
case IPv4InterfaceAddressTlv.TYPE:
iValue = tempCb.readInt();
tlv = new IPv4InterfaceAddressTlv(iValue);
break;
case IPv4NeighborAddressTlv.TYPE:
iValue = tempCb.readInt();
tlv = new IPv4NeighborAddressTlv(iValue);
break;
case IPv6InterfaceAddressTlv.TYPE:
byte[] ipv6Value = new byte[IPv6InterfaceAddressTlv.VALUE_LENGTH];
tempCb.readBytes(ipv6Value, 0, IPv6InterfaceAddressTlv.VALUE_LENGTH);
tlv = new IPv6InterfaceAddressTlv(ipv6Value);
break;
case IPv6NeighborAddressTlv.TYPE:
byte[] ipv6NeighborAdd = new byte[IPv6NeighborAddressTlv.VALUE_LENGTH];
tempCb.readBytes(ipv6NeighborAdd, 0, IPv6NeighborAddressTlv.VALUE_LENGTH);
tlv = new IPv6NeighborAddressTlv(ipv6NeighborAdd);
break;
default:
throw new PcepParseException("Unsupported Sub TLV type:" + hType);
}
// Check for the padding
int pad = hLength % 4;
if (0 < pad) {
pad = 4 - pad;
if (pad <= tempCb.readableBytes()) {
tempCb.skipBytes(pad);
}
}
llLinkDescriptorsSubTLVs.add(tlv);
}
if (0 < tempCb.readableBytes()) {
throw new PcepParseException("Sub Tlv parsing error. Extra bytes received.");
}
return new TELinkDescriptorsTLV(llLinkDescriptorsSubTLVs);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", hLength)
.add("LinkDescriptorsSubTLVs", llLinkDescriptorsSubTLVs).toString();
}
}
/*
* Copyright 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.types;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.pcepio.exceptions.PcepParseException;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
public class TENodeAttributesTlv implements PcepValueType {
/*
* Reference :PCEP Extension for Transporting TE Data draft-dhodylee-pce-pcep-te-data-extn-02
*
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type=[TBD20] | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
// Node Attributes Sub-TLVs (variable) //
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
protected static final Logger log = LoggerFactory.getLogger(TENodeAttributesTlv.class);
public static final short TYPE = 1267; //TODD:change this TBD20
public short hLength;
public static final int TLV_HEADER_LENGTH = 4;
// LinkDescriptors Sub-TLVs (variable)
private LinkedList<PcepValueType> llNodeAttributesSubTLVs;
/**
* Constructor to initialize llNodeAttributesSubTLVs.
*
* @param llNodeAttributesSubTLVs linked list of Node Attributes Sub-TLVs
*/
public TENodeAttributesTlv(LinkedList<PcepValueType> llNodeAttributesSubTLVs) {
this.llNodeAttributesSubTLVs = llNodeAttributesSubTLVs;
}
/**
* Returns object of TENodeAttributesTlv.
*
* @param llNodeAttributesSubTLVs LinkedList of PcepValueType
* @return object of TENodeAttributesTlv
*/
public static TENodeAttributesTlv of(LinkedList<PcepValueType> llNodeAttributesSubTLVs) {
return new TENodeAttributesTlv(llNodeAttributesSubTLVs);
}
/**
* Returns Node Attributes Sub-TLVs.
*
* @return llNodeAttributesSubTLVs linked list of Node Attributes Sub-TLVs
*/
public LinkedList<PcepValueType> getllNodeAttributesSubTLVs() {
return llNodeAttributesSubTLVs;
}
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
@Override
public short getType() {
return TYPE;
}
@Override
public short getLength() {
return hLength;
}
@Override
public int hashCode() {
return Objects.hash(llNodeAttributesSubTLVs.hashCode());
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
/*
* Here we have a list of Tlv so to compare each sub tlv between the object
* we have to take a list iterator so one by one we can get each sub tlv object
* and can compare them.
* it may be possible that the size of 2 lists is not equal so we have to first check
* the size, if both are same then we should check for the subtlv objects otherwise
* we should return false.
*/
if (obj instanceof TENodeAttributesTlv) {
int countObjSubTlv = 0;
int countOtherSubTlv = 0;
boolean isCommonSubTlv = true;
TENodeAttributesTlv other = (TENodeAttributesTlv) obj;
Iterator<PcepValueType> objListIterator = ((TENodeAttributesTlv) obj).llNodeAttributesSubTLVs.iterator();
countObjSubTlv = ((TENodeAttributesTlv) obj).llNodeAttributesSubTLVs.size();
countOtherSubTlv = other.llNodeAttributesSubTLVs.size();
if (countObjSubTlv != countOtherSubTlv) {
return false;
} else {
while (objListIterator.hasNext() && isCommonSubTlv) {
PcepValueType subTlv = objListIterator.next();
isCommonSubTlv = Objects.equals(llNodeAttributesSubTLVs.contains(subTlv),
other.llNodeAttributesSubTLVs.contains(subTlv));
}
return isCommonSubTlv;
}
}
return false;
}
@Override
public int write(ChannelBuffer c) {
int tlvStartIndex = c.writerIndex();
c.writeShort(TYPE);
int tlvLenIndex = c.writerIndex();
hLength = 0;
c.writeShort(hLength);
ListIterator<PcepValueType> listIterator = llNodeAttributesSubTLVs.listIterator();
while (listIterator.hasNext()) {
PcepValueType tlv = listIterator.next();
tlv.write(c);
// need to take care of padding
int pad = tlv.getLength() % 4;
if (0 != pad) {
pad = 4 - pad;
for (int i = 0; i < pad; ++i) {
c.writeByte((byte) 0);
}
}
}
hLength = (short) (c.writerIndex() - tlvStartIndex);
c.setShort(tlvLenIndex, hLength);
return c.writerIndex() - tlvStartIndex;
}
/**
* Reads the channel buffer and returns object of TENodeAttributesTlv.
*
* @param c input channel buffer
* @param hLength length
* @return object of TENodeAttributesTlv
* @throws PcepParseException if mandatory fields are missing
*/
public static PcepValueType read(ChannelBuffer c, short hLength) throws PcepParseException {
// Node Descriptor Sub-TLVs (variable)
LinkedList<PcepValueType> llNodeAttributesSubTLVs = new LinkedList<PcepValueType>();
ChannelBuffer tempCb = c.readBytes(hLength - TLV_HEADER_LENGTH);
while (TLV_HEADER_LENGTH <= tempCb.readableBytes()) {
PcepValueType tlv;
short hType = tempCb.readShort();
int iValue = 0;
short length = tempCb.readShort();
switch (hType) {
case NodeFlagBitsTlv.TYPE:
byte cValue = tempCb.readByte();
tlv = new NodeFlagBitsTlv(cValue);
break;
case OpaqueNodeAttributeTlv.TYPE:
tlv = OpaqueNodeAttributeTlv.read(tempCb, length);
break;
case NodeNameTlv.TYPE:
tlv = NodeNameTlv.read(tempCb, length);
break;
case ISISAreaIdentifierTlv.TYPE:
tlv = ISISAreaIdentifierTlv.read(tempCb, length);
break;
case IPv4TERouterIdOfLocalNodeTlv.TYPE:
iValue = tempCb.readInt();
tlv = new IPv4TERouterIdOfLocalNodeTlv(iValue);
break;
case IPv6TERouterIdofLocalNodeTlv.TYPE:
byte[] ipv6Value = new byte[IPv6TERouterIdofLocalNodeTlv.VALUE_LENGTH];
tempCb.readBytes(ipv6Value, 0, IPv6TERouterIdofLocalNodeTlv.VALUE_LENGTH);
tlv = new IPv6TERouterIdofLocalNodeTlv(ipv6Value);
break;
default:
throw new PcepParseException("Unsupported Sub TLV type :" + hType);
}
// Check for the padding
int pad = length % 4;
if (0 < pad) {
pad = 4 - pad;
if (pad <= tempCb.readableBytes()) {
tempCb.skipBytes(pad);
}
}
llNodeAttributesSubTLVs.add(tlv);
}
if (0 < tempCb.readableBytes()) {
throw new PcepParseException("Sub Tlv parsing error. Extra bytes received.");
}
return new TENodeAttributesTlv(llNodeAttributesSubTLVs);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", hLength)
.add("NodeAttributesSubTLVs", llNodeAttributesSubTLVs).toString();
}
}
/*
* Copyright 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.types;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
/**
* Provides TED Capability Tlv.
*/
public class TedCapabilityTlv implements PcepValueType {
/*
* Reference :PCEP Extension for Transporting TE Data draft-dhodylee-pce-pcep-te-data-extn-02
* 0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type=[TBD5] | Length=4 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Flags |R|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
protected static final Logger log = LoggerFactory.getLogger(TedCapabilityTlv.class);
public static final short TYPE = 132; //TODO: need to change this TBD5
public static final short LENGTH = 4;
public static final int SET = 1;
public static final byte RFLAG_CHECK = 0x01;
private final boolean bRFlag;
private final int rawValue;
private final boolean isRawValueSet;
/**
* Constructor to initialize raw Value.
*
* @param rawValue Flags
*/
public TedCapabilityTlv(final int rawValue) {
this.rawValue = rawValue;
this.isRawValueSet = true;
int temp = rawValue;
temp = temp & RFLAG_CHECK;
if (temp == SET) {
this.bRFlag = true;
} else {
this.bRFlag = false;
}
}
/**
* Constructor to initialize bRFlag.
*
* @param bRFlag R-flag
*/
public TedCapabilityTlv(boolean bRFlag) {
this.bRFlag = bRFlag;
this.rawValue = 0;
this.isRawValueSet = false;
}
/**
* Returns R-flag.
*
* @return bRFlag
*/
public boolean getbRFlag() {
return bRFlag;
}
/**
* Returns an object of TedCapabilityTlv.
*
* @param raw value Flags
* @return object of TedCapabilityTlv
*/
public static TedCapabilityTlv of(final int raw) {
return new TedCapabilityTlv(raw);
}
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
public int getInt() {
return rawValue;
}
@Override
public short getType() {
return TYPE;
}
@Override
public short getLength() {
return LENGTH;
}
@Override
public int hashCode() {
if (isRawValueSet) {
return Objects.hash(rawValue);
} else {
return Objects.hash(bRFlag);
}
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof TedCapabilityTlv) {
TedCapabilityTlv other = (TedCapabilityTlv) obj;
if (isRawValueSet) {
return Objects.equals(this.rawValue, other.rawValue);
} else {
return Objects.equals(this.bRFlag, other.bRFlag);
}
}
return false;
}
@Override
public int write(ChannelBuffer c) {
int iStartIndex = c.writerIndex();
int temp = 0;
c.writeShort(TYPE);
c.writeShort(LENGTH);
if (isRawValueSet) {
c.writeInt(rawValue);
} else {
if (bRFlag) {
temp = temp | RFLAG_CHECK;
}
c.writeInt(temp);
}
return c.writerIndex() - iStartIndex;
}
/**
* Reads channel buffer and returns object of TedCapabilityTlv.
*
* @param c input channel buffer
* @return object of TedCapabilityTlv
*/
public static TedCapabilityTlv read(ChannelBuffer c) {
return TedCapabilityTlv.of(c.readInt());
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH).add("Value", rawValue)
.toString();
}
}
/*
* Copyright 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.types;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
/**
* Provides Unreserved Bandwidth Tlv.
*/
public class UnreservedBandwidthTlv implements PcepValueType {
/* Reference :[RFC5305]/3.6
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type=[TDB36] | Length=4 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Unreserved Bandwidth |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
protected static final Logger log = LoggerFactory.getLogger(UnreservedBandwidthTlv.class);
public static final short TYPE = 11; //TDB36
public static final short LENGTH = 4;
private final int rawValue;
/**
* Constructor to initialize rawValue.
*
* @param rawValue Unreserved Bandwidth
*/
public UnreservedBandwidthTlv(int rawValue) {
this.rawValue = rawValue;
}
/**
* Returns newly created UnreservedBandwidthTlv object.
*
* @param raw as Unreserved Bandwidth
* @return object of UnreservedBandwidthTlv
*/
public static UnreservedBandwidthTlv of(final int raw) {
return new UnreservedBandwidthTlv(raw);
}
/**
* Returns Unreserved Bandwidth.
*
* @return rawValue Unreserved Bandwidth
*/
public int getInt() {
return rawValue;
}
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
@Override
public short getType() {
return TYPE;
}
@Override
public short getLength() {
return LENGTH;
}
@Override
public int hashCode() {
return Objects.hash(rawValue);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof UnreservedBandwidthTlv) {
UnreservedBandwidthTlv other = (UnreservedBandwidthTlv) obj;
return Objects.equals(this.rawValue, other.rawValue);
}
return false;
}
@Override
public int write(ChannelBuffer c) {
int iLenStartIndex = c.writerIndex();
c.writeShort(TYPE);
c.writeShort(LENGTH);
c.writeInt(rawValue);
return c.writerIndex() - iLenStartIndex;
}
/**
* Reads byte stream from channel buffer and returns object of UnreservedBandwidthTlv.
*
* @param c input channel buffer
* @return object of UnreservedBandwidthTlv
*/
public static UnreservedBandwidthTlv read(ChannelBuffer c) {
return UnreservedBandwidthTlv.of(c.readInt());
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH).add("Value", rawValue)
.toString();
}
}
/*
* Copyright 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 com.google.common.testing.EqualsTester;
import org.junit.Test;
import org.onosproject.pcepio.types.AdministrativeGroupTlv;
/**
* Test of the AdministrativeGroupTlv.
*/
public class AdministrativeGroupTlvTest {
private final AdministrativeGroupTlv tlv1 = AdministrativeGroupTlv.of(1);
private final AdministrativeGroupTlv sameAsTlv1 = AdministrativeGroupTlv.of(1);
private final AdministrativeGroupTlv tlv2 = AdministrativeGroupTlv.of(2);
@Test
public void basics() {
new EqualsTester()
.addEqualityGroup(tlv1, sameAsTlv1)
.addEqualityGroup(tlv2)
.testEquals();
}
}
/*
* Copyright 2014 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 com.google.common.testing.EqualsTester;
import org.junit.Test;
import org.onosproject.pcepio.types.AutonomousSystemTlv;
/**
* Test of the AutonomousSystemTlv.
*/
public class AutonomousSystemTlvTest {
private final AutonomousSystemTlv tlv1 = AutonomousSystemTlv.of(1);
private final AutonomousSystemTlv sameAsTlv1 = AutonomousSystemTlv.of(1);
private final AutonomousSystemTlv tlv2 = AutonomousSystemTlv.of(2);
@Test
public void basics() {
new EqualsTester()
.addEqualityGroup(tlv1, sameAsTlv1)
.addEqualityGroup(tlv2)
.testEquals();
}
}
/*
* Copyright 2014 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 com.google.common.testing.EqualsTester;
import org.junit.Test;
import org.onosproject.pcepio.types.BGPLSidentifierTlv;
/**
* Test of the BGPLSidentifierTlv.
*/
public class BGPLSidentifierTlvTest {
private final BGPLSidentifierTlv tlv1 = BGPLSidentifierTlv.of(1);
private final BGPLSidentifierTlv sameAsTlv1 = BGPLSidentifierTlv.of(1);
private final BGPLSidentifierTlv tlv2 = BGPLSidentifierTlv.of(2);
@Test
public void basics() {
new EqualsTester()
.addEqualityGroup(tlv1, sameAsTlv1)
.addEqualityGroup(tlv2)
.testEquals();
}
}
/*
* Copyright 2014 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 com.google.common.testing.EqualsTester;
import org.junit.Test;
import org.onosproject.pcepio.types.GmplsCapabilityTlv;
/**
* Test of the GmplsCapabilityTlv.
*/
public class GmplsCapabilityTlvTest {
private final GmplsCapabilityTlv tlv1 = GmplsCapabilityTlv.of(1);
private final GmplsCapabilityTlv sameAsTlv1 = GmplsCapabilityTlv.of(1);
private final GmplsCapabilityTlv tlv2 = GmplsCapabilityTlv.of(2);
@Test
public void basics() {
new EqualsTester()
.addEqualityGroup(tlv1, sameAsTlv1)
.addEqualityGroup(tlv2)
.testEquals();
}
}
/*
* Copyright 2014 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 com.google.common.testing.EqualsTester;
import org.junit.Test;
import org.onosproject.pcepio.types.IGPMetricTlv;
/**
* Test of the IGPMetricTlv.
*/
public class IGPMetricTlvTest {
private byte[] b1 = new byte[] {0x01, 0x02};
private byte[] b2 = new byte[] {0x01, 0x02};
private final IGPMetricTlv tlv1 = IGPMetricTlv.of(b1, (short) 2);
private final IGPMetricTlv sameAsTlv1 = IGPMetricTlv.of(b1, (short) 2);
private final IGPMetricTlv tlv2 = IGPMetricTlv.of(b2, (short) 2);
@Test
public void basics() {
new EqualsTester()
.addEqualityGroup(tlv1, sameAsTlv1)
.addEqualityGroup(tlv2)
.testEquals();
}
}
/*
* Copyright 2014 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 com.google.common.testing.EqualsTester;
import org.junit.Test;
import org.onosproject.pcepio.types.IPv4InterfaceAddressTlv;
/**
* Test of the IPv4InterfaceAddressTlv.
*/
public class IPv4InterfaceAddressTlvTest {
private final IPv4InterfaceAddressTlv tlv1 = IPv4InterfaceAddressTlv.of(2);
private final IPv4InterfaceAddressTlv sameAsTlv1 = IPv4InterfaceAddressTlv.of(2);
private final IPv4InterfaceAddressTlv tlv2 = IPv4InterfaceAddressTlv.of(3);
@Test
public void basics() {
new EqualsTester()
.addEqualityGroup(tlv1, sameAsTlv1)
.addEqualityGroup(tlv2)
.testEquals();
}
}
/*
* Copyright 2014 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 com.google.common.testing.EqualsTester;
import org.junit.Test;
import org.onosproject.pcepio.types.IPv4NeighborAddressTlv;
/**
* Test of the IPv4NeighborAddressTlv.
*/
public class IPv4NeighborAddressTlvTest {
private final IPv4NeighborAddressTlv tlv1 = IPv4NeighborAddressTlv.of(2);
private final IPv4NeighborAddressTlv sameAsTlv1 = IPv4NeighborAddressTlv.of(2);
private final IPv4NeighborAddressTlv tlv2 = IPv4NeighborAddressTlv.of(3);
@Test
public void basics() {
new EqualsTester()
.addEqualityGroup(tlv1, sameAsTlv1)
.addEqualityGroup(tlv2)
.testEquals();
}
}
/*
* Copyright 2014 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 com.google.common.testing.EqualsTester;
import org.junit.Test;
import org.onosproject.pcepio.types.IPv4TERouterIdOfLocalNodeTlv;
/**
* Test of the IPv4TERouterIdOfLocalNodeTlv.
*/
public class IPv4TERouterIdOfLocalNodeTlvTest {
private final IPv4TERouterIdOfLocalNodeTlv tlv1 = IPv4TERouterIdOfLocalNodeTlv.of(2);
private final IPv4TERouterIdOfLocalNodeTlv sameAsTlv1 = IPv4TERouterIdOfLocalNodeTlv.of(2);
private final IPv4TERouterIdOfLocalNodeTlv tlv2 = IPv4TERouterIdOfLocalNodeTlv.of(3);
@Test
public void basics() {
new EqualsTester()
.addEqualityGroup(tlv1, sameAsTlv1)
.addEqualityGroup(tlv2)
.testEquals();
}
}
/*
* Copyright 2014 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 com.google.common.testing.EqualsTester;
import org.junit.Test;
import org.onosproject.pcepio.types.IPv4TERouterIdOfRemoteNodeTlv;
/**
* Test of the IPv4TERouterIdOfRemoteNodeTlv.
*/
public class IPv4TERouterIdOfRemoteNodeTlvTest {
private final IPv4TERouterIdOfRemoteNodeTlv tlv1 = IPv4TERouterIdOfRemoteNodeTlv.of(2);
private final IPv4TERouterIdOfRemoteNodeTlv sameAsTlv1 = IPv4TERouterIdOfRemoteNodeTlv.of(2);
private final IPv4TERouterIdOfRemoteNodeTlv tlv2 = IPv4TERouterIdOfRemoteNodeTlv.of(3);
@Test
public void basics() {
new EqualsTester()
.addEqualityGroup(tlv1, sameAsTlv1)
.addEqualityGroup(tlv2)
.testEquals();
}
}
/*
* Copyright 2014 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 com.google.common.testing.EqualsTester;
import org.junit.Test;
import org.onosproject.pcepio.types.IPv6InterfaceAddressTlv;
/**
* Test of the IPv6InterfaceAddressTlv.
*/
public class IPv6InterfaceAddressTlvTest {
private byte[] b1 = new byte[] {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
private byte[] b2 = new byte[] {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 };
private final IPv6InterfaceAddressTlv tlv1 = IPv6InterfaceAddressTlv.of(b1);
private final IPv6InterfaceAddressTlv sameAsTlv1 = IPv6InterfaceAddressTlv.of(b1);
private final IPv6InterfaceAddressTlv tlv2 = IPv6InterfaceAddressTlv.of(b2);
@Test
public void basics() {
new EqualsTester()
.addEqualityGroup(tlv1, sameAsTlv1)
.addEqualityGroup(tlv2)
.testEquals();
}
}
/*
* Copyright 2014 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 com.google.common.testing.EqualsTester;
import org.junit.Test;
import org.onosproject.pcepio.types.IPv6NeighborAddressTlv;
/**
* Test of the IPv6NeighborAddressTlv.
*/
public class IPv6NeighborAddressTlvTest {
private byte[] b1 = new byte[] {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
private byte[] b2 = new byte[] {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 };
private final IPv6NeighborAddressTlv tlv1 = IPv6NeighborAddressTlv.of(b1);
private final IPv6NeighborAddressTlv sameAsTlv1 = IPv6NeighborAddressTlv.of(b1);
private final IPv6NeighborAddressTlv tlv2 = IPv6NeighborAddressTlv.of(b2);
@Test
public void basics() {
new EqualsTester()
.addEqualityGroup(tlv1, sameAsTlv1)
.addEqualityGroup(tlv2)
.testEquals();
}
}
/*
* Copyright 2014 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 com.google.common.testing.EqualsTester;
import org.junit.Test;
import org.onosproject.pcepio.types.IPv6TERouterIdofLocalNodeTlv;
/**
* Test of the IPv6TERouterIdofLocalNodeTlv.
*/
public class IPv6TERouterIdofLocalNodeTlvTest {
private byte[] b1 = new byte[] {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
private byte[] b2 = new byte[] {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 };
private final IPv6TERouterIdofLocalNodeTlv tlv1 = IPv6TERouterIdofLocalNodeTlv.of(b1);
private final IPv6TERouterIdofLocalNodeTlv sameAsTlv1 = IPv6TERouterIdofLocalNodeTlv.of(b1);
private final IPv6TERouterIdofLocalNodeTlv tlv2 = IPv6TERouterIdofLocalNodeTlv.of(b2);
@Test
public void basics() {
new EqualsTester()
.addEqualityGroup(tlv1, sameAsTlv1)
.addEqualityGroup(tlv2)
.testEquals();
}
}
/*
* Copyright 2014 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 com.google.common.testing.EqualsTester;
import org.junit.Test;
import org.onosproject.pcepio.types.IPv6TERouterIdofRemoteNodeTlv;
/**
* Test of the IPv6TERouterIdofRemoteNodeTlv.
*/
public class IPv6TERouterIdofRemoteNodeTlvTest {
private byte[] b1 = new byte[] {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
private byte[] b2 = new byte[] {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 };
private final IPv6TERouterIdofRemoteNodeTlv tlv1 = IPv6TERouterIdofRemoteNodeTlv.of(b1);
private final IPv6TERouterIdofRemoteNodeTlv sameAsTlv1 = IPv6TERouterIdofRemoteNodeTlv.of(b1);
private final IPv6TERouterIdofRemoteNodeTlv tlv2 = IPv6TERouterIdofRemoteNodeTlv.of(b2);
@Test
public void basics() {
new EqualsTester()
.addEqualityGroup(tlv1, sameAsTlv1)
.addEqualityGroup(tlv2)
.testEquals();
}
}
/*
* Copyright 2014 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 com.google.common.testing.EqualsTester;
import org.junit.Test;
import org.onosproject.pcepio.types.ISISAreaIdentifierTlv;
/**
* Test of the ISISAreaIdentifierTlv.
*/
public class ISISAreaIdentifierTlvTest {
private byte[] b1 = new byte[] {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
private byte[] b2 = new byte[] {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 };
private final ISISAreaIdentifierTlv tlv1 = ISISAreaIdentifierTlv.of(b1, (short) 20);
private final ISISAreaIdentifierTlv sameAsTlv1 = ISISAreaIdentifierTlv.of(b1, (short) 20);
private final ISISAreaIdentifierTlv tlv2 = ISISAreaIdentifierTlv.of(b2, (short) 20);
@Test
public void basics() {
new EqualsTester()
.addEqualityGroup(tlv1, sameAsTlv1)
.addEqualityGroup(tlv2)
.testEquals();
}
}
/*
* Copyright 2014 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 com.google.common.testing.EqualsTester;
import org.junit.Test;
import org.onosproject.pcepio.types.LinkLocalRemoteIdentifiersTlv;
/**
* Test of the LinkLocalRemoteIdentifiersTlv.
*/
public class LinkLocalRemoteIdentifiersTlvTest {
private final LinkLocalRemoteIdentifiersTlv tlv1 = LinkLocalRemoteIdentifiersTlv.of(10, 20);
private final LinkLocalRemoteIdentifiersTlv sameAsTlv1 = LinkLocalRemoteIdentifiersTlv.of(10, 20);
private final LinkLocalRemoteIdentifiersTlv tlv2 = LinkLocalRemoteIdentifiersTlv.of(20, 30);
@Test
public void basics() {
new EqualsTester()
.addEqualityGroup(tlv1, sameAsTlv1)
.addEqualityGroup(tlv2)
.testEquals();
}
}
/*
* Copyright 2014 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 com.google.common.testing.EqualsTester;
import org.junit.Test;
import org.onosproject.pcepio.types.LinkNameTlv;
/**
* Test of the LinkNameTlv.
*/
public class LinkNameTlvTest {
private final byte[] rawValue1 = new byte[] {0x01, 0x00};
private final byte[] rawValue2 = new byte[] {0x02, 0x00};
private final LinkNameTlv tlv1 = new LinkNameTlv(rawValue1, (short) rawValue1.length);
private final LinkNameTlv sameAsTlv1 = LinkNameTlv.of(tlv1.getValue(), tlv1.getLength());
private final LinkNameTlv tlv2 = new LinkNameTlv(rawValue2, (short) 0);
private final LinkNameTlv sameAsTlv2 = new LinkNameTlv(rawValue2, (short) rawValue2.length);
@Test
public void basics() {
new EqualsTester()
.addEqualityGroup(tlv1, sameAsTlv1)
.addEqualityGroup(tlv2, sameAsTlv2)
.testEquals();
}
}
/* * Copyright 2014 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 com.google.common.testing.EqualsTester; import org.junit.Test;import org.onosproject.pcepio.types.LinkProtectionTypeTlv; /** * Test of the LinkProtectionTypeTlv. */public class LinkProtectionTypeTlvTest { private final byte rawValue1 = 0x0A; private final byte rawValue2 = 0x0A; private final LinkProtectionTypeTlv tlv1 = new LinkProtectionTypeTlv(rawValue1); private final LinkProtectionTypeTlv tlv2 = new LinkProtectionTypeTlv(rawValue2, (byte) 0); @Test public void basics() { new EqualsTester() .addEqualityGroup(tlv1, tlv2) .testEquals(); }}
\ No newline at end of file
/*
* Copyright 2014 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 com.google.common.testing.EqualsTester;
import org.junit.Test;
import org.onosproject.pcepio.types.MPLSProtocolMaskTlv;
/**
* Test of the MPLSProtocolMaskTlv.
*/
public class MPLSProtocolMaskTlvTest {
private final byte rawValue1 = 0x0A;
private final byte rawValue2 = 0x0A;
private final MPLSProtocolMaskTlv tlv1 = new MPLSProtocolMaskTlv(rawValue1);
private final MPLSProtocolMaskTlv tlv2 = MPLSProtocolMaskTlv.of(rawValue2);
@Test
public void basics() {
new EqualsTester()
.addEqualityGroup(tlv1, tlv2)
.testEquals();
}
}
/*
* Copyright 2014 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 org.junit.Test;
import org.onosproject.pcepio.types.MaximumLinkBandwidthTlv;
import com.google.common.testing.EqualsTester;
/**
* Test of the MaximumLinkBandwidthTlv.
*/
public class MaximumLinkBandwidthTlvTest {
private final int rawValue1 = 0x0A;
private final int rawValue2 = 0x0A;
private final MaximumLinkBandwidthTlv tlv1 = new MaximumLinkBandwidthTlv(rawValue1);
private final MaximumLinkBandwidthTlv tlv2 = MaximumLinkBandwidthTlv.of(rawValue2);
@Test
public void basics() {
new EqualsTester()
.addEqualityGroup(tlv1, tlv2)
.testEquals();
}
}
/*
* Copyright 2014 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 org.junit.Test;
import org.onosproject.pcepio.types.MaximumReservableLinkBandwidthTlv;
import com.google.common.testing.EqualsTester;
/**
* Test of the MaximumReservableLinkBandwidthTlv.
*/
public class MaximumReservableLinkBandwidthTlvTest {
private final int rawValue1 = 0x0A;
private final int rawValue2 = 0x0A;
private final MaximumReservableLinkBandwidthTlv tlv1 = new MaximumReservableLinkBandwidthTlv(rawValue1);
private final MaximumReservableLinkBandwidthTlv tlv2 = MaximumReservableLinkBandwidthTlv.of(rawValue2);
@Test
public void basics() {
new EqualsTester()
.addEqualityGroup(tlv1, tlv2)
.testEquals();
}
}
/*
* Copyright 2014 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 com.google.common.testing.EqualsTester;
import org.junit.Test;
import org.onosproject.pcepio.types.NodeFlagBitsTlv;
/**
* Test of the NodeFlagBitsTlv.
*/
public class NodeFlagBitsTlvTest {
private final byte rawValue1 = 0x0A;
private final NodeFlagBitsTlv tlv1 = new NodeFlagBitsTlv(rawValue1);
private final NodeFlagBitsTlv tlv2 = NodeFlagBitsTlv.of(tlv1.getbyte());
@Test
public void basics() {
new EqualsTester()
.addEqualityGroup(tlv1, tlv2)
.testEquals();
}
}
/*
* Copyright 2014 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 com.google.common.testing.EqualsTester;
import org.junit.Test;
import org.onosproject.pcepio.types.NodeNameTlv;
/**
* Test of the NodeNameTlv.
*/
public class NodeNameTlvTest {
private final byte[] rawValue1 = new byte[] {0x01, 0x02};
private final byte[] rawValue2 = new byte[] {0x14, 0x15};
private final NodeNameTlv tlv1 = new NodeNameTlv(rawValue1, (short) rawValue1.length);
private final NodeNameTlv sameAsTlv1 = NodeNameTlv.of(tlv1.getValue(), tlv1.getLength());
private final NodeNameTlv tlv2 = new NodeNameTlv(rawValue2, (short) 0);
private final NodeNameTlv sameAsTlv2 = new NodeNameTlv(rawValue2, (short) rawValue2.length);
@Test
public void basics() {
new EqualsTester()
.addEqualityGroup(tlv1, sameAsTlv1)
.addEqualityGroup(tlv2, sameAsTlv2)
.testEquals();
}
}
/*
* Copyright 2014 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 com.google.common.testing.EqualsTester;
import org.junit.Test;
import org.onosproject.pcepio.types.OSPFareaIDsubTlv;
/**
* Test of the OSPFareaIDsubTlv.
*/
public class OSPFareaIDsubTlvTest {
private final int rawValue1 = 0x0A;
private final OSPFareaIDsubTlv tlv1 = new OSPFareaIDsubTlv(rawValue1);
private final OSPFareaIDsubTlv tlv2 = OSPFareaIDsubTlv.of(tlv1.getInt());
@Test
public void basics() {
new EqualsTester()
.addEqualityGroup(tlv1, tlv2)
.testEquals();
}
}
/*
* Copyright 2014 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 com.google.common.testing.EqualsTester;
import org.junit.Test;
import org.onosproject.pcepio.types.OpaqueLinkAttributeTlv;
/**
* Test of the OpaqueLinkAttributeTlv.
*/
public class OpaqueLinkAttributeTlvTest {
private final byte[] rawValue1 = new byte[] {0x01, 0x02};
private final byte[] rawValue2 = new byte[] {0x14, 0x15};
private final OpaqueLinkAttributeTlv tlv1 = new OpaqueLinkAttributeTlv(rawValue1, (short) rawValue1.length);
private final OpaqueLinkAttributeTlv sameAsTlv1 = OpaqueLinkAttributeTlv.of(tlv1.getValue(), tlv1.getLength());
private final OpaqueLinkAttributeTlv tlv2 = new OpaqueLinkAttributeTlv(rawValue2, (short) 0);
private final OpaqueLinkAttributeTlv sameAsTlv2 = new OpaqueLinkAttributeTlv(rawValue2, (short) rawValue2.length);
@Test
public void basics() {
new EqualsTester()
.addEqualityGroup(tlv1, sameAsTlv1)
.addEqualityGroup(tlv2, sameAsTlv2)
.testEquals();
}
}
/*
* Copyright 2014 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 com.google.common.testing.EqualsTester;
import org.junit.Test;
import org.onosproject.pcepio.types.PceccCapabilityTlv;
/**
* Test of the PceccCapabilityTlv.
*/
public class PceccCapabilityTlvTest {
private final int rawValue1 = 0x0A;
private final int rawValue2 = 0x0A;
private final PceccCapabilityTlv tlv1 = new PceccCapabilityTlv(rawValue1);
private final PceccCapabilityTlv tlv2 = PceccCapabilityTlv.of(rawValue2);
@Test
public void basics() {
new EqualsTester()
.addEqualityGroup(tlv1, tlv2)
.testEquals();
}
}
/*
* Copyright 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.LinkedList;
import org.junit.Test;
import org.onosproject.pcepio.types.AutonomousSystemTlv;
import org.onosproject.pcepio.types.BGPLSidentifierTlv;
import org.onosproject.pcepio.types.PcepValueType;
import org.onosproject.pcepio.types.RemoteTENodeDescriptorsTLV;
import com.google.common.testing.EqualsTester;
/**
* Test case for Remote TE Node Descriptors tlv.
*/
public class RemoteTENodeDescriptorsTLVTest {
AutonomousSystemTlv autonomousSystemTlv1 = new AutonomousSystemTlv(10);
BGPLSidentifierTlv bGPLSidentifierTlv1 = new BGPLSidentifierTlv(20);;
LinkedList<PcepValueType> llRemoteTENodeDescriptorSubTLVs1 = new LinkedList<PcepValueType>();
LinkedList<PcepValueType> llRemoteTENodeDescriptorSubTLVs2 = new LinkedList<PcepValueType>();
LinkedList<PcepValueType> llRemoteTENodeDescriptorSubTLVs3 = new LinkedList<PcepValueType>();
boolean b = llRemoteTENodeDescriptorSubTLVs1.add(autonomousSystemTlv1);
boolean c = llRemoteTENodeDescriptorSubTLVs2.add(autonomousSystemTlv1);
boolean d = llRemoteTENodeDescriptorSubTLVs3.add(bGPLSidentifierTlv1);
final RemoteTENodeDescriptorsTLV tlv1 = RemoteTENodeDescriptorsTLV.of(llRemoteTENodeDescriptorSubTLVs1);
final RemoteTENodeDescriptorsTLV tlv2 = RemoteTENodeDescriptorsTLV.of(llRemoteTENodeDescriptorSubTLVs2);
final RemoteTENodeDescriptorsTLV tlv3 = RemoteTENodeDescriptorsTLV.of(llRemoteTENodeDescriptorSubTLVs3);
@Test
public void basics() {
new EqualsTester().addEqualityGroup(tlv1, tlv2).addEqualityGroup(tlv3).testEquals();
}
}
/*
* Copyright 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 org.junit.Test;
import org.onosproject.pcepio.types.RouterIDSubTlv;
import com.google.common.testing.EqualsTester;
/**
* Test case for Router ID Sub tlv.
*/
public class RouterIDSubTlvTest {
private byte[] value1 = {1, 2 };
private Short length1 = new Short((short) 2);
private final RouterIDSubTlv tlv1 = RouterIDSubTlv.of(value1, length1);
private Short length2 = new Short((short) 2);
private final RouterIDSubTlv tlv2 = RouterIDSubTlv.of(value1, length2);
private byte[] value3 = {1, 2, 3 };
private Short length3 = new Short((short) 3);
private final RouterIDSubTlv tlv3 = RouterIDSubTlv.of(value3, length3);
@Test
public void basics() {
new EqualsTester().addEqualityGroup(tlv1, tlv2).addEqualityGroup(tlv3).testEquals();
}
}
/*
* Copyright 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 org.junit.Test;
import org.onosproject.pcepio.types.SharedRiskLinkGroupTlv;
import com.google.common.testing.EqualsTester;
/**
* Test case for Shared Risk Link Group tlv.
*/
public class SharedRiskLinkGroupTlvTest {
private int[] raw = {1 };
private Short hLength = new Short((short) 2);
private final SharedRiskLinkGroupTlv tlv1 = SharedRiskLinkGroupTlv.of(raw, hLength);
private Short hLength1 = new Short((short) 2);
private final SharedRiskLinkGroupTlv tlv2 = SharedRiskLinkGroupTlv.of(raw, hLength1);
private int[] raw2 = {2 };
private Short hLength2 = new Short((short) 3);
private SharedRiskLinkGroupTlv tlv3 = SharedRiskLinkGroupTlv.of(raw2, hLength2);
@Test
public void basics() {
new EqualsTester().addEqualityGroup(tlv1, tlv2).addEqualityGroup(tlv3).testEquals();
}
}
/*
* Copyright 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 org.junit.Test;
import org.onosproject.pcepio.types.StatefulLspDbVerTlv;
import com.google.common.testing.EqualsTester;
/**
* Test case for Stateful Lsp Db Ver tlv.
*/
public class StatefulLspDbVerTlvTest {
private final StatefulLspDbVerTlv tlv1 = StatefulLspDbVerTlv.of(1);
private final StatefulLspDbVerTlv tlv2 = StatefulLspDbVerTlv.of(1);
private final StatefulLspDbVerTlv tlv3 = StatefulLspDbVerTlv.of(2);
@Test
public void basics() {
new EqualsTester().addEqualityGroup(tlv1, tlv2).addEqualityGroup(tlv3).testEquals();
}
}
/*
* Copyright 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 org.junit.Test;
import org.onosproject.pcepio.types.StatefulPceCapabilityTlv;
import com.google.common.testing.EqualsTester;
/**
* Test case for Stateful Pce Capability tlv.
*/
public class StatefulPceCapabilityTlvTest {
private final StatefulPceCapabilityTlv tlv1 = StatefulPceCapabilityTlv.of(1);
private final StatefulPceCapabilityTlv tlv2 = StatefulPceCapabilityTlv.of(1);
private final StatefulPceCapabilityTlv tlv3 = StatefulPceCapabilityTlv.of(2);
@Test
public void basics() {
new EqualsTester().addEqualityGroup(tlv1, tlv2).addEqualityGroup(tlv3).testEquals();
}
}
/*
* Copyright 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 org.junit.Test;
import org.onosproject.pcepio.types.TEDefaultMetricTlv;
import com.google.common.testing.EqualsTester;
/**
* Test case for TE Default Metric tlv.
*/
public class TEDefaultMetricTlvTest {
private final TEDefaultMetricTlv tlv1 = TEDefaultMetricTlv.of(1);
private final TEDefaultMetricTlv tlv2 = TEDefaultMetricTlv.of(1);
private final TEDefaultMetricTlv tlv3 = TEDefaultMetricTlv.of(2);
@Test
public void basics() {
new EqualsTester().addEqualityGroup(tlv1, tlv2).addEqualityGroup(tlv3).testEquals();
}
}
\ No newline at end of file
/*
* Copyright 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.LinkedList;
import org.junit.Test;
import org.onosproject.pcepio.types.AdministrativeGroupTlv;
import org.onosproject.pcepio.types.MaximumReservableLinkBandwidthTlv;
import org.onosproject.pcepio.types.PcepValueType;
import org.onosproject.pcepio.types.TELinkAttributesTlv;
import com.google.common.testing.EqualsTester;
/**
* Test case for TE Link Attribute Tlv.
*/
public class TELinkAttributesTlvTest {
AdministrativeGroupTlv administrativeGroupTlv1 = new AdministrativeGroupTlv(10);
MaximumReservableLinkBandwidthTlv maximumReservableLinkBandwidthTlv1 = new MaximumReservableLinkBandwidthTlv(20);;
LinkedList<PcepValueType> llLinkAttributesSubTLVs = new LinkedList<PcepValueType>();
LinkedList<PcepValueType> llLinkAttributesSubTLVs2 = new LinkedList<PcepValueType>();
LinkedList<PcepValueType> llLinkAttributesSubTLVs3 = new LinkedList<PcepValueType>();
boolean b = llLinkAttributesSubTLVs.add(administrativeGroupTlv1);
boolean c = llLinkAttributesSubTLVs2.add(administrativeGroupTlv1);
boolean d = llLinkAttributesSubTLVs3.add(maximumReservableLinkBandwidthTlv1);
final TELinkAttributesTlv tlv1 = TELinkAttributesTlv.of(llLinkAttributesSubTLVs);
final TELinkAttributesTlv tlv2 = TELinkAttributesTlv.of(llLinkAttributesSubTLVs2);
final TELinkAttributesTlv tlv3 = TELinkAttributesTlv.of(llLinkAttributesSubTLVs3);
@Test
public void basics() {
new EqualsTester().addEqualityGroup(tlv1, tlv2).addEqualityGroup(tlv3).testEquals();
}
}
/*
* Copyright 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.LinkedList;
import org.junit.Test;
import org.onosproject.pcepio.types.IPv4InterfaceAddressTlv;
import org.onosproject.pcepio.types.LinkLocalRemoteIdentifiersTlv;
import org.onosproject.pcepio.types.PcepValueType;
import org.onosproject.pcepio.types.TELinkDescriptorsTLV;
import com.google.common.testing.EqualsTester;
/**
* Test case for TE link descriptors Tlv.
*/
public class TELinkDescriptorsTLVTest {
LinkLocalRemoteIdentifiersTlv linkLocalRemoteIdentifiersTlv1 = new LinkLocalRemoteIdentifiersTlv(10, 10);
IPv4InterfaceAddressTlv iPv4InterfaceAddressTlv1 = new IPv4InterfaceAddressTlv((int) 0x01010101);
LinkedList<PcepValueType> llLinkDescriptorsSubTLVs1 = new LinkedList<PcepValueType>();
LinkedList<PcepValueType> llLinkDescriptorsSubTLVs2 = new LinkedList<PcepValueType>();
LinkedList<PcepValueType> llLinkDescriptorsSubTLVs3 = new LinkedList<PcepValueType>();
boolean b = llLinkDescriptorsSubTLVs1.add(linkLocalRemoteIdentifiersTlv1);
boolean c = llLinkDescriptorsSubTLVs2.add(linkLocalRemoteIdentifiersTlv1);
boolean d = llLinkDescriptorsSubTLVs3.add(iPv4InterfaceAddressTlv1);
final TELinkDescriptorsTLV tlv1 = TELinkDescriptorsTLV.of(llLinkDescriptorsSubTLVs1);
final TELinkDescriptorsTLV tlv2 = TELinkDescriptorsTLV.of(llLinkDescriptorsSubTLVs2);
final TELinkDescriptorsTLV tlv3 = TELinkDescriptorsTLV.of(llLinkDescriptorsSubTLVs3);
@Test
public void basics() {
new EqualsTester().addEqualityGroup(tlv1, tlv2).addEqualityGroup(tlv3).testEquals();
}
}
/*
* Copyright 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.LinkedList;
import org.junit.Test;
import org.onosproject.pcepio.types.IPv4TERouterIdOfLocalNodeTlv;
import org.onosproject.pcepio.types.NodeFlagBitsTlv;
import org.onosproject.pcepio.types.PcepValueType;
import org.onosproject.pcepio.types.TENodeAttributesTlv;
import com.google.common.testing.EqualsTester;
/**
* Test case for TE Node Attribute tlv.
*/
public class TENodeAttributesTlvTest {
NodeFlagBitsTlv nodeFlagBitsTlv1 = new NodeFlagBitsTlv((byte) 10);
IPv4TERouterIdOfLocalNodeTlv iPv4TERouterIdOfLocalNodeTlv1 = new IPv4TERouterIdOfLocalNodeTlv((int) 0x01010101);;
LinkedList<PcepValueType> llNodeAttributesSubTLVs1 = new LinkedList<PcepValueType>();
LinkedList<PcepValueType> llNodeAttributesSubTLVs2 = new LinkedList<PcepValueType>();
LinkedList<PcepValueType> llNodeAttributesSubTLVs3 = new LinkedList<PcepValueType>();
boolean b = llNodeAttributesSubTLVs1.add(nodeFlagBitsTlv1);
boolean c = llNodeAttributesSubTLVs2.add(nodeFlagBitsTlv1);
boolean d = llNodeAttributesSubTLVs3.add(iPv4TERouterIdOfLocalNodeTlv1);
final TENodeAttributesTlv tlv1 = TENodeAttributesTlv.of(llNodeAttributesSubTLVs1);
final TENodeAttributesTlv tlv2 = TENodeAttributesTlv.of(llNodeAttributesSubTLVs2);
final TENodeAttributesTlv tlv3 = TENodeAttributesTlv.of(llNodeAttributesSubTLVs3);
@Test
public void basics() {
new EqualsTester().addEqualityGroup(tlv1, tlv2).addEqualityGroup(tlv3).testEquals();
}
}
/*
* Copyright 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 org.junit.Test;
import org.onosproject.pcepio.types.TedCapabilityTlv;
import com.google.common.testing.EqualsTester;
/**
* Test case for TED Capability tlv.
*/
public class TedCapabilityTlvTest {
private final TedCapabilityTlv tlv1 = TedCapabilityTlv.of(1);
private final TedCapabilityTlv tlv2 = TedCapabilityTlv.of(1);
private final TedCapabilityTlv tlv3 = TedCapabilityTlv.of(2);
@Test
public void basics() {
new EqualsTester().addEqualityGroup(tlv1, tlv2).addEqualityGroup(tlv3).testEquals();
}
}
/*
* Copyright 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 org.junit.Test;
import org.onosproject.pcepio.types.UnreservedBandwidthTlv;
import com.google.common.testing.EqualsTester;
/**
* Unit Test case for Unreserved Bandwidth Tlv.
*/
public class UnreservedBandwidthTlvTest {
// Objects of unreserved bandwidth tlv
private final UnreservedBandwidthTlv tlv1 = UnreservedBandwidthTlv.of(100);
private final UnreservedBandwidthTlv tlv2 = UnreservedBandwidthTlv.of(100);
private final UnreservedBandwidthTlv tlv3 = UnreservedBandwidthTlv.of(200);
@Test
public void basics() {
new EqualsTester().addEqualityGroup(tlv1, tlv2).addEqualityGroup(tlv3).testEquals();
}
}