[ONOS-2356] Implementation for PCEP label update message.
Change-Id: I510a9a7c7c868da1fc3d6e2625501f094faf8115
diff --git a/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv4AdjacencyVer1.java b/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv4AdjacencyVer1.java
new file mode 100644
index 0000000..b9d055f
--- /dev/null
+++ b/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv4AdjacencyVer1.java
@@ -0,0 +1,248 @@
+/*
+ * 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();
+ }
+}
diff --git a/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv4UnnumberedAdjacencyVer1.java b/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv4UnnumberedAdjacencyVer1.java
new file mode 100644
index 0000000..f61fe67
--- /dev/null
+++ b/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv4UnnumberedAdjacencyVer1.java
@@ -0,0 +1,330 @@
+/*
+ * 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.PcepFecObjectIPv4UnnumberedAdjacency;
+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 PcepFecObjectIPv4UnnumberedAdjacencyVer1 implements PcepFecObjectIPv4UnnumberedAdjacency {
+
+ /*
+ * 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 Node-ID |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Local Interface ID |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Remote Node-ID |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Remote Interface ID |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ FEC Object-Type is 5, Unnumbered Adjacency with IPv4 NodeIDs
+ */
+ protected static final Logger log = LoggerFactory.getLogger(PcepFecObjectIPv4UnnumberedAdjacencyVer1.class);
+
+ public static final byte FEC_OBJ_TYPE = 5;
+ 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;
+
+ 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 localNodeID;
+ private int localInterfaceID;
+ private int remoteNodeID;
+ private int remoteInterfaceID;
+
+ /**
+ * Constructor to initialize parameter for PCEP fec object.
+ *
+ * @param fecObjHeader fec object header
+ * @param localNodeID local node ID
+ * @param localInterfaceID local interface ID
+ * @param remoteNodeID remote node ID
+ * @param remoteInterfaceID remote interface ID
+ */
+ public PcepFecObjectIPv4UnnumberedAdjacencyVer1(PcepObjectHeader fecObjHeader, int localNodeID,
+ int localInterfaceID, int remoteNodeID, int remoteInterfaceID) {
+ this.fecObjHeader = fecObjHeader;
+ this.localNodeID = localNodeID;
+ this.localInterfaceID = localInterfaceID;
+ this.remoteNodeID = remoteNodeID;
+ this.remoteInterfaceID = remoteInterfaceID;
+ }
+
+ /**
+ * Sets Object Header.
+ *
+ * @param obj object header
+ */
+ public void setFecIpv4UnnumberedAdjacencyObjHeader(PcepObjectHeader obj) {
+ this.fecObjHeader = obj;
+ }
+
+ @Override
+ public void setLocalNodeID(int localNodeID) {
+ this.localNodeID = localNodeID;
+ }
+
+ /**
+ * Returns Object Header.
+ *
+ * @return fecObjHeader fec object header
+ */
+ public PcepObjectHeader getFecIpv4UnnumberedAdjacencyObjHeader() {
+ return this.fecObjHeader;
+ }
+
+ @Override
+ public int getLocalNodeID() {
+ return this.localNodeID;
+ }
+
+ @Override
+ public int getLocalInterfaceID() {
+ return this.localInterfaceID;
+ }
+
+ @Override
+ public void setLocalInterfaceID(int localInterfaceID) {
+ this.localInterfaceID = localInterfaceID;
+ }
+
+ @Override
+ public int getRemoteNodeID() {
+ return this.remoteNodeID;
+ }
+
+ @Override
+ public void setRemoteNodeID(int remoteNodeID) {
+ this.remoteNodeID = remoteNodeID;
+ }
+
+ @Override
+ public int getRemoteInterfaceID() {
+ return this.remoteInterfaceID;
+ }
+
+ @Override
+ public void setRemoteInterfaceID(int remoteInterfaceID) {
+ this.remoteInterfaceID = remoteInterfaceID;
+ }
+
+ /**
+ * Reads from channel buffer and returns object of PcepFecObjectIPv4UnnumberedAdjacency.
+ *
+ * @param cb of channel buffer
+ * @return object of PcepFecObjectIPv4UnnumberedAdjacency
+ * @throws PcepParseException when fails to read from channel buffer
+ */
+ public static PcepFecObjectIPv4UnnumberedAdjacency read(ChannelBuffer cb) throws PcepParseException {
+
+ PcepObjectHeader fecObjHeader;
+ int localNodeID;
+ int localInterfaceID;
+ int remoteNodeID;
+ int remoteInterfaceID;
+
+ fecObjHeader = PcepObjectHeader.read(cb);
+
+ //take only FEC IPv4 Unnumbered Adjacency Object buffer.
+ ChannelBuffer tempCb = cb.readBytes(fecObjHeader.getObjLen() - MINIMUM_COMMON_HEADER_LENGTH);
+ localNodeID = tempCb.readInt();
+ localInterfaceID = tempCb.readInt();
+ remoteNodeID = tempCb.readInt();
+ remoteInterfaceID = tempCb.readInt();
+
+ return new PcepFecObjectIPv4UnnumberedAdjacencyVer1(fecObjHeader, localNodeID, localInterfaceID, remoteNodeID,
+ remoteInterfaceID);
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) throws PcepParseException {
+
+ int objStartIndex = cb.writerIndex();
+
+ //Write common header
+ int objLenIndex = fecObjHeader.write(cb);
+ cb.writeInt(localNodeID);
+ cb.writeInt(localInterfaceID);
+ cb.writeInt(remoteNodeID);
+ cb.writeInt(remoteInterfaceID);
+
+ //Now write FEC IPv4 Unnumbered Adjacency Object Length
+ cb.setShort(objLenIndex, (short) (cb.writerIndex() - objStartIndex));
+
+ return cb.writerIndex();
+ }
+
+ /**
+ * Builder class for PCEP Fec object IPv4 unnumbered Adjacency.
+ */
+ public static class Builder implements PcepFecObjectIPv4UnnumberedAdjacency.Builder {
+ private boolean bIsHeaderSet = false;
+ private boolean bIsLocalNodeIDset = false;
+ private boolean bIsLocalInterfaceIDset = false;
+ private boolean bIsRemoteNodeIDset = false;
+ private boolean bIsRemoteInterfaceIDset = false;
+
+ private PcepObjectHeader fecObjHeader;
+ private int localNodeID;
+ private int localInterfaceID;
+ private int remoteNodeID;
+ private int remoteInterfaceID;
+
+ private boolean bIsPFlagSet = false;
+ private boolean bPFlag;
+
+ private boolean bIsIFlagSet = false;
+ private boolean bIFlag;
+
+ @Override
+ public PcepFecObjectIPv4UnnumberedAdjacency build() throws PcepParseException {
+ PcepObjectHeader fecObjHeader = this.bIsHeaderSet ? this.fecObjHeader : DEFAULT_FEC_OBJECT_HEADER;
+
+ if (!this.bIsLocalNodeIDset) {
+ throw new PcepParseException(
+ " Local Node ID not set while building PcepFecObjectIPv4UnnumberedAdjacency object.");
+ }
+ if (!this.bIsLocalInterfaceIDset) {
+ throw new PcepParseException(
+ " Local Interface ID not set while building PcepFecObjectIPv4UnnumberedAdjacency object.");
+ }
+ if (!this.bIsRemoteNodeIDset) {
+ throw new PcepParseException(
+ " Remote Node ID not set while building PcepFecObjectIPv4UnnumberedAdjacency object.");
+ }
+ if (!this.bIsRemoteInterfaceIDset) {
+ throw new PcepParseException(
+ " Remote Interface ID not set while building PcepFecObjectIPv4UnnumberedAdjacency object.");
+ }
+ if (bIsPFlagSet) {
+ fecObjHeader.setPFlag(bPFlag);
+ }
+ if (bIsIFlagSet) {
+ fecObjHeader.setIFlag(bIFlag);
+ }
+ return new PcepFecObjectIPv4UnnumberedAdjacencyVer1(fecObjHeader, this.localNodeID, this.localInterfaceID,
+ this.remoteNodeID, this.remoteInterfaceID);
+ }
+
+ @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 getFecIpv4UnnumberedAdjacencyObjHeader() {
+ return this.fecObjHeader;
+ }
+
+ @Override
+ public Builder setFecIpv4UnnumberedAdjacencyObjHeader(PcepObjectHeader obj) {
+ this.fecObjHeader = obj;
+ this.bIsHeaderSet = true;
+ return this;
+ }
+
+ @Override
+ public int getLocalNodeID() {
+ return this.localNodeID;
+ }
+
+ @Override
+ public Builder setLocalNodeID(int value) {
+ this.localNodeID = value;
+ this.bIsLocalNodeIDset = true;
+ return this;
+ }
+
+ @Override
+ public int getLocalInterfaceID() {
+ return this.localInterfaceID;
+ }
+
+ @Override
+ public Builder setLocalInterfaceID(int value) {
+ this.localInterfaceID = value;
+ this.bIsLocalInterfaceIDset = true;
+ return this;
+ }
+
+ @Override
+ public int getRemoteNodeID() {
+ return this.remoteNodeID;
+ }
+
+ @Override
+ public Builder setRemoteNodeID(int value) {
+ this.remoteNodeID = value;
+ this.bIsRemoteNodeIDset = true;
+ return this;
+ }
+
+ @Override
+ public int getRemoteInterfaceID() {
+ return this.remoteInterfaceID;
+ }
+
+ @Override
+ public Builder setRemoteInterfaceID(int value) {
+ this.remoteInterfaceID = value;
+ this.bIsRemoteInterfaceIDset = 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("LocalNodeID: ", localNodeID)
+ .add("LocalInterfaceID: ", localInterfaceID).add("RemoteNodeID: ", remoteNodeID)
+ .add("RemoteInterfaceID: ", remoteInterfaceID).toString();
+ }
+}
diff --git a/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv4Ver1.java b/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv4Ver1.java
new file mode 100644
index 0000000..20ece97
--- /dev/null
+++ b/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv4Ver1.java
@@ -0,0 +1,212 @@
+/*
+ * 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();
+ }
+}
diff --git a/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv6AdjacencyVer1.java b/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv6AdjacencyVer1.java
new file mode 100644
index 0000000..856f667
--- /dev/null
+++ b/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv6AdjacencyVer1.java
@@ -0,0 +1,244 @@
+/*
+ * 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();
+ }
+}
diff --git a/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv6Ver1.java b/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv6Ver1.java
new file mode 100644
index 0000000..3895ae9
--- /dev/null
+++ b/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv6Ver1.java
@@ -0,0 +1,215 @@
+/*
+ * 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();
+ }
+}
diff --git a/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelObjectVer1.java b/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelObjectVer1.java
new file mode 100644
index 0000000..834054b
--- /dev/null
+++ b/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelObjectVer1.java
@@ -0,0 +1,364 @@
+/*
+ * 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.PcepLabelObject;
+import org.onosproject.pcepio.types.NexthopIPv4addressTlv;
+import org.onosproject.pcepio.types.NexthopIPv6addressTlv;
+import org.onosproject.pcepio.types.NexthopUnnumberedIPv4IDTlv;
+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;
+
+/*
+ * ref : draft-zhao-pce-pcep-extension-for-pce-controller-01 , section : 7.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
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Reserved | Flags |O|
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Label |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | |
+ // Optional TLV //
+ | |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ The LABEL Object format
+ */
+public class PcepLabelObjectVer1 implements PcepLabelObject {
+
+ protected static final Logger log = LoggerFactory.getLogger(PcepLspObjectVer1.class);
+
+ public static final byte LABEL_OBJ_TYPE = 1;
+ public static final byte LABEL_OBJ_CLASS = 35; //TBD : to be defined
+ public static final byte LABEL_OBJECT_VERSION = 1;
+ public static final byte OBJECT_HEADER_LENGTH = 4;
+ public static final boolean DEFAULT_OFLAG = false;
+
+ // LSP_OBJ_MINIMUM_LENGTH = CommonHeaderLen(4)+ LspObjectHeaderLen(8)
+ public static final short LABEL_OBJ_MINIMUM_LENGTH = 12;
+
+ public static final int OFLAG_SET = 1;
+ public static final int OFLAG_RESET = 0;
+ public static final int MINIMUM_COMMON_HEADER_LENGTH = 4;
+
+ static final PcepObjectHeader DEFAULT_LABEL_OBJECT_HEADER = new PcepObjectHeader(LABEL_OBJ_CLASS, LABEL_OBJ_TYPE,
+ PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, LABEL_OBJ_MINIMUM_LENGTH);
+
+ private PcepObjectHeader labelObjHeader;
+ private boolean bOFlag;
+ private int label;
+ // Optional TLV
+ private LinkedList<PcepValueType> llOptionalTlv;
+
+ /**
+ * Constructor to initialize parameters for PCEP label object.
+ *
+ * @param labelObjHeader label object header
+ * @param bOFlag O flag
+ * @param label label
+ * @param llOptionalTlv list of optional tlvs
+ */
+ public PcepLabelObjectVer1(PcepObjectHeader labelObjHeader, boolean bOFlag, int label,
+ LinkedList<PcepValueType> llOptionalTlv) {
+ this.labelObjHeader = labelObjHeader;
+ this.bOFlag = bOFlag;
+ this.label = label;
+ this.llOptionalTlv = llOptionalTlv;
+ }
+
+ @Override
+ public LinkedList<PcepValueType> getOptionalTlv() {
+ return this.llOptionalTlv;
+ }
+
+ @Override
+ public void setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) {
+ this.llOptionalTlv = llOptionalTlv;
+ }
+
+ @Override
+ public boolean getOFlag() {
+ return this.bOFlag;
+ }
+
+ @Override
+ public void setOFlag(boolean value) {
+ this.bOFlag = value;
+ }
+
+ @Override
+ public int getLabel() {
+ return this.label;
+ }
+
+ @Override
+ public void setLabel(int value) {
+ this.label = value;
+ }
+
+ /**
+ * Reads form channel buffer and returns objects of PcepLabelObject.
+ *
+ * @param cb of type channel buffer
+ * @return objects of PcepLabelObject
+ * @throws PcepParseException when fails to read from channel buffer
+ */
+ public static PcepLabelObject read(ChannelBuffer cb) throws PcepParseException {
+
+ PcepObjectHeader labelObjHeader;
+
+ boolean bOFlag;
+ int label;
+
+ // Optional TLV
+ LinkedList<PcepValueType> llOptionalTlv = new LinkedList<PcepValueType>();
+ labelObjHeader = PcepObjectHeader.read(cb);
+
+ //take only LspObject buffer.
+ ChannelBuffer tempCb = cb.readBytes(labelObjHeader.getObjLen() - OBJECT_HEADER_LENGTH);
+
+ int iTemp = tempCb.readInt();
+ bOFlag = (iTemp & (byte) 0x01) == 1 ? true : false;
+ label = tempCb.readInt();
+
+ // parse optional TLV
+ llOptionalTlv = parseOptionalTlv(tempCb);
+ return new PcepLabelObjectVer1(labelObjHeader, bOFlag, label, llOptionalTlv);
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) throws PcepParseException {
+
+ //write Object header
+ int objStartIndex = cb.writerIndex();
+ int objLenIndex = labelObjHeader.write(cb);
+
+ if (objLenIndex <= 0) {
+ throw new PcepParseException(" ObjectLength Index is " + objLenIndex);
+ }
+
+ byte oFlag;
+
+ oFlag = (byte) ((bOFlag) ? OFLAG_SET : OFLAG_RESET);
+ cb.writeInt(oFlag);
+ cb.writeInt(label);
+
+ // Add optional TLV
+ packOptionalTlv(cb);
+
+ //Update object length now
+ int length = cb.writerIndex() - objStartIndex;
+
+ //will be helpful during print().
+ labelObjHeader.setObjLen((short) length);
+ cb.setShort(objLenIndex, (short) length);
+ return cb.writerIndex();
+ }
+
+ /**
+ * Returns list of optional tlvs.
+ *
+ * @param cb of type channel buffer
+ * @return list of optional tlvs.
+ * @throws PcepParseException when fails to parse list of optional tlvs
+ */
+ protected static LinkedList<PcepValueType> parseOptionalTlv(ChannelBuffer cb) throws PcepParseException {
+
+ LinkedList<PcepValueType> llOutOptionalTlv = new LinkedList<PcepValueType>();
+
+ while (MINIMUM_COMMON_HEADER_LENGTH <= cb.readableBytes()) {
+
+ PcepValueType tlv;
+ short hType = cb.readShort();
+ short hLength = cb.readShort();
+ int iValue = 0;
+
+ switch (hType) {
+
+ case NexthopIPv4addressTlv.TYPE:
+ iValue = cb.readInt();
+ tlv = new NexthopIPv4addressTlv(iValue);
+ break;
+ case NexthopIPv6addressTlv.TYPE:
+ byte[] ipv6Value = new byte[NexthopIPv6addressTlv.VALUE_LENGTH];
+ cb.readBytes(ipv6Value, 0, NexthopIPv6addressTlv.VALUE_LENGTH);
+ tlv = new NexthopIPv6addressTlv(ipv6Value);
+ break;
+ case NexthopUnnumberedIPv4IDTlv.TYPE:
+ tlv = NexthopUnnumberedIPv4IDTlv.read(cb);
+ 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 channel buffer.
+ * @return 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);
+ }
+ return cb.writerIndex();
+ }
+
+ /**
+ * Builder class for PCEP label object.
+ */
+ public static class Builder implements PcepLabelObject.Builder {
+
+ private boolean bIsHeaderSet = false;
+ private boolean bIsOFlagSet = false;
+ private boolean bIsLabelSet = false;
+
+ private PcepObjectHeader labelObjHeader;
+ private boolean bOFlag;
+ private int label;
+
+ LinkedList<PcepValueType> llOptionalTlv = new LinkedList<PcepValueType>();
+
+ private boolean bIsPFlagSet = false;
+ private boolean bPFlag;
+
+ private boolean bIsIFlagSet = false;
+ private boolean bIFlag;
+
+ @Override
+ public PcepLabelObject build() throws PcepParseException {
+ PcepObjectHeader labelObjHeader = this.bIsHeaderSet ? this.labelObjHeader : DEFAULT_LABEL_OBJECT_HEADER;
+ boolean bOFlag = this.bIsOFlagSet ? this.bOFlag : DEFAULT_OFLAG;
+
+ if (!this.bIsLabelSet) {
+ throw new PcepParseException(" Label NOT Set while building PcepLabelObject.");
+ }
+ if (bIsPFlagSet) {
+ labelObjHeader.setPFlag(bPFlag);
+ }
+ if (bIsIFlagSet) {
+ labelObjHeader.setIFlag(bIFlag);
+ }
+ return new PcepLabelObjectVer1(labelObjHeader, bOFlag, this.label, this.llOptionalTlv);
+ }
+
+ @Override
+ public PcepObjectHeader getLabelObjHeader() {
+ return this.labelObjHeader;
+ }
+
+ @Override
+ public Builder setLabelObjHeader(PcepObjectHeader obj) {
+ this.labelObjHeader = obj;
+ this.bIsHeaderSet = true;
+ return this;
+ }
+
+ @Override
+ public boolean getOFlag() {
+ return this.bOFlag;
+ }
+
+ @Override
+ public Builder setOFlag(boolean value) {
+ this.bOFlag = value;
+ this.bIsOFlagSet = true;
+ return this;
+ }
+
+ @Override
+ public int getLabel() {
+ return this.label;
+ }
+
+ @Override
+ public Builder setLabel(int value) {
+ this.label = value;
+ this.bIsLabelSet = 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("OFlag", bOFlag).add("label", label)
+ .add("OptionalTlvList", llOptionalTlv).toString();
+ }
+}
diff --git a/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelUpdateMsgVer1.java b/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelUpdateMsgVer1.java
new file mode 100644
index 0000000..2b23424
--- /dev/null
+++ b/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelUpdateMsgVer1.java
@@ -0,0 +1,227 @@
+/*
+ * 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();
+ }
+}
diff --git a/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelUpdateVer1.java b/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelUpdateVer1.java
new file mode 100644
index 0000000..7c7b3de
--- /dev/null
+++ b/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelUpdateVer1.java
@@ -0,0 +1,361 @@
+/*
+ * 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.PcepFecObject;
+import org.onosproject.pcepio.protocol.PcepLabelObject;
+import org.onosproject.pcepio.protocol.PcepLabelUpdate;
+import org.onosproject.pcepio.protocol.PcepLspObject;
+import org.onosproject.pcepio.protocol.PcepSrpObject;
+import org.onosproject.pcepio.types.PcepLabelDownload;
+import org.onosproject.pcepio.types.PcepLabelMap;
+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 PCEP LABEL update .
+ * Reference :draft-zhao-pce-pcep-extension-for-pce-controller-01.
+ */
+public class PcepLabelUpdateVer1 implements PcepLabelUpdate {
+
+ /*
+ * <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(PcepLabelUpdateVer1.class);
+
+ //Either PceLabelDownload or PceLabelMap is mandatory.
+ //label Download
+ private PcepLabelDownload labelDownload;
+ private boolean isLabelDownloadSet;
+ //label Map
+ private PcepLabelMap labelMap;
+ private boolean isLabelMapSet;
+
+ /**
+ * Constructor to reset parameters.
+ */
+ public PcepLabelUpdateVer1() {
+ this.labelDownload = null;
+ this.isLabelDownloadSet = false;
+ this.labelMap = null;
+ this.isLabelMapSet = false;
+ }
+
+ /**
+ * Constructor to initialize PCEP label download.
+ *
+ * @param labelDownload PCEP label download
+ */
+ public PcepLabelUpdateVer1(PcepLabelDownload labelDownload) {
+ this.labelDownload = labelDownload;
+ this.isLabelDownloadSet = true;
+ this.labelMap = null;
+ this.isLabelMapSet = false;
+ }
+
+ /**
+ * Constructor to initialize PCEP label map.
+ *
+ * @param labelMap PCEP label map
+ */
+ public PcepLabelUpdateVer1(PcepLabelMap labelMap) {
+ this.labelDownload = null;
+ this.isLabelDownloadSet = false;
+ this.labelMap = labelMap;
+ this.isLabelMapSet = true;
+ }
+
+ /**
+ * builder class for PCEP label update.
+ */
+ static class Builder implements PcepLabelUpdate.Builder {
+
+ private PcepLabelDownload labelDownload;
+ private boolean isLabelDownloadSet;
+ private PcepLabelMap labelMap;
+ private boolean isLabelMapSet;
+
+ @Override
+ public PcepLabelUpdate build() throws PcepParseException {
+
+ if (isLabelDownloadSet) {
+ return new PcepLabelUpdateVer1(labelDownload);
+ }
+ if (isLabelMapSet) {
+ return new PcepLabelUpdateVer1(labelMap);
+ }
+ if (!isLabelDownloadSet && !isLabelMapSet) {
+ throw new PcepParseException(
+ "Label Download or Label Map is not set while building PcepLabelUpdate Message");
+ }
+ return new PcepLabelUpdateVer1();
+ }
+
+ @Override
+ public Builder setLabelDownload(PcepLabelDownload labelDownload) {
+ this.labelDownload = labelDownload;
+ this.isLabelDownloadSet = true;
+ return this;
+ }
+
+ @Override
+ public PcepLabelDownload getLabelDownload() {
+ return labelDownload;
+ }
+
+ @Override
+ public Builder setLabelMap(PcepLabelMap labelMap) {
+ this.labelMap = labelMap;
+ this.isLabelMapSet = true;
+ return this;
+ }
+
+ @Override
+ public PcepLabelMap getLabelMap() {
+ return labelMap;
+ }
+ }
+
+ /**
+ * Reads PcepLabels from the byte stream received from channel buffer.
+ *
+ * @param cb of type channel buffer.
+ * @return PcepLabelUpdate object.
+ * @throws PcepParseException when fails to read from channel buffer
+ */
+ public static PcepLabelUpdate read(ChannelBuffer cb) throws PcepParseException {
+
+ PcepLabelUpdateVer1 pceLabelUpdate = new PcepLabelUpdateVer1();
+
+ PcepSrpObject srpObject;
+ PcepObjectHeader tempObjHeader;
+
+ //read SRP mandatory Object
+ srpObject = PcepSrpObjectVer1.read(cb);
+
+ //checking next object
+ cb.markReaderIndex();
+
+ tempObjHeader = PcepObjectHeader.read(cb);
+ cb.resetReaderIndex();
+
+ if (tempObjHeader.getObjClass() == PcepLspObjectVer1.LSP_OBJ_CLASS) {
+
+ //now it is belong to <pce-label-download>
+ PcepLabelDownload labelDownload = new PcepLabelDownload();
+
+ //set SRP
+ labelDownload.setSrpObject(srpObject);
+
+ //read and set LSP
+ labelDownload.setLspObject(PcepLspObjectVer1.read(cb));
+
+ //<label-list>
+ LinkedList<PcepLabelObject> llLabelList = new LinkedList<PcepLabelObject>();
+ PcepLabelObject labelObject;
+
+ while (0 < cb.readableBytes()) {
+
+ cb.markReaderIndex();
+ tempObjHeader = PcepObjectHeader.read(cb);
+ cb.resetReaderIndex();
+
+ if (tempObjHeader.getObjClass() != PcepLabelObjectVer1.LABEL_OBJ_CLASS) {
+ break;
+ }
+ labelObject = PcepLabelObjectVer1.read(cb);
+ llLabelList.add(labelObject);
+ }
+ labelDownload.setLabelList(llLabelList);
+ pceLabelUpdate.setLabelDownload(labelDownload);
+ } else if (tempObjHeader.getObjClass() == PcepLabelObjectVer1.LABEL_OBJ_CLASS) {
+ //belong to <pce-label-map>
+ PcepLabelMap labelMap = new PcepLabelMap();
+
+ //set SRP Object
+ labelMap.setSrpObject(srpObject);
+
+ //read and set Label Object
+ labelMap.setLabelObject(PcepLabelObjectVer1.read(cb));
+
+ cb.markReaderIndex();
+ tempObjHeader = PcepObjectHeader.read(cb);
+ cb.resetReaderIndex();
+
+ PcepFecObject fecObject = null;
+ switch (tempObjHeader.getObjType()) {
+ case PcepFecObjectIPv4Ver1.FEC_OBJ_TYPE:
+ fecObject = PcepFecObjectIPv4Ver1.read(cb);
+ break;
+ case PcepFecObjectIPv6Ver1.FEC_OBJ_TYPE:
+ fecObject = PcepFecObjectIPv6Ver1.read(cb);
+ break;
+ case PcepFecObjectIPv4AdjacencyVer1.FEC_OBJ_TYPE:
+ fecObject = PcepFecObjectIPv4AdjacencyVer1.read(cb);
+ break;
+ case PcepFecObjectIPv6AdjacencyVer1.FEC_OBJ_TYPE:
+ fecObject = PcepFecObjectIPv6AdjacencyVer1.read(cb);
+ break;
+ case PcepFecObjectIPv4UnnumberedAdjacencyVer1.FEC_OBJ_TYPE:
+ fecObject = PcepFecObjectIPv4UnnumberedAdjacencyVer1.read(cb);
+ break;
+ default:
+ throw new PcepParseException("Unkown FEC object type " + tempObjHeader.getObjType());
+ }
+ labelMap.setFECObject(fecObject);
+ pceLabelUpdate.setLabelMap(labelMap);
+ } else {
+ throw new PcepParseException(
+ "Either <pce-label-download> or <pce-label-map> should be present. Received Class: "
+ + tempObjHeader.getObjClass());
+ }
+ return pceLabelUpdate;
+ }
+
+ @Override
+ public void write(ChannelBuffer cb) throws PcepParseException {
+
+ if ((labelDownload != null) && (labelMap != null)) {
+ throw new PcepParseException("Label Download and Label Map both can't be present.");
+ }
+
+ if ((labelDownload == null) && (labelMap == null)) {
+ throw new PcepParseException("Either Label Download or Label Map should be present.");
+ }
+
+ if (labelDownload != null) {
+
+ PcepLspObject lspObject;
+ PcepSrpObject srpObject;
+ PcepLabelObject labelObject;
+ LinkedList<PcepLabelObject> llLabelList;
+
+ srpObject = labelDownload.getSrpObject();
+ if (srpObject == null) {
+ throw new PcepParseException("SRP Object is mandatory object for Label Download.");
+ } else {
+ srpObject.write(cb);
+ }
+
+ lspObject = labelDownload.getLspObject();
+ if (lspObject == null) {
+ throw new PcepParseException("LSP Object is mandatory object for Label Download.");
+ } else {
+ lspObject.write(cb);
+ }
+
+ llLabelList = labelDownload.getLabelList();
+ if (llLabelList == null) {
+ throw new PcepParseException("Label list is mandatory object for Label Download.");
+ } else {
+ ListIterator<PcepLabelObject> listIterator = llLabelList.listIterator();
+ while (listIterator.hasNext()) {
+ labelObject = listIterator.next();
+ labelObject.write(cb);
+ }
+ }
+ }
+
+ if (labelMap != null) {
+
+ PcepSrpObject srpObject;
+ PcepLabelObject labelObject;
+ PcepFecObject fecObject;
+
+ srpObject = labelMap.getSrpObject();
+ if (srpObject == null) {
+ throw new PcepParseException("SRP Object is mandatory object for Label map.");
+ } else {
+ srpObject.write(cb);
+ }
+ labelObject = labelMap.getLabelObject();
+ if (labelObject == null) {
+ throw new PcepParseException("label Object is mandatory object for Label map.");
+ } else {
+ labelObject.write(cb);
+ }
+ fecObject = labelMap.getFECObject();
+ if (fecObject == null) {
+ throw new PcepParseException("fec Object is mandatory object for Label map.");
+ } else {
+ fecObject.write(cb);
+ }
+ }
+ }
+
+ @Override
+ public void setLabelDownload(PcepLabelDownload labelDownload) {
+ if (this.isLabelMapSet) {
+ return;
+ }
+ this.labelDownload = labelDownload;
+ this.isLabelDownloadSet = true;
+ }
+
+ @Override
+ public PcepLabelDownload getLabelDownload() {
+ return this.labelDownload;
+ }
+
+ @Override
+ public void setLabelMap(PcepLabelMap labelMap) {
+ if (this.isLabelDownloadSet) {
+ return;
+ }
+ this.labelMap = labelMap;
+ this.isLabelMapSet = true;
+ }
+
+ @Override
+ public PcepLabelMap getLabelMap() {
+ return this.labelMap;
+ }
+
+ @Override
+ public String toString() {
+ ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass());
+
+ if (labelDownload instanceof PcepLabelDownload) {
+ toStrHelper.add("LabelDownload", labelDownload);
+ }
+ if (labelMap instanceof PcepLabelMap) {
+ toStrHelper.add("LabelMap", labelMap);
+ }
+ return toStrHelper.toString();
+ }
+}
diff --git a/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/NexthopIPv4addressTlv.java b/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/NexthopIPv4addressTlv.java
new file mode 100644
index 0000000..2306dcc
--- /dev/null
+++ b/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/NexthopIPv4addressTlv.java
@@ -0,0 +1,143 @@
+/*
+ * 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();
+ }
+}
diff --git a/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/NexthopIPv6addressTlv.java b/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/NexthopIPv6addressTlv.java
new file mode 100644
index 0000000..9b39dd5
--- /dev/null
+++ b/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/NexthopIPv6addressTlv.java
@@ -0,0 +1,190 @@
+/*
+ * 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();
+ }
+}
diff --git a/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/NexthopUnnumberedIPv4IDTlv.java b/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/NexthopUnnumberedIPv4IDTlv.java
new file mode 100644
index 0000000..c8fae0a
--- /dev/null
+++ b/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/NexthopUnnumberedIPv4IDTlv.java
@@ -0,0 +1,159 @@
+/*
+ * 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();
+ }
+}