Bharat saraswal
Committed by Gerrit Code Review

[ONOS-2356] Implementation for PCEP label update message.

Change-Id: I510a9a7c7c868da1fc3d6e2625501f094faf8115
/*
* 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.PcepFecObjectIPv4Adjacency;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.onosproject.pcepio.types.PcepObjectHeader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
public class PcepFecObjectIPv4AdjacencyVer1 implements PcepFecObjectIPv4Adjacency {
/*
* ref : draft-zhao-pce-pcep-extension-for-pce-controller-01 , section : 7.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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Local IPv4 address |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Remote IPv4 address |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
FEC Object-Type is 3 IPv4 Adjacency
*/
protected static final Logger log = LoggerFactory.getLogger(PcepFecObjectIPv4AdjacencyVer1.class);
public static final byte FEC_OBJ_TYPE = 3;
public static final byte FEC_OBJ_CLASS = 36; //to be defined
public static final byte FEC_OBJECT_VERSION = 1;
public static final short FEC_OBJ_MINIMUM_LENGTH = 12;
public static final int MINIMUM_COMMON_HEADER_LENGTH = 4;
static final PcepObjectHeader DEFAULT_FEC_OBJECT_HEADER = new PcepObjectHeader(FEC_OBJ_CLASS, FEC_OBJ_TYPE,
PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, FEC_OBJ_MINIMUM_LENGTH);
private PcepObjectHeader fecObjHeader;
private int localIPv4Address;
private int remoteIPv4Address;
/**
* Constructor to initialize parameters for PCEP fec object .
*
* @param fecObjHeader FEC Object header
* @param localIPv4Address Local IPv4 Address
* @param remoteIPv4Address Remote IPv4 Address
*/
public PcepFecObjectIPv4AdjacencyVer1(PcepObjectHeader fecObjHeader, int localIPv4Address, int remoteIPv4Address) {
this.fecObjHeader = fecObjHeader;
this.localIPv4Address = localIPv4Address;
this.remoteIPv4Address = remoteIPv4Address;
}
/**
* Sets Object header.
*
* @param obj Pcep fec Object Header
*/
public void setFecIpv4ObjHeader(PcepObjectHeader obj) {
this.fecObjHeader = obj;
}
@Override
public int getLocalIPv4Address() {
return this.localIPv4Address;
}
@Override
public void seLocalIPv4Address(int value) {
this.localIPv4Address = value;
}
@Override
public int getRemoteIPv4Address() {
return this.remoteIPv4Address;
}
@Override
public void seRemoteIPv4Address(int value) {
this.remoteIPv4Address = value;
}
/**
* Reads from channel buffer and Returns object of PcepFecObjectIPv4Adjacency.
*
* @param cb of channel buffer.
* @return object of PcepFecObjectIPv4Adjacency
* @throws PcepParseException when fails to read from channel buffer
*/
public static PcepFecObjectIPv4Adjacency read(ChannelBuffer cb) throws PcepParseException {
PcepObjectHeader fecObjHeader;
int localIPv4Address;
int remoteIPv4Address;
fecObjHeader = PcepObjectHeader.read(cb);
//take only FEC IPv4 Adjacency Object buffer.
ChannelBuffer tempCb = cb.readBytes(fecObjHeader.getObjLen() - MINIMUM_COMMON_HEADER_LENGTH);
localIPv4Address = tempCb.readInt();
remoteIPv4Address = tempCb.readInt();
return new PcepFecObjectIPv4AdjacencyVer1(fecObjHeader, localIPv4Address, remoteIPv4Address);
}
@Override
public int write(ChannelBuffer cb) throws PcepParseException {
int objStartIndex = cb.writerIndex();
//Write common header
int objLenIndex = fecObjHeader.write(cb);
cb.writeInt(localIPv4Address);
cb.writeInt(remoteIPv4Address);
//Now write FEC IPv4 Adjacency Object Length
cb.setShort(objLenIndex, (short) (cb.writerIndex() - objStartIndex));
return cb.writerIndex();
}
/**
* Builder class for PCEP fec object IPv4 Adjacency.
*/
public static class Builder implements PcepFecObjectIPv4Adjacency.Builder {
private boolean bIsHeaderSet = false;
private boolean bIsLocalIPv4Addressset = false;
private boolean bIsRemoteIPv4Addressset = false;
private PcepObjectHeader fecObjHeader;
int localIPv4Address;
int remoteIPv4Address;
private boolean bIsPFlagSet = false;
private boolean bPFlag;
private boolean bIsIFlagSet = false;
private boolean bIFlag;
@Override
public PcepFecObjectIPv4Adjacency build() throws PcepParseException {
PcepObjectHeader fecObjHeader = this.bIsHeaderSet ? this.fecObjHeader : DEFAULT_FEC_OBJECT_HEADER;
if (!this.bIsLocalIPv4Addressset) {
throw new PcepParseException(
"Local IPv4 Address not set while building PcepFecObjectIPv4Adjacency object.");
}
if (!this.bIsRemoteIPv4Addressset) {
throw new PcepParseException(
" Remote IPv4 Address not set while building PcepFecObjectIPv4Adjacency object.");
}
if (bIsPFlagSet) {
fecObjHeader.setPFlag(bPFlag);
}
if (bIsIFlagSet) {
fecObjHeader.setIFlag(bIFlag);
}
return new PcepFecObjectIPv4AdjacencyVer1(fecObjHeader, this.localIPv4Address, this.remoteIPv4Address);
}
@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 PcepObjectHeader getFecIpv4AdjacencyObjHeader() {
return this.fecObjHeader;
}
@Override
public Builder setFecIpv4AdjacencyObjHeader(PcepObjectHeader obj) {
this.fecObjHeader = obj;
this.bIsHeaderSet = true;
return this;
}
@Override
public int getLocalIPv4Address() {
return this.localIPv4Address;
}
@Override
public Builder seLocalIPv4Address(int value) {
this.localIPv4Address = value;
this.bIsLocalIPv4Addressset = true;
return this;
}
@Override
public int getRemoteIPv4Address() {
return this.remoteIPv4Address;
}
@Override
public Builder seRemoteIPv4Address(int value) {
this.remoteIPv4Address = value;
this.bIsRemoteIPv4Addressset = true;
return this;
}
}
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
@Override
public int getType() {
return FEC_OBJ_TYPE;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass()).add("fecObjHeader", fecObjHeader)
.add("localIPv4Address", localIPv4Address).add("remoteIPv4Address", remoteIPv4Address).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.PcepFecObjectIPv4;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.onosproject.pcepio.types.PcepObjectHeader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
public class PcepFecObjectIPv4Ver1 implements PcepFecObjectIPv4 {
/*
* ref : draft-zhao-pce-pcep-extension-for-pce-controller-01 , section : 7.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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| IPv4 Node ID |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
FEC Object-Type is 1 IPv4 Node ID
*/
protected static final Logger log = LoggerFactory.getLogger(PcepFecObjectIPv4Ver1.class);
public static final byte FEC_OBJ_TYPE = 1;
public static final byte FEC_OBJ_CLASS = 63; //to be defined
public static final byte FEC_OBJECT_VERSION = 1;
public static final short FEC_OBJ_MINIMUM_LENGTH = 8;
public static final int MINIMUM_COMMON_HEADER_LENGTH = 4;
static final PcepObjectHeader DEFAULT_FEC_OBJECT_HEADER = new PcepObjectHeader(FEC_OBJ_CLASS, FEC_OBJ_TYPE,
PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, FEC_OBJ_MINIMUM_LENGTH);
private PcepObjectHeader fecObjHeader;
private int nodeID;
/**
* Constructor to initialize parameters for PCEP fec object.
*
* @param fecObjHeader fec object header
* @param nodeID node id
*/
public PcepFecObjectIPv4Ver1(PcepObjectHeader fecObjHeader, int nodeID) {
this.fecObjHeader = fecObjHeader;
this.nodeID = nodeID;
}
/**
* Sets the Object Header.
*
* @param obj object header
*/
public void setFecIpv4ObjHeader(PcepObjectHeader obj) {
this.fecObjHeader = obj;
}
@Override
public void setNodeID(int nodeID) {
this.nodeID = nodeID;
}
/**
* Returns Object Header.
*
* @return fecObjHeader fec object header
*/
public PcepObjectHeader getFecIpv4ObjHeader() {
return this.fecObjHeader;
}
@Override
public int getNodeID() {
return this.nodeID;
}
/**
* Reads from channel buffer and returns object of PcepFecObjectIPv4.
*
* @param cb of channel buffer
* @return object of PcepFecObjectIPv4
* @throws PcepParseException when fails to read from channel buffer
*/
public static PcepFecObjectIPv4 read(ChannelBuffer cb) throws PcepParseException {
PcepObjectHeader fecObjHeader;
int nodeID;
fecObjHeader = PcepObjectHeader.read(cb);
nodeID = cb.readInt();
return new PcepFecObjectIPv4Ver1(fecObjHeader, nodeID);
}
@Override
public int write(ChannelBuffer cb) throws PcepParseException {
int objStartIndex = cb.writerIndex();
//write common header
int objLenIndex = fecObjHeader.write(cb);
cb.writeInt(nodeID);
//now write FEC IPv4 Object Length
cb.setShort(objLenIndex, (short) (cb.writerIndex() - objStartIndex));
return cb.writerIndex();
}
/**
* Builder class for PCEP fec pobject IPv4.
*/
public static class Builder implements PcepFecObjectIPv4.Builder {
private boolean bIsHeaderSet = false;
private boolean bIsNodeIdset = false;
private PcepObjectHeader fecObjHeader;
private int nodeID;
private boolean bIsPFlagSet = false;
private boolean bPFlag;
private boolean bIsIFlagSet = false;
private boolean bIFlag;
@Override
public PcepFecObjectIPv4 build() throws PcepParseException {
PcepObjectHeader fecObjHeader = this.bIsHeaderSet ? this.fecObjHeader : DEFAULT_FEC_OBJECT_HEADER;
if (!this.bIsNodeIdset) {
throw new PcepParseException("NodeID not set while building PcepFecObjectIPv4 object.");
}
if (bIsPFlagSet) {
fecObjHeader.setPFlag(bPFlag);
}
if (bIsIFlagSet) {
fecObjHeader.setIFlag(bIFlag);
}
return new PcepFecObjectIPv4Ver1(fecObjHeader, this.nodeID);
}
@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 PcepObjectHeader getFecIpv4ObjHeader() {
return this.fecObjHeader;
}
@Override
public Builder setFecIpv4ObjHeader(PcepObjectHeader obj) {
this.fecObjHeader = obj;
this.bIsHeaderSet = true;
return this;
}
@Override
public int getNodeID() {
return this.nodeID;
}
@Override
public Builder setNodeID(int value) {
this.nodeID = value;
this.bIsNodeIdset = true;
return this;
}
}
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
@Override
public int getType() {
return FEC_OBJ_TYPE;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass()).add("fecObjHeader", fecObjHeader).add("nodeID: ", nodeID)
.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.PcepFecObjectIPv6Adjacency;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.onosproject.pcepio.types.PcepObjectHeader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
public class PcepFecObjectIPv6AdjacencyVer1 implements PcepFecObjectIPv6Adjacency {
/*
* ref : draft-zhao-pce-pcep-extension-for-pce-controller-01 , section : 7.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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
// Local IPv6 address (16 bytes) //
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
// Remote IPv6 address (16 bytes) //
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
FEC Object-Type is 4 IPv6 Adjacency
*/
protected static final Logger log = LoggerFactory.getLogger(PcepFecObjectIPv6AdjacencyVer1.class);
public static final byte FEC_OBJ_TYPE = 4;
public static final byte FEC_OBJ_CLASS = 63; //to be defined
public static final byte FEC_OBJECT_VERSION = 1;
public static final short FEC_OBJ_MINIMUM_LENGTH = 36;
public static final int MINIMUM_COMMON_HEADER_LENGTH = 4;
public static final int IPV6_ADDRESS_LENGTH = 16;
static final PcepObjectHeader DEFAULT_FEC_OBJECT_HEADER = new PcepObjectHeader(FEC_OBJ_CLASS, FEC_OBJ_TYPE,
PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, FEC_OBJ_MINIMUM_LENGTH);
private PcepObjectHeader fecObjHeader;
private byte[] localIPv6Address = new byte[IPV6_ADDRESS_LENGTH];
private byte[] remoteIPv6Address = new byte[IPV6_ADDRESS_LENGTH];
/**
* Constructor to initialize parameters for PCEP fec object.
*
* @param fecObjHeader fec object header
* @param localIPv6Address local IPv6 address
* @param remoteIPv6Address remote IPv6 address
*/
public PcepFecObjectIPv6AdjacencyVer1(PcepObjectHeader fecObjHeader, byte[] localIPv6Address,
byte[] remoteIPv6Address) {
this.fecObjHeader = fecObjHeader;
this.localIPv6Address = localIPv6Address;
this.remoteIPv6Address = remoteIPv6Address;
}
/**
* Sets Object Header.
*
* @param obj object header
*/
public void setFecIpv4ObjHeader(PcepObjectHeader obj) {
this.fecObjHeader = obj;
}
@Override
public byte[] getLocalIPv6Address() {
return this.localIPv6Address;
}
@Override
public void seLocalIPv6Address(byte[] value) {
this.localIPv6Address = value;
}
@Override
public byte[] getRemoteIPv6Address() {
return this.remoteIPv6Address;
}
@Override
public void seRemoteIPv6Address(byte[] value) {
this.remoteIPv6Address = value;
}
/**
* Reads channel buffer and Returns object of PcepFecObjectIPv6Adjacency.
*
* @param cb of channel buffer
* @return object of PcepFecObjectIPv6Adjacency
* @throws PcepParseException when fails tp read from channel buffer
*/
public static PcepFecObjectIPv6Adjacency read(ChannelBuffer cb) throws PcepParseException {
PcepObjectHeader fecObjHeader;
byte[] localIPv6Address = new byte[IPV6_ADDRESS_LENGTH];
byte[] remoteIPv6Address = new byte[IPV6_ADDRESS_LENGTH];
fecObjHeader = PcepObjectHeader.read(cb);
cb.readBytes(localIPv6Address, 0, IPV6_ADDRESS_LENGTH);
cb.readBytes(remoteIPv6Address, 0, IPV6_ADDRESS_LENGTH);
return new PcepFecObjectIPv6AdjacencyVer1(fecObjHeader, localIPv6Address, remoteIPv6Address);
}
@Override
public int write(ChannelBuffer cb) throws PcepParseException {
int objStartIndex = cb.writerIndex();
//write common header
int objLenIndex = fecObjHeader.write(cb);
cb.writeBytes(localIPv6Address);
cb.writeBytes(remoteIPv6Address);
//now write FEC IPv6 Adjacency Object Length
cb.setShort(objLenIndex, (short) (cb.writerIndex() - objStartIndex));
return cb.writerIndex();
}
/**
* Builder class for PCEP fec object IPv6 Adjacency.
*/
public static class Builder implements PcepFecObjectIPv6Adjacency.Builder {
private boolean bIsHeaderSet = false;
private boolean bIsLocalIPv6Addressset = false;
private boolean bIsRemoteIPv6Addressset = false;
private PcepObjectHeader fecObjHeader;
byte[] localIPv6Address = new byte[IPV6_ADDRESS_LENGTH];
byte[] remoteIPv6Address = new byte[IPV6_ADDRESS_LENGTH];
private boolean bIsPFlagSet = false;
private boolean bPFlag;
private boolean bIsIFlagSet = false;
private boolean bIFlag;
@Override
public PcepFecObjectIPv6Adjacency build() throws PcepParseException {
PcepObjectHeader fecObjHeader = this.bIsHeaderSet ? this.fecObjHeader : DEFAULT_FEC_OBJECT_HEADER;
if (!this.bIsLocalIPv6Addressset) {
throw new PcepParseException(
"Local IPv6 Address not set while building PcepFecObjectIPv6Adjacency object.");
}
if (!this.bIsRemoteIPv6Addressset) {
throw new PcepParseException(
"Remote IPv6 Address not set while building PcepFecObjectIPv6Adjacency object.");
}
if (bIsPFlagSet) {
fecObjHeader.setPFlag(bPFlag);
}
if (bIsIFlagSet) {
fecObjHeader.setIFlag(bIFlag);
}
return new PcepFecObjectIPv6AdjacencyVer1(fecObjHeader, this.localIPv6Address, this.remoteIPv6Address);
}
@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 PcepObjectHeader getFecIpv6AdjacencyObjHeader() {
return this.fecObjHeader;
}
@Override
public Builder setFecIpv6AdjacencyObjHeader(PcepObjectHeader obj) {
this.fecObjHeader = obj;
this.bIsHeaderSet = true;
return this;
}
@Override
public byte[] getLocalIPv6Address() {
return this.localIPv6Address;
}
@Override
public Builder setLocalIPv6Address(byte[] value) {
this.localIPv6Address = value;
this.bIsLocalIPv6Addressset = true;
return this;
}
@Override
public byte[] getRemoteIPv6Address() {
return this.remoteIPv6Address;
}
@Override
public Builder setRemoteIPv6Address(byte[] value) {
this.remoteIPv6Address = value;
this.bIsRemoteIPv6Addressset = true;
return this;
}
}
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
@Override
public int getType() {
return FEC_OBJ_TYPE;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass()).add("localIPv6Address", localIPv6Address)
.add("remoteIPv6Address: ", remoteIPv6Address).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.PcepFecObjectIPv6;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.onosproject.pcepio.types.PcepObjectHeader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
public class PcepFecObjectIPv6Ver1 implements PcepFecObjectIPv6 {
/*
* ref : draft-zhao-pce-pcep-extension-for-pce-controller-01 , section : 7.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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
// IPv6 Node ID (16 bytes) //
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
FEC Object-Type is 2 IPv6 Node ID
*/
protected static final Logger log = LoggerFactory.getLogger(PcepFecObjectIPv6Ver1.class);
public static final byte FEC_OBJ_TYPE = 2;
public static final byte FEC_OBJ_CLASS = 63; //to be defined
public static final byte FEC_OBJECT_VERSION = 1;
public static final short FEC_OBJ_MINIMUM_LENGTH = 20;
public static final int MINIMUM_COMMON_HEADER_LENGTH = 4;
public static final int IPV6_ADDRESS_LENGTH = 16;
static final PcepObjectHeader DEFAULT_FEC_OBJECT_HEADER = new PcepObjectHeader(FEC_OBJ_CLASS, FEC_OBJ_TYPE,
PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, FEC_OBJ_MINIMUM_LENGTH);
private PcepObjectHeader fecObjHeader;
private byte[] nodeID = new byte[IPV6_ADDRESS_LENGTH];
/**
* Constructor to initialize parameters for PCEP fec object.
*
* @param fecObjHeader Fec object header
* @param nodeID node ID
*/
public PcepFecObjectIPv6Ver1(PcepObjectHeader fecObjHeader, byte[] nodeID) {
this.fecObjHeader = fecObjHeader;
this.nodeID = nodeID;
}
/**
* Sets the Object header.
*
* @param obj object header
*/
public void setFecIpv6ObjHeader(PcepObjectHeader obj) {
this.fecObjHeader = obj;
}
@Override
public void setNodeID(byte[] nodeID) {
this.nodeID = nodeID;
}
/**
* Returns object header.
*
* @return fec Object Header
*/
public PcepObjectHeader getFecIpv6ObjHeader() {
return this.fecObjHeader;
}
@Override
public byte[] getNodeID() {
return this.nodeID;
}
/**
* reads the channel buffer and returns object of PcepFecObjectIPv6.
*
* @param cb of channel buffer.
* @return object of PcepFecObjectIPv6
* @throws PcepParseException when fails to read from channel buffer
*/
public static PcepFecObjectIPv6 read(ChannelBuffer cb) throws PcepParseException {
PcepObjectHeader fecObjHeader;
byte[] nodeID = new byte[IPV6_ADDRESS_LENGTH];
fecObjHeader = PcepObjectHeader.read(cb);
cb.readBytes(nodeID, 0, IPV6_ADDRESS_LENGTH);
return new PcepFecObjectIPv6Ver1(fecObjHeader, nodeID);
}
@Override
public int write(ChannelBuffer cb) throws PcepParseException {
int objStartIndex = cb.writerIndex();
//write common header
int objLenIndex = fecObjHeader.write(cb);
cb.writeBytes(nodeID);
//now write FEC IPv4 Object Length
cb.setShort(objLenIndex, (short) (cb.writerIndex() - objStartIndex));
return cb.writerIndex();
}
/**
* Builder class for PCEP fec object IPv6.
*/
public static class Builder implements PcepFecObjectIPv6.Builder {
private boolean bIsHeaderSet = false;
private boolean bIsNodeIdset = false;
private PcepObjectHeader fecObjHeader;
private byte[] nodeID = new byte[IPV6_ADDRESS_LENGTH];
private boolean bIsPFlagSet = false;
private boolean bPFlag;
private boolean bIsIFlagSet = false;
private boolean bIFlag;
@Override
public PcepFecObjectIPv6 build() throws PcepParseException {
PcepObjectHeader fecObjHeader = this.bIsHeaderSet ? this.fecObjHeader : DEFAULT_FEC_OBJECT_HEADER;
if (!this.bIsNodeIdset) {
throw new PcepParseException(" NodeID not set while building PcepFecObjectIPv6 object.");
}
if (bIsPFlagSet) {
fecObjHeader.setPFlag(bPFlag);
}
if (bIsIFlagSet) {
fecObjHeader.setIFlag(bIFlag);
}
return new PcepFecObjectIPv6Ver1(fecObjHeader, this.nodeID);
}
@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 PcepObjectHeader getFecIpv6ObjHeader() {
return this.fecObjHeader;
}
@Override
public Builder setFecIpv6ObjHeader(PcepObjectHeader obj) {
this.fecObjHeader = obj;
this.bIsHeaderSet = true;
return this;
}
@Override
public byte[] getNodeID() {
return this.nodeID;
}
@Override
public Builder setNodeID(byte[] value) {
this.nodeID = value;
this.bIsNodeIdset = true;
return this;
}
}
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
@Override
public int getType() {
return FEC_OBJ_TYPE;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass()).add("fecObjHeader", fecObjHeader).add("NodeID: ", nodeID)
.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.PcepLabelUpdate;
import org.onosproject.pcepio.protocol.PcepLabelUpdateMsg;
import org.onosproject.pcepio.protocol.PcepMessageReader;
import org.onosproject.pcepio.protocol.PcepMessageWriter;
import org.onosproject.pcepio.protocol.PcepType;
import org.onosproject.pcepio.protocol.PcepVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
class PcepLabelUpdateMsgVer1 implements PcepLabelUpdateMsg {
// Pcep version: 1
/*
The format of the PCLabelUpd message:
<PCLabelUpd Message> ::= <Common Header>
<pce-label-update-list>
Where:
<pce-label-update-list> ::= <pce-label-update>
[<pce-label-update-list>]
<pce-label-update> ::= (<pce-label-download>|<pce-label-map>)
Where:
<pce-label-download> ::= <SRP>
<LSP>
<label-list>
<pce-label-map> ::= <SRP>
<LABEL>
<FEC>
<label-list > ::= <LABEL>
[<label-list>]
*/
protected static final Logger log = LoggerFactory.getLogger(PcepLabelUpdateMsgVer1.class);
public static final byte PACKET_VERSION = 1;
//LabelUpdateMsgMinLength = COMMON-HEADER(4)+SrpObjMinLentgh(12)+LabelObjectMinLength(12)+FECType1Object(8)
public static final int PACKET_MINIMUM_LENGTH = 36;
public static final PcepType MSG_TYPE = PcepType.LABEL_UPDATE;
//pce-label-update-list
private LinkedList<PcepLabelUpdate> llPcLabelUpdateList;
static final PcepLabelUpdateMsgVer1.Reader READER = new Reader();
//Reader reads LabelUpdate Message from the channel.
static class Reader implements PcepMessageReader<PcepLabelUpdateMsg> {
@Override
public PcepLabelUpdateMsg readFrom(ChannelBuffer cb) throws PcepParseException {
if (cb.readableBytes() < PACKET_MINIMUM_LENGTH) {
throw new PcepParseException("Readable bytes are less than Packet minimum length.");
}
// fixed value property version == 1
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 == 13
byte type = cb.readByte();
if (type != MSG_TYPE.getType()) {
throw new PcepParseException("Wrong type. Expected=PcepType.LABEL_UPDATE(13), got=" + type);
}
short length = cb.readShort();
if (length < PACKET_MINIMUM_LENGTH) {
throw new PcepParseException("Wrong length. Expected to be >= " + PACKET_MINIMUM_LENGTH + ", is: "
+ length);
}
// parse <pce-label-download> / <pce-label-map>
LinkedList<PcepLabelUpdate> llPcLabelUpdateList = parsePcLabelUpdateList(cb);
return new PcepLabelUpdateMsgVer1(llPcLabelUpdateList);
}
/**
* Returns list of PCEP Label Update object.
*
* @param cb of type channel buffer
* @return llPcLabelUpdateList list of PCEP label update object
* @throws PcepParseException when fails to parse list of PCEP label update object
*/
public LinkedList<PcepLabelUpdate> parsePcLabelUpdateList(ChannelBuffer cb) throws PcepParseException {
LinkedList<PcepLabelUpdate> llPcLabelUpdateList;
llPcLabelUpdateList = new LinkedList<PcepLabelUpdate>();
while (0 < cb.readableBytes()) {
llPcLabelUpdateList.add(PcepLabelUpdateVer1.read(cb));
}
return llPcLabelUpdateList;
}
}
/**
* Constructor to initialize PCEP Label Update List.
*
* @param llPcLabelUpdateList list of PCEP Label Update object
*/
PcepLabelUpdateMsgVer1(LinkedList<PcepLabelUpdate> llPcLabelUpdateList) {
this.llPcLabelUpdateList = llPcLabelUpdateList;
}
static class Builder implements PcepLabelUpdateMsg.Builder {
LinkedList<PcepLabelUpdate> llPcLabelUpdateList;
@Override
public PcepVersion getVersion() {
return PcepVersion.PCEP_1;
}
@Override
public PcepType getType() {
return PcepType.LABEL_UPDATE;
}
@Override
public PcepLabelUpdateMsg build() {
return new PcepLabelUpdateMsgVer1(this.llPcLabelUpdateList);
}
@Override
public LinkedList<PcepLabelUpdate> getPcLabelUpdateList() {
return this.llPcLabelUpdateList;
}
@Override
public Builder setPcLabelUpdateList(LinkedList<PcepLabelUpdate> ll) {
this.llPcLabelUpdateList = ll;
return this;
}
}
@Override
public void writeTo(ChannelBuffer cb) throws PcepParseException {
WRITER.write(cb, this);
}
static final Writer WRITER = new Writer();
//Writer writes LabelUpdate Message to the channel.
static class Writer implements PcepMessageWriter<PcepLabelUpdateMsgVer1> {
@Override
public void write(ChannelBuffer cb, PcepLabelUpdateMsgVer1 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 will be set after calculating length, but currently set it as 0.
int msgLenIndex = cb.writerIndex();
cb.writeShort((short) 0);
ListIterator<PcepLabelUpdate> listIterator = message.llPcLabelUpdateList.listIterator();
while (listIterator.hasNext()) {
PcepLabelUpdate labelUpdate = listIterator.next();
labelUpdate.write(cb);
}
// update 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 LinkedList<PcepLabelUpdate> getPcLabelUpdateList() {
return this.llPcLabelUpdateList;
}
@Override
public void setPcLabelUpdateList(LinkedList<PcepLabelUpdate> ll) {
this.llPcLabelUpdateList = ll;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass()).add("PcLabelUpdateList", llPcLabelUpdateList).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;
/**
* NexthopIPv6addressTlv provides Ipv4 address of next hop.
*/
public class NexthopIPv4addressTlv implements PcepValueType {
/*
Reference :draft-zhao-pce-pcep-extension-for-pce-controller-01
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=TBD | Length = 8 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| nexthop IPv4 address |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
NEXTHOP-IPV4-ADDRESS TLV
*/
protected static final Logger log = LoggerFactory.getLogger(NexthopIPv4addressTlv.class);
public static final short TYPE = 2; //to be defined
//Length is header + value
public static final short LENGTH = 8;
public static final short VALUE_LENGTH = 4;
private final int rawValue;
/**
* Constructor to initialize next hop IPv4 address.
*
* @param rawValue next hop IPv4 address
*/
public NexthopIPv4addressTlv(int rawValue) {
this.rawValue = rawValue;
}
/**
* Return next hop IPv4 address tlv.
*
* @param raw of next hop IPv4 address
* @return object of NexthopIPv4addressTlv
*/
public static NexthopIPv4addressTlv of(final int raw) {
return new NexthopIPv4addressTlv(raw);
}
/**
* Returns next hop IPv4 address.
*
* @return next hop IPv4 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 NexthopIPv4addressTlv) {
NexthopIPv4addressTlv other = (NexthopIPv4addressTlv) obj;
return Objects.equals(this.rawValue, other.rawValue);
}
return false;
}
@Override
public int write(ChannelBuffer c) {
int iStartIndex = c.writerIndex();
c.writeShort(TYPE);
c.writeShort(LENGTH);
c.writeInt(rawValue);
return c.writerIndex() - iStartIndex;
}
/**
* Reads the channel buffer and returns object of NexthopIPv4addressTlv.
*
* @param c type of channel buffer
* @return object of NexthopIPv4addressTlv
*/
public static NexthopIPv4addressTlv read(ChannelBuffer c) {
return NexthopIPv4addressTlv.of(c.readInt());
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("Type", TYPE)
.add("Length", LENGTH)
.add("Ipv4Address ", 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;
/**
* NexthopIPv6addressTlv provides Ipv6 address of next hop.
*/
public class NexthopIPv6addressTlv implements PcepValueType {
/*
Reference: draft-zhao-pce-pcep-extension-for-pce-controller-01.
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=TBD | Length = 20 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
// nexthop IPv6 address (16 bytes) //
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
NEXTHOP-IPV6-ADDRESS TLV:
*/
protected static final Logger log = LoggerFactory.getLogger(NexthopIPv6addressTlv.class);
public static final short TYPE = 100; //to be defined
//Length is header + value
public static final short LENGTH = 20;
public static final short VALUE_LENGTH = 16;
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 NexthopIPv6addressTlv NONE = new NexthopIPv6addressTlv(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 NexthopIPv6addressTlv NO_MASK = new NexthopIPv6addressTlv(NO_MASK_VAL);
public static final NexthopIPv6addressTlv FULL_MASK = NONE;
private final byte[] rawValue;
/**
* Constructor to initialize IP address for next hop IPv6 address tlv.
*
* @param rawValue value of Next hop ipAddress
*/
public NexthopIPv6addressTlv(byte[] rawValue) {
log.debug("NexthopIPv6addressTlv");
this.rawValue = rawValue;
}
/**
* Creates next hop IPv6 address tlv.
*
* @param raw value of Next hop ipAddress
* @return object of NexthopIPv6addressTlv
*/
//logic to be checked
public static NexthopIPv6addressTlv of(final byte[] raw) {
//check NONE_VAL
boolean bFoundNONE = true;
//value starts from 3rd byte.
for (int i = 5; 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 = 5; i < 20; ++i) {
if (0xFF != raw[i]) {
bFoundNoMask = false;
}
}
if (bFoundNoMask) {
return NO_MASK;
}
return new NexthopIPv6addressTlv(raw);
}
/**
* Returns next hop IPv6 address.
*
* @return next hop IPv6 address
*/
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 NexthopIPv6addressTlv) {
NexthopIPv6addressTlv other = (NexthopIPv6addressTlv) obj;
return Objects.equals(this.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 NexthopIPv6addressTlv.
*
* @param c type of channel buffer
* @return object of NexthopIPv6addressTlv
*/
public static NexthopIPv6addressTlv read(ChannelBuffer c) {
byte[] yTemp = new byte[20];
c.readBytes(yTemp, 0, 20);
return NexthopIPv6addressTlv.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("IpAddress", 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;
/**
* NexthopUnnumberedIPv4IDTlv provides the next node's ID and Interface ID.
*/
public class NexthopUnnumberedIPv4IDTlv implements PcepValueType {
/*
Reference : draft-zhao-pce-pcep-extension-for-pce-controller-01.
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=TBD | Length = 12 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Node-ID |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Interface ID |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
NEXTHOP-UNNUMBERED-IPV4-ID TLV
*/
protected static final Logger log = LoggerFactory.getLogger(NexthopUnnumberedIPv4IDTlv.class);
public static final short TYPE = 1; //to be defined
//Length is header + value
public static final short LENGTH = 12;
private final int nodeID;
private final int interfaceID;
/**
* constructor to initialize nodeID and interfaceID.
*
* @param nodeID node ID
* @param interfaceID interface ID
*/
public NexthopUnnumberedIPv4IDTlv(int nodeID, int interfaceID) {
this.nodeID = nodeID;
this.interfaceID = interfaceID;
}
/**
* Returns new object of NexthopUnnumberedIPv4IDTlv.
*
* @param nodeID node ID
* @param interfaceID interface ID
* @return NexthopUnnumberedIPv4IDTlv
*/
public static NexthopUnnumberedIPv4IDTlv of(int nodeID, int interfaceID) {
return new NexthopUnnumberedIPv4IDTlv(nodeID, interfaceID);
}
/**
* Returns Node Id.
*
* @return node ID
*/
public int getNodeID() {
return nodeID;
}
/**
* Returns Interface Id.
*
* @return interface ID
*/
public int getInterfaceID() {
return interfaceID;
}
@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(nodeID, interfaceID);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof NexthopUnnumberedIPv4IDTlv) {
NexthopUnnumberedIPv4IDTlv other = (NexthopUnnumberedIPv4IDTlv) obj;
return Objects.equals(this.nodeID, other.nodeID) && Objects.equals(this.interfaceID, other.interfaceID);
}
return false;
}
@Override
public int write(ChannelBuffer c) {
int iLenStartIndex = c.writerIndex();
c.writeShort(TYPE);
c.writeShort(LENGTH);
c.writeInt(nodeID);
c.writeInt(interfaceID);
return c.writerIndex() - iLenStartIndex;
}
/**
* Reads the channel buffer and returns object of NexthopUnnumberedIPv4IDTlv.
*
* @param cb type of channel buffer
* @return object of NexthopUnnumberedIPv4IDTlv
*/
public static NexthopUnnumberedIPv4IDTlv read(ChannelBuffer cb) {
int nodeID = cb.readInt();
int interfaceID = cb.readInt();
return new NexthopUnnumberedIPv4IDTlv(nodeID, interfaceID);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH).add("NodeId", nodeID)
.add("InterfaceId", interfaceID).toString();
}
}