diff options
Diffstat (limited to 'framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1')
43 files changed, 0 insertions, 13207 deletions
diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcInitiatedLspRequestVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcInitiatedLspRequestVer1.java deleted file mode 100644 index d61f7319..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcInitiatedLspRequestVer1.java +++ /dev/null @@ -1,291 +0,0 @@ -/* - * 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.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcInitiatedLspRequest; -import org.onosproject.pcepio.protocol.PcepAttribute; -import org.onosproject.pcepio.protocol.PcepEndPointsObject; -import org.onosproject.pcepio.protocol.PcepEroObject; -import org.onosproject.pcepio.protocol.PcepLspObject; -import org.onosproject.pcepio.protocol.PcepSrpObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PcInitiatedLspRequest for PCEP Initiate message. - * Reference : PCE initiated tunnel setup draft-ietf-pce-pce-initiated-lsp-03. - */ -public class PcInitiatedLspRequestVer1 implements PcInitiatedLspRequest { - - /* - * <PCE-initiated-lsp-request> ::= (<PCE-initiated-lsp-instantiation>|<PCE-initiated-lsp-deletion>) - <PCE-initiated-lsp-instantiation> ::= <SRP> - <LSP> - <END-POINTS> - <ERO> - [<attribute-list>] - <PCE-initiated-lsp-deletion> ::= <SRP> - <LSP> - */ - - protected static final Logger log = LoggerFactory.getLogger(PcInitiatedLspRequestVer1.class); - - //PCEP SRP Object - private PcepSrpObject srpObject; - //PCEP LSP Object - private PcepLspObject lspObject; - //PCEP End Point Object - private PcepEndPointsObject endPointsObject; - //PCEP ERO Object - private PcepEroObject eroObject; - //PCEP Attribute list - private PcepAttribute pcepAttribute; - - /** - * Default constructor. - */ - public PcInitiatedLspRequestVer1() { - srpObject = null; - lspObject = null; - endPointsObject = null; - eroObject = null; - pcepAttribute = null; - - } - - /** - * Constructor to initialize all parameters of PC initiated lsp request. - * - * @param srpObject PCEP srp Object - * @param lspObject PCEP lsp object - * @param endPointsObject PCPE endpoints object - * @param eroObject PCEP ero object - * @param pcepAttribute PCEP attribute - */ - public PcInitiatedLspRequestVer1(PcepSrpObject srpObject, PcepLspObject lspObject, - PcepEndPointsObject endPointsObject, PcepEroObject eroObject, PcepAttribute pcepAttribute) { - this.srpObject = srpObject; - this.lspObject = lspObject; - this.endPointsObject = endPointsObject; - this.eroObject = eroObject; - this.pcepAttribute = pcepAttribute; - - } - - @Override - public PcepSrpObject getSrpObject() { - return srpObject; - } - - @Override - public PcepLspObject getLspObject() { - return lspObject; - } - - @Override - public PcepEndPointsObject getEndPointsObject() { - return endPointsObject; - } - - @Override - public PcepEroObject getEroObject() { - return eroObject; - } - - @Override - public PcepAttribute getPcepAttribute() { - return pcepAttribute; - } - - @Override - public void setSrpObject(PcepSrpObject srpobj) { - this.srpObject = srpobj; - - } - - @Override - public void setLspObject(PcepLspObject lspObject) { - this.lspObject = lspObject; - } - - @Override - public void setEndPointsObject(PcepEndPointsObject endPointsObject) { - this.endPointsObject = endPointsObject; - } - - @Override - public void setEroObject(PcepEroObject eroObject) { - this.eroObject = eroObject; - } - - @Override - public void setPcepAttribute(PcepAttribute pcepAttribute) { - this.pcepAttribute = pcepAttribute; - } - - /** - * Builder class for PC initiated lsp reuqest. - */ - public static class Builder implements PcInitiatedLspRequest.Builder { - - private boolean bIsSRPObjectSet = false; - private boolean bIsLSPObjectSet = false; - private boolean bIsEndPointsObjectSet = false; - private boolean bIsEROObjectSet = false; - private boolean bIsPcepAttributeSet = false; - private boolean bIsbRFlagSet = false; - - //PCEP SRP Object - private PcepSrpObject srpObject; - //PCEP LSP Object - private PcepLspObject lspObject; - //PCEP End Point Object - private PcepEndPointsObject endPointsObject; - //PCEP ERO Object - private PcepEroObject eroObject; - //PCEP Attribute list - private PcepAttribute pcepAttribute; - - @Override - public PcInitiatedLspRequest build() throws PcepParseException { - - //PCEP SRP Object - PcepSrpObject srpObject = null; - //PCEP LSP Object - PcepLspObject lspObject = null; - //PCEP End Point Object - PcepEndPointsObject endPointsObject = null; - //PCEP ERO Object - PcepEroObject eroObject = null; - //PCEP Attribute list - PcepAttribute pcepAttribute = null; - boolean bRFlag = false; - - if (!this.bIsSRPObjectSet) { - throw new PcepParseException("Srp object NOT Set while building PcInitiatedLspRequest"); - } else { - srpObject = this.srpObject; - bRFlag = srpObject.getRFlag(); - } - - if (bRFlag) { - this.bIsbRFlagSet = true; - } else { - this.bIsbRFlagSet = false; - } - - if (!this.bIsLSPObjectSet) { - throw new PcepParseException("LSP Object NOT Set while building PcInitiatedLspRequest"); - } else { - lspObject = this.lspObject; - } - if (!this.bIsbRFlagSet) { - - if (!this.bIsEndPointsObjectSet) { - throw new PcepParseException("EndPoints Object NOT Set while building PcInitiatedLspRequest"); - } else { - endPointsObject = this.endPointsObject; - } - if (!this.bIsEROObjectSet) { - throw new PcepParseException("ERO Object NOT Set while building PcInitiatedLspRequest"); - } else { - eroObject = this.eroObject; - } - if (bIsPcepAttributeSet) { - pcepAttribute = this.pcepAttribute; - } - } - return new PcInitiatedLspRequestVer1(srpObject, lspObject, endPointsObject, eroObject, pcepAttribute); - } - - @Override - public PcepSrpObject getSrpObject() { - return this.srpObject; - } - - @Override - public PcepLspObject getLspObject() { - return this.lspObject; - } - - @Override - public PcepEndPointsObject getEndPointsObject() { - return this.endPointsObject; - } - - @Override - public PcepEroObject getEroObject() { - return this.eroObject; - } - - @Override - public PcepAttribute getPcepAttribute() { - return this.pcepAttribute; - } - - @Override - public Builder setSrpObject(PcepSrpObject srpobj) { - this.srpObject = srpobj; - this.bIsSRPObjectSet = true; - return this; - - } - - @Override - public Builder setLspObject(PcepLspObject lspObject) { - this.lspObject = lspObject; - this.bIsLSPObjectSet = true; - return this; - } - - @Override - public Builder setEndPointsObject(PcepEndPointsObject endPointsObject) { - this.endPointsObject = endPointsObject; - this.bIsEndPointsObjectSet = true; - return this; - } - - @Override - public Builder setEroObject(PcepEroObject eroObject) { - this.eroObject = eroObject; - this.bIsEROObjectSet = true; - return this; - } - - @Override - public Builder setPcepAttribute(PcepAttribute pcepAttribute) { - this.pcepAttribute = pcepAttribute; - this.bIsPcepAttributeSet = true; - return this; - } - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .omitNullValues() - .add("SrpObject", srpObject) - .add("LspObject", lspObject) - .add("EndPointObject", endPointsObject) - .add("EroObject", eroObject) - .add("PcepAttribute", pcepAttribute) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepAttributeVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepAttributeVer1.java deleted file mode 100644 index 65a844c2..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepAttributeVer1.java +++ /dev/null @@ -1,431 +0,0 @@ -/* - * 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.PcepAttribute; -import org.onosproject.pcepio.protocol.PcepBandwidthObject; -import org.onosproject.pcepio.protocol.PcepIroObject; -import org.onosproject.pcepio.protocol.PcepLspaObject; -import org.onosproject.pcepio.protocol.PcepMetricObject; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP Attribute List. - */ -public class PcepAttributeVer1 implements PcepAttribute { - - /* Reference : RFC5440 - * where: - * <attribute-list> ::=[<LSPA>] - * [<BANDWIDTH>] - * [<metric-list>] - * [<IRO>] - * - * <metric-list> ::=<METRIC>[<metric-list>] - */ - protected static final Logger log = LoggerFactory.getLogger(PcepAttributeVer1.class); - - public static final int OBJECT_HEADER_LENGTH = 4; - - //PCEP LSPA Object - private PcepLspaObject lspaObject; - private boolean isLspaObjectSet; - - //PCEP Bandwidth Object - private PcepBandwidthObject bandwidthObject; - private boolean isBandwidthObjectSet; - - //PCEP Metric list - private LinkedList<PcepMetricObject> llMetricList; - private boolean isMetricListSet; - - //PCEP IRO object - private PcepIroObject iroObject; - private boolean isIroObjectSet; - - /** - * Default constructor to initialize member variables. - */ - public PcepAttributeVer1() { - - lspaObject = null; - bandwidthObject = null; - llMetricList = null; - iroObject = null; - this.isLspaObjectSet = false; - this.isBandwidthObjectSet = false; - this.isMetricListSet = false; - this.isIroObjectSet = false; - } - - /** - * Constructor to initialize all parameters for PCEP attribute. - * - * @param lspaObject PCEP lspa Object. - * @param bandwidthObject PCEP bandwidth object. - * @param llMetricList list of PCEP metric objects. - * @param iroObject PCEP iro object. - */ - public PcepAttributeVer1(PcepLspaObject lspaObject, PcepBandwidthObject bandwidthObject, - LinkedList<PcepMetricObject> llMetricList, PcepIroObject iroObject) { - - this.lspaObject = lspaObject; - this.bandwidthObject = bandwidthObject; - this.llMetricList = llMetricList; - this.iroObject = iroObject; - if (lspaObject == null) { - this.isLspaObjectSet = false; - } else { - this.isLspaObjectSet = true; - } - if (bandwidthObject == null) { - this.isBandwidthObjectSet = false; - } else { - this.isBandwidthObjectSet = true; - } - if (llMetricList == null) { - this.isMetricListSet = false; - } else { - this.isMetricListSet = true; - } - if (iroObject == null) { - this.isIroObjectSet = false; - } else { - this.isIroObjectSet = true; - } - } - - /** - * constructor to initialize bandwidthObject. - * - * @param bandwidthObject bandwidth object - */ - public PcepAttributeVer1(PcepBandwidthObject bandwidthObject) { - this.isLspaObjectSet = false; - - this.bandwidthObject = bandwidthObject; - this.isBandwidthObjectSet = true; - - this.isMetricListSet = false; - - this.isIroObjectSet = false; - } - - /** - * Parse list for MeticObject. - * - * @param cb of type channel buffer - * @return true if parsing metric list is success - * @throws PcepParseException when a non metric object is received - */ - public boolean parseMetricList(ChannelBuffer cb) throws PcepParseException { - - if (llMetricList == null) { - llMetricList = new LinkedList<>(); - } - - PcepMetricObject metriclist; - - //caller should verify for metric object - byte yObjClass = PcepMetricObjectVer1.METRIC_OBJ_CLASS; - byte yObjType = PcepMetricObjectVer1.METRIC_OBJ_TYPE; - - while ((yObjClass == PcepMetricObjectVer1.METRIC_OBJ_CLASS) - && (yObjType == PcepMetricObjectVer1.METRIC_OBJ_TYPE)) { - - metriclist = PcepMetricObjectVer1.read(cb); - llMetricList.add(metriclist); - yObjClass = 0; - yObjType = 0; - - if (cb.readableBytes() > OBJECT_HEADER_LENGTH) { - cb.markReaderIndex(); - PcepObjectHeader tempObjHeader = PcepObjectHeader.read(cb); - cb.resetReaderIndex(); - yObjClass = tempObjHeader.getObjClass(); - yObjType = tempObjHeader.getObjType(); - } - } - return true; - } - - /** - * Reads lspa , bandwidth , Metriclist and Iro objects and sets the objects. - * - * @param cb of type channel buffer - * @return instance of Pcep Attribute - * @throws PcepParseException while parsing Pcep Attributes from channel buffer - */ - - public static PcepAttribute read(ChannelBuffer cb) throws PcepParseException { - if (cb.readableBytes() < OBJECT_HEADER_LENGTH) { - return null; - } - //check whether any pcep attribute is present - cb.markReaderIndex(); - PcepObjectHeader tempObjHeader = PcepObjectHeader.read(cb); - cb.resetReaderIndex(); - byte yObjClass = tempObjHeader.getObjClass(); - - if (PcepLspaObjectVer1.LSPA_OBJ_CLASS != yObjClass && PcepBandwidthObjectVer1.BANDWIDTH_OBJ_CLASS != yObjClass - && PcepMetricObjectVer1.METRIC_OBJ_CLASS != yObjClass && PcepIroObjectVer1.IRO_OBJ_CLASS != yObjClass) { - //No PCEP attribute is present - return null; - } - - PcepAttributeVer1 pcepAttribute = new PcepAttributeVer1(); - - //If LSPA present then store it.LSPA is optional - if (yObjClass == PcepLspaObjectVer1.LSPA_OBJ_CLASS) { - pcepAttribute.setLspaObject(PcepLspaObjectVer1.read(cb)); - yObjClass = checkNextObject(cb); - } - - //If BANDWIDTH present then store it.BANDWIDTH is optional - if (yObjClass == PcepBandwidthObjectVer1.BANDWIDTH_OBJ_CLASS) { - pcepAttribute.setBandwidthObject(PcepBandwidthObjectVer1.read(cb)); - yObjClass = checkNextObject(cb); - } - - //If Metric list present then store it.MetricList is optional - if (yObjClass == PcepMetricObjectVer1.METRIC_OBJ_CLASS) { - pcepAttribute.parseMetricList(cb); - yObjClass = checkNextObject(cb); - } - - //If IRO present then store it.IRO is optional - if (yObjClass == PcepIroObjectVer1.IRO_OBJ_CLASS) { - pcepAttribute.setIroObject(PcepIroObjectVer1.read(cb)); - } - - PcepLspaObject lspaObject = pcepAttribute.getLspaObject(); - PcepBandwidthObject bandwidthObject = pcepAttribute.getBandwidthObject(); - LinkedList<PcepMetricObject> metriclist = pcepAttribute.llMetricList; - PcepIroObject iroObject = pcepAttribute.getIroObject(); - - return new PcepAttributeVer1(lspaObject, bandwidthObject, metriclist, iroObject); - } - - /** - * Checks whether there is a more object or not. - * - * @param cb of type channel buffer - * @return instance of object header - */ - private static byte checkNextObject(ChannelBuffer cb) { - if (cb.readableBytes() < OBJECT_HEADER_LENGTH) { - return 0; - } - cb.markReaderIndex(); - PcepObjectHeader tempObjHeader = PcepObjectHeader.read(cb); - cb.resetReaderIndex(); - return tempObjHeader.getObjClass(); - } - - @Override - public int write(ChannelBuffer cb) throws PcepParseException { - int iLenStartIndex = cb.writerIndex(); - //PCEP LSPA object is optional - if (this.isLspaObjectSet) { - this.lspaObject.write(cb); - } - - //PCEP BANDWIDTH object is optional - if (this.isBandwidthObjectSet) { - this.bandwidthObject.write(cb); - } - - //PCEP Metric list is optional - if (this.isMetricListSet) { - ListIterator<PcepMetricObject> listIterator = this.llMetricList.listIterator(); - while (listIterator.hasNext()) { - listIterator.next().write(cb); - } - } - - //PCEP IRO object is optional - if (this.isIroObjectSet) { - this.iroObject.write(cb); - } - return cb.writerIndex() - iLenStartIndex; - } - - @Override - public PcepLspaObject getLspaObject() { - return lspaObject; - } - - @Override - public PcepBandwidthObject getBandwidthObject() { - return bandwidthObject; - } - - @Override - public LinkedList<PcepMetricObject> getMetricObjectList() { - return llMetricList; - } - - @Override - public PcepIroObject getIroObject() { - return iroObject; - } - - @Override - public void setBandwidthObject(PcepBandwidthObject bandwidthObject) { - this.isBandwidthObjectSet = true; - this.bandwidthObject = bandwidthObject; - } - - @Override - public void setMetricObjectList(LinkedList<PcepMetricObject> llMetricList) { - this.isMetricListSet = true; - this.llMetricList = llMetricList; - - } - - @Override - public void setLspaObject(PcepLspaObject lspaObject) { - this.isLspaObjectSet = true; - this.lspaObject = lspaObject; - } - - @Override - public void setIroObject(PcepIroObject iroObject) { - this.isIroObjectSet = true; - this.iroObject = iroObject; - } - - /** - * Builder class for PCEP attributes. - */ - public static class Builder implements PcepAttribute.Builder { - - //PCEP LSPA Object - private PcepLspaObject lspaObject; - private boolean isLspaObjectSet; - - //PCEP BANDWIDTH Object - private PcepBandwidthObject bandwidthObject; - private boolean isBandwidthObjectSet; - - //PCEP Metric list - private LinkedList<PcepMetricObject> llMetricList; - private boolean isMetricListSet; - - //PCEP IRO object - private PcepIroObject iroObject; - private boolean isIroObjectSet; - - @Override - public PcepAttribute build() { - - //PCEP LSPA Object - PcepLspaObject lspaObject = null; - - //PCEP BANDWIDTH Object - PcepBandwidthObject bandwidthObject = null; - - //PCEP Metric list - LinkedList<PcepMetricObject> llMetricList = null; - - //PCEP IRO object - PcepIroObject iroObject = null; - - if (this.isLspaObjectSet) { - lspaObject = this.lspaObject; - } - if (this.isBandwidthObjectSet) { - bandwidthObject = this.bandwidthObject; - } - if (this.isMetricListSet) { - llMetricList = this.llMetricList; - } - if (this.isIroObjectSet) { - iroObject = this.iroObject; - } - return new PcepAttributeVer1(lspaObject, bandwidthObject, llMetricList, iroObject); - } - - @Override - public PcepLspaObject getLspaObject() { - return this.lspaObject; - } - - @Override - public PcepBandwidthObject getBandwidthObject() { - return this.bandwidthObject; - } - - @Override - public LinkedList<PcepMetricObject> getMetricObjectList() { - return this.llMetricList; - } - - @Override - public PcepIroObject getIroObject() { - return this.iroObject; - } - - @Override - public Builder setBandwidthObject(PcepBandwidthObject bandwidthObject) { - this.isBandwidthObjectSet = true; - this.bandwidthObject = bandwidthObject; - return this; - } - - @Override - public Builder setMetricObjectList(LinkedList<PcepMetricObject> llMetricList) { - this.isMetricListSet = true; - this.llMetricList = llMetricList; - return this; - } - - @Override - public Builder setLspaObject(PcepLspaObject lspaObject) { - this.isLspaObjectSet = true; - this.lspaObject = lspaObject; - return this; - } - - @Override - public Builder setIroObject(PcepIroObject iroObject) { - this.isIroObjectSet = true; - this.iroObject = iroObject; - return this; - } - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .omitNullValues() - .add("lspaObject", lspaObject) - .add("bandwidthObject", bandwidthObject) - .add("MetricObjectList", llMetricList) - .add("IroObject", iroObject) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepBandwidthObjectVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepBandwidthObjectVer1.java deleted file mode 100644 index 1c78d5b4..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepBandwidthObjectVer1.java +++ /dev/null @@ -1,233 +0,0 @@ -/* - * 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.PcepBandwidthObject; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PcepBandwidthObject. - */ -public class PcepBandwidthObjectVer1 implements PcepBandwidthObject { - - /* - * RFC : 5440 , section : 7.7. - 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 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Bandwidth | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - The BANDWIDTH Object format - */ - - protected static final Logger log = LoggerFactory.getLogger(PcepBandwidthObjectVer1.class); - /* - * Requested bandwidth: BANDWIDTH Object-Type is 1. - Bandwidth of an existing TE LSP for which a re-optimization is - requested. BANDWIDTH Object-Type is 2. - */ - //Right now handling type 1 - public static final byte BANDWIDTH_OBJ_TYPE = 1; - public static final byte BANDWIDTH_OBJ_CLASS = 5; - public static final byte BANDWIDTH_OBJECT_VERSION = 1; - public static final short BANDWIDTH_OBJ_MINIMUM_LENGTH = 8; - - static final PcepObjectHeader DEFAULT_BANDWIDTH_OBJECT_HEADER = new PcepObjectHeader(BANDWIDTH_OBJ_CLASS, - BANDWIDTH_OBJ_TYPE, PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, - BANDWIDTH_OBJ_MINIMUM_LENGTH); - - private PcepObjectHeader bandwidthObjHeader; - private int iBandwidth; - - /** - * Constructor to bandwidth object header and bandwidth. - * - * @param bandwidthObjHeader bandwidth object header - * @param iBandwidth bandwidth value - */ - public PcepBandwidthObjectVer1(PcepObjectHeader bandwidthObjHeader, int iBandwidth) { - this.bandwidthObjHeader = bandwidthObjHeader; - this.iBandwidth = iBandwidth; - } - - /** - * Constructor to initialize bandwidth. - * - * @param iBandwidth bandwidth value - */ - public PcepBandwidthObjectVer1(int iBandwidth) { - this.bandwidthObjHeader = DEFAULT_BANDWIDTH_OBJECT_HEADER; - this.iBandwidth = iBandwidth; - } - - /** - * Returns Object Header. - * - * @return bandwidthObjHeader - */ - public PcepObjectHeader getBandwidthObjHeader() { - return this.bandwidthObjHeader; - } - - /** - * Sets Object Header. - * - * @param obj bandwidth object header - */ - public void setBandwidthObjHeader(PcepObjectHeader obj) { - this.bandwidthObjHeader = obj; - } - - @Override - public int getBandwidth() { - return this.iBandwidth; - } - - @Override - public void setBandwidth(int iBandwidth) { - this.iBandwidth = iBandwidth; - } - - /** - * Reads from channel buffer and returns object of PcepBandwidthObject. - * - * @param cb channel buffer to parse - * @return object of PcepBandwidthObject - * @throws PcepParseException while parsing channel buffer - */ - public static PcepBandwidthObject read(ChannelBuffer cb) throws PcepParseException { - - PcepObjectHeader bandwidthObjHeader; - int iBandwidth; - - bandwidthObjHeader = PcepObjectHeader.read(cb); - iBandwidth = cb.readInt(); - - return new PcepBandwidthObjectVer1(bandwidthObjHeader, iBandwidth); - } - - @Override - public int write(ChannelBuffer cb) throws PcepParseException { - - //write Object header - int objStartIndex = cb.writerIndex(); - int objLenIndex = bandwidthObjHeader.write(cb); - - if (objLenIndex <= 0) { - throw new PcepParseException("Failed to write bandwidth object header. Index " + objLenIndex); - } - - cb.writeInt(iBandwidth); - short hLength = (short) (cb.writerIndex() - objStartIndex); - cb.setShort(objLenIndex, hLength); - //will be helpful during print(). - bandwidthObjHeader.setObjLen(hLength); - - return cb.writerIndex() - objStartIndex; - } - - /** - * builder class for PCEP bandwidth object. - */ - public static class Builder implements PcepBandwidthObject.Builder { - - private PcepObjectHeader bandwidthObjHeader; - private boolean bIsHeaderSet = false; - - private int iBandwidth; - private boolean bIsBandwidthSet = false; - - private boolean bPFlag; - private boolean bIsPFlagSet = false; - - private boolean bIFlag; - private boolean bIsIFlagSet = false; - - @Override - public PcepBandwidthObject build() throws PcepParseException { - - PcepObjectHeader bandwidthObjHeader = this.bIsHeaderSet ? this.bandwidthObjHeader - : DEFAULT_BANDWIDTH_OBJECT_HEADER; - - if (bIsPFlagSet) { - bandwidthObjHeader.setPFlag(bPFlag); - } - - if (bIsIFlagSet) { - bandwidthObjHeader.setIFlag(bIFlag); - } - - if (!this.bIsBandwidthSet) { - throw new PcepParseException("bandwidth not Set while building Bandwidth Object."); - } - - return new PcepBandwidthObjectVer1(bandwidthObjHeader, iBandwidth); - } - - @Override - public int getBandwidth() { - return this.iBandwidth; - } - - @Override - public PcepObjectHeader getBandwidthObjHeader() { - return this.bandwidthObjHeader; - } - - @Override - public Builder setBandwidthObjHeader(PcepObjectHeader obj) { - this.bandwidthObjHeader = obj; - return this; - } - - @Override - public Builder setBandwidth(int iBandwidth) { - this.iBandwidth = iBandwidth; - this.bIsBandwidthSet = true; - 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("BandwidthObjectHeader", bandwidthObjHeader) - .add("Bandwidth", iBandwidth).toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepCloseMsgVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepCloseMsgVer1.java deleted file mode 100644 index bcc679d3..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepCloseMsgVer1.java +++ /dev/null @@ -1,351 +0,0 @@ -/* - * 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.PcepCloseMsg; -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.onosproject.pcepio.types.PcepObjectHeader; -import org.onosproject.pcepio.types.PcepValueType; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP Close Message. - */ -class PcepCloseMsgVer1 implements PcepCloseMsg { - - /* - * RFC : 5440 , section : 6.8 - * <Close Message> ::= <Common Header> <CLOSE> - * - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Ver | Flags | Message-Type | Message-Length | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Object-Class | OT |Res|P|I| Object Length (bytes) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Reserved | Flags | Reason | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | | - // Optional TLVs // - | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - - protected static final Logger log = LoggerFactory.getLogger(PcepCloseMsgVer1.class); - - // Pcep version: 1 - public static final byte PACKET_VERSION = 1; - public static final int PACKET_MINIMUM_LENGTH = 12; - public static final PcepType MSG_TYPE = PcepType.CLOSE; - public static final byte CLOSE_OBJ_TYPE = 1; - public static final byte CLOSE_OBJ_CLASS = 15; - public static final byte CLOSE_OBJECT_VERSION = 1; - public static final byte DEFAULT_REASON = 1; // Default reason to close - public static final short CLOSE_OBJ_MINIMUM_LENGTH = 8; - public static final int SHIFT_FLAG = 5; - static final PcepObjectHeader DEFAULT_CLOSE_HEADER = new PcepObjectHeader(CLOSE_OBJ_CLASS, CLOSE_OBJ_TYPE, - PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, CLOSE_OBJ_MINIMUM_LENGTH); - - private final PcepObjectHeader closeObjHeader; - private byte yReason; - private LinkedList<PcepValueType> llOptionalTlv; - - public static final PcepCloseMsgVer1.Reader READER = new Reader(); - - /** - * Reader class for reading close message for channel buffer. - */ - static class Reader implements PcepMessageReader<PcepCloseMsg> { - PcepObjectHeader closeObjHeader; - byte yReason; - // Optional TLV - private LinkedList<PcepValueType> llOptionalTlv; - - @Override - public PcepCloseMsg readFrom(ChannelBuffer cb) throws PcepParseException { - - if (cb.readableBytes() < PACKET_MINIMUM_LENGTH) { - throw new PcepParseException("Packet size is less than the minimum length."); - } - // fixed value property version == 1 - byte version = cb.readByte(); - version = (byte) (version >> SHIFT_FLAG); - if (version != PACKET_VERSION) { - throw new PcepParseException("Wrong version. Expected=PcepVersion.PCEP_1(1), got=" + version); - } - // fixed value property type == 7 - byte type = cb.readByte(); - if (type != MSG_TYPE.getType()) { - throw new PcepParseException("Wrong type. Expected=PcepType.CLOSE(7), got=" + type); - } - short length = cb.readShort(); - if (length < PACKET_MINIMUM_LENGTH) { - throw new PcepParseException("Wrong length. Expected to be >= " + PACKET_MINIMUM_LENGTH + ", was: " - + length); - } - closeObjHeader = PcepObjectHeader.read(cb); - // Reserved - cb.readShort(); - // Flags - cb.readByte(); - // Reason - yReason = cb.readByte(); - // parse optional TLV - llOptionalTlv = parseOptionalTlv(cb); - return new PcepCloseMsgVer1(closeObjHeader, yReason, llOptionalTlv); - } - } - - /** - * Parse the list of Optional Tlvs. - * - * @param cb channel buffer - * @return list of Optional Tlvs - * @throws PcepParseException when fails to parse optional tlvs - */ - public static LinkedList<PcepValueType> parseOptionalTlv(ChannelBuffer cb) throws PcepParseException { - - LinkedList<PcepValueType> llOptionalTlv = new LinkedList<>(); - /* - rfc 5440: - Optional TLVs may be included within the CLOSE object body. The - specification of such TLVs is outside the scope of this document. - */ - return llOptionalTlv; - } - - /** - * constructor to initialize PCEP close Message with all the parameters. - * - * @param closeObjHeader object header for close message - * @param yReason reason for closing the channel - * @param llOptionalTlv list of optional tlvs - */ - PcepCloseMsgVer1(PcepObjectHeader closeObjHeader, byte yReason, LinkedList<PcepValueType> llOptionalTlv) { - - this.closeObjHeader = closeObjHeader; - this.yReason = yReason; - this.llOptionalTlv = llOptionalTlv; - } - - /** - * Builder class for PCEP close message. - */ - static class Builder implements PcepCloseMsg.Builder { - - // PCEP Close message fields - private boolean bIsHeaderSet = false; - private PcepObjectHeader closeObjHeader; - private boolean bIsReasonSet = false; - private byte yReason; - private LinkedList<PcepValueType> llOptionalTlv = new LinkedList<>(); - - private boolean bIsPFlagSet = false; - private boolean bPFlag; - - private boolean bIsIFlagSet = false; - private boolean bIFlag; - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public PcepType getType() { - return PcepType.CLOSE; - } - - @Override - public PcepCloseMsg build() { - - PcepObjectHeader closeObjHeader = this.bIsHeaderSet ? this.closeObjHeader : DEFAULT_CLOSE_HEADER; - byte yReason = this.bIsReasonSet ? this.yReason : DEFAULT_REASON; - - if (bIsPFlagSet) { - closeObjHeader.setPFlag(bPFlag); - } - - if (bIsIFlagSet) { - closeObjHeader.setIFlag(bIFlag); - } - return new PcepCloseMsgVer1(closeObjHeader, yReason, this.llOptionalTlv); - } - - @Override - public PcepObjectHeader getCloseObjHeader() { - return this.closeObjHeader; - } - - @Override - public Builder setCloseObjHeader(PcepObjectHeader obj) { - this.closeObjHeader = obj; - this.bIsHeaderSet = true; - return this; - } - - @Override - public byte getReason() { - return this.yReason; - } - - @Override - public Builder setReason(byte value) { - this.yReason = value; - this.bIsReasonSet = true; - return this; - } - - @Override - public Builder setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) { - this.llOptionalTlv = llOptionalTlv; - return this; - } - - @Override - public LinkedList<PcepValueType> getOptionalTlv() { - return this.llOptionalTlv; - } - - @Override - public Builder setPFlag(boolean value) { - this.bPFlag = value; - this.bIsPFlagSet = true; - return this; - } - - @Override - public Builder setIFlag(boolean value) { - this.bIFlag = value; - this.bIsIFlagSet = true; - return this; - } - } - - @Override - public void writeTo(ChannelBuffer cb) throws PcepParseException { - WRITER.write(cb, this); - } - - static final Writer WRITER = new Writer(); - - /** - * Writer class for writing close message to channel buffer. - */ - static class Writer implements PcepMessageWriter<PcepCloseMsgVer1> { - - @Override - public void write(ChannelBuffer cb, PcepCloseMsgVer1 message) throws PcepParseException { - int startIndex = cb.writerIndex(); - // first 3 bits set to version - cb.writeByte((byte) (PACKET_VERSION << SHIFT_FLAG)); - // message type - cb.writeByte(MSG_TYPE.getType()); - // length is length of variable message, will be updated at the end - // Store the position of message - // length in buffer - int msgLenIndex = cb.writerIndex(); - cb.writeShort((short) 0); - int objStartIndex = cb.writerIndex(); - int objLenIndex = message.closeObjHeader.write(cb); - if (objLenIndex <= 0) { - throw new PcepParseException("Failed to write Close object header."); - } - // first 3 bits set to version - cb.writeShort(0); // Reserved - cb.writeByte(0); // Flags - cb.writeByte(message.yReason); - // Pack optional TLV - packOptionalTlv(cb, message); - int length = cb.writerIndex() - objStartIndex; - cb.setShort(objLenIndex, (short) length); - // will be helpful during print(). - message.closeObjHeader.setObjLen((short) length); - // As per RFC the length of object should be - // multiples of 4 - int pad = length % 4; - if (pad != 0) { - pad = 4 - pad; - for (int i = 0; i < pad; i++) { - cb.writeByte((byte) 0); - } - length = length + pad; - } - // update message length field - length = cb.writerIndex() - startIndex; - cb.setShort(msgLenIndex, (short) length); - } - - public void packOptionalTlv(ChannelBuffer cb, PcepCloseMsgVer1 message) { - - LinkedList<PcepValueType> llOptionalTlv = message.llOptionalTlv; - ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator(); - while (listIterator.hasNext()) { - listIterator.next().write(cb); - } - } - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public PcepType getType() { - return MSG_TYPE; - } - - @Override - public byte getReason() { - return this.yReason; - } - - @Override - public void setReason(byte value) { - this.yReason = value; - } - - @Override - public LinkedList<PcepValueType> getOptionalTlv() { - return this.llOptionalTlv; - } - - @Override - public void setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) { - this.llOptionalTlv = llOptionalTlv; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("closeObjectHeader", closeObjHeader).add("Reason", yReason) - .add("OptionalTlvlist", llOptionalTlv).toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepEndPointsObjectVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepEndPointsObjectVer1.java deleted file mode 100644 index 08dc0c9b..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepEndPointsObjectVer1.java +++ /dev/null @@ -1,256 +0,0 @@ -/* - * 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.PcepEndPointsObject; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP Endpoints Object. - */ -public class PcepEndPointsObjectVer1 implements PcepEndPointsObject { - - /* - * RFC : 5440 , section : 7.6 - * An End point is defined as follows: - END-POINTS Object-Class is 4. - - END-POINTS Object-Type is 1 for IPv4 and 2 for IPv6. - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Object-Class | OT |Res|P|I| Object Length (bytes) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Source IPv4 address | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Destination IPv4 address | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - */ - protected static final Logger log = LoggerFactory.getLogger(PcepEndPointsObjectVer1.class); - - static final byte END_POINTS_OBJ_TYPE = 1; - static final byte END_POINTS_OBJ_CLASS = 4; - static final byte END_POINTS_OBJECT_VERSION = 1; - static final short END_POINTS_OBJ_MINIMUM_LENGTH = 12; - public static byte endPointObjType; - - static final PcepObjectHeader DEFAULT_END_POINTS_OBJECT_HEADER = new PcepObjectHeader(END_POINTS_OBJ_CLASS, - END_POINTS_OBJ_TYPE, PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, - END_POINTS_OBJ_MINIMUM_LENGTH); - - private PcepObjectHeader endPointsObjHeader; - public int sourceIpAddress; - public int destIpAddress; - - /** - * Constructor to initialize all variables. - * - * @param endPointsObjHeader end points object header - * @param sourceIpAddress source IP address - * @param destIpAddress destination IP address - */ - public PcepEndPointsObjectVer1(PcepObjectHeader endPointsObjHeader, int sourceIpAddress, int destIpAddress) { - - this.endPointsObjHeader = endPointsObjHeader; - this.sourceIpAddress = sourceIpAddress; - this.destIpAddress = destIpAddress; - } - - /** - * Sets End Points Object Header. - * - * @param obj of PcepObjectHeader - */ - public void setEndPointsObjHeader(PcepObjectHeader obj) { - this.endPointsObjHeader = obj; - } - - @Override - public void setSourceIpAddress(int sourceIpAddress) { - this.sourceIpAddress = sourceIpAddress; - } - - @Override - public void setDestIpAddress(int destIpAddress) { - this.destIpAddress = destIpAddress; - } - - @Override - public int getSourceIpAddress() { - return this.sourceIpAddress; - } - - @Override - public int getDestIpAddress() { - return this.destIpAddress; - } - - /** - * Reads from channel buffer and returns object of PcepEndPointsObject. - * - * @param cb of channel buffer - * @return object of PcepEndPointsObject - * @throws PcepParseException while parsing channel buffer - */ - public static PcepEndPointsObject read(ChannelBuffer cb) throws PcepParseException { - - PcepObjectHeader endPointsObjHeader; - int sourceIpAddress; - int destIpAddress; - - endPointsObjHeader = PcepObjectHeader.read(cb); - if (endPointsObjHeader.getObjType() == END_POINTS_OBJ_TYPE - && endPointsObjHeader.getObjClass() == END_POINTS_OBJ_CLASS) { - sourceIpAddress = cb.readInt(); - destIpAddress = cb.readInt(); - } else { - throw new PcepParseException("Expected PcepEndPointsObject."); - } - return new PcepEndPointsObjectVer1(endPointsObjHeader, sourceIpAddress, destIpAddress); - } - - @Override - public int write(ChannelBuffer cb) throws PcepParseException { - - int objStartIndex = cb.writerIndex(); - //write common header - int objLenIndex = endPointsObjHeader.write(cb); - - //write source IPv4 IP - cb.writeInt(sourceIpAddress); - //write destination IPv4 IP - cb.writeInt(destIpAddress); - - int length = cb.writerIndex() - objStartIndex; - //now write EndPoints Object Length - cb.setShort(objLenIndex, (short) length); - //will be helpful during print(). - endPointsObjHeader.setObjLen((short) length); - - return cb.writerIndex(); - - } - - /** - * Builder class for PCEP end points objects. - */ - public static class Builder implements PcepEndPointsObject.Builder { - - private boolean bIsHeaderSet = false; - private boolean bIsSourceIpAddressset = false; - private boolean bIsDestIpAddressset = false; - private PcepObjectHeader endpointsObjHeader; - private int sourceIpAddress; - private int destIpAddress; - - private boolean bIsPFlagSet = false; - private boolean bPFlag; - - private boolean bIsIFlagSet = false; - private boolean bIFlag; - - @Override - public PcepEndPointsObject build() throws PcepParseException { - - PcepObjectHeader endpointsObjHeader = this.bIsHeaderSet ? this.endpointsObjHeader - : DEFAULT_END_POINTS_OBJECT_HEADER; - - if (bIsPFlagSet) { - endpointsObjHeader.setPFlag(bPFlag); - } - - if (bIsIFlagSet) { - endpointsObjHeader.setIFlag(bIFlag); - } - - if (!this.bIsSourceIpAddressset) { - throw new PcepParseException("SourceIpAddress not set while building EndPoints object"); - } - - if (!this.bIsDestIpAddressset) { - throw new PcepParseException("DestIpAddress not set while building EndPoints object"); - } - - return new PcepEndPointsObjectVer1(endpointsObjHeader, this.sourceIpAddress, this.destIpAddress); - } - - @Override - public PcepObjectHeader getEndPointsObjHeader() { - return this.endpointsObjHeader; - } - - @Override - public Builder setEndPointsObjHeader(PcepObjectHeader obj) { - this.endpointsObjHeader = obj; - this.bIsHeaderSet = true; - return this; - } - - @Override - public int getSourceIpAddress() { - return this.sourceIpAddress; - } - - @Override - public Builder setSourceIpAddress(int sourceIpAddress) { - this.sourceIpAddress = sourceIpAddress; - this.bIsSourceIpAddressset = true; - return this; - } - - @Override - public int getDestIpAddress() { - return this.destIpAddress; - } - - @Override - public Builder setDestIpAddress(int destIpAddress) { - this.destIpAddress = destIpAddress; - this.bIsDestIpAddressset = true; - 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("sourceIpAddress", sourceIpAddress) - .add("destIpAddress", destIpAddress).toString(); - } - -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepEroObjectVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepEroObjectVer1.java deleted file mode 100644 index 4d7cb16e..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepEroObjectVer1.java +++ /dev/null @@ -1,407 +0,0 @@ -/* - * 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.PcepEroObject; -import org.onosproject.pcepio.types.AutonomousSystemTlv; -import org.onosproject.pcepio.types.IPv4SubObject; -import org.onosproject.pcepio.types.IPv6SubObject; -import org.onosproject.pcepio.types.PathKeySubObject; -import org.onosproject.pcepio.types.PcepErrorDetailInfo; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.onosproject.pcepio.types.PcepValueType; -import org.onosproject.pcepio.types.SrEroSubObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP Ero Object. - */ -public class PcepEroObjectVer1 implements PcepEroObject { - /* - * rfc3209 - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Object-Class | OT |Res|P|I| Object Length (bytes) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | | - // (Subobjects) // - | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - If a Path message contains multiple EXPLICIT_ROUTE objects, only the - first object is meaningful. Subsequent EXPLICIT_ROUTE objects MAY be - ignored and SHOULD NOT be propagated. - - In current implementation, only strict hops are supported. So, - empty ERO with no sub-objects is considered illegal. - - Subobjects: - 0 1 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-------------//----------------+ - |L| Type | Length | (Subobject contents) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-------------//----------------+ - - L - - The L bit is an attribute of the subobject. The L bit is set - if the subobject represents a loose hop in the explicit route. - If the bit is not set, the subobject represents a strict hop in - the explicit route. - - Type - - The Type indicates the type of contents of the subobject. - - - Subobject 1: IPv4 address - - 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 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - |L| Type | Length | IPv4 address (4 bytes) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | IPv4 address (continued) | Prefix Length | Resvd | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - Subobject 2: IPv6 Prefix - - 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 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - |L| Type | Length | IPv6 address (16 bytes) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | IPv6 address (continued) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | IPv6 address (continued) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | IPv6 address (continued) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | IPv6 address (continued) | Prefix Length | Resvd | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - Subobject 3: Autonomous System Number - - The contents of an Autonomous System (AS) number subobject are a 2- - octet AS number. The abstract node represented by this subobject is - the set of nodes belonging to the autonomous system. - - The length of the AS number subobject is 4 octets. - - Subobject 4: PATH_KEY_32_BIT_SUB_OBJ_TYPE: - - Pathkey subobject(RFC 5520): - 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 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - |L| Type | Length | Path-Key | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | PCE ID (4 bytes) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - Subobject 5: SR_ERO_SUB_OBJ_TYPE: - - SR-ERO subobject: (draft-ietf-pce-segment-routing-00) - 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 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - |L| Type | Length | ST | Flags |F|S|C|M| - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | SID | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // NAI (variable) // - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - - protected static final Logger log = LoggerFactory.getLogger(PcepEroObjectVer1.class); - - public static final byte ERO_OBJ_TYPE = 1; - public static final byte ERO_OBJ_CLASS = 7; - public static final byte ERO_OBJECT_VERSION = 1; - public static final short ERO_OBJ_MINIMUM_LENGTH = 12; - public static final byte IPV4_TYPE = 1; - public static final byte PATH_KEY_32_BIT_SUB_OBJ_TYPE = 64; - public static final int LABEL_SUB_OBJ_TYPE = 3; - public static final int SR_ERO_SUB_OBJ_TYPE = 96; - public static final int OBJECT_HEADER_LENGTH = 4; - public static final int YTYPE_SHIFT_VALUE = 0x7F; - - static final PcepObjectHeader DEFAULT_ERO_OBJECT_HEADER = new PcepObjectHeader(ERO_OBJ_CLASS, ERO_OBJ_TYPE, - PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, ERO_OBJ_MINIMUM_LENGTH); - - private PcepObjectHeader eroObjHeader; - private LinkedList<PcepValueType> llSubObjects = new LinkedList<>(); - - /** - * reset variables. - */ - public PcepEroObjectVer1() { - this.eroObjHeader = null; - this.llSubObjects = null; - } - - /** - * Constructor to initialize parameters of ERO object. - * - * @param eroObjHeader ERO object header - * @param llSubObjects list of sub objects. - */ - public PcepEroObjectVer1(PcepObjectHeader eroObjHeader, LinkedList<PcepValueType> llSubObjects) { - - this.eroObjHeader = eroObjHeader; - this.llSubObjects = llSubObjects; - } - - /** - * Returns ERO object header. - * - * @return eroObjHeader ERO object header - */ - public PcepObjectHeader getEroObjHeader() { - return this.eroObjHeader; - } - - /** - * Sets Object Header. - * - * @param obj ERO object header - */ - public void setEroObjHeader(PcepObjectHeader obj) { - this.eroObjHeader = obj; - } - - @Override - public LinkedList<PcepValueType> getSubObjects() { - return this.llSubObjects; - } - - @Override - public void setSubObjects(LinkedList<PcepValueType> llSubObjects) { - this.llSubObjects = llSubObjects; - } - - /** - * Reads from channel buffer and returns object of PcepEroObject. - * - * @param cb channel buffer. - * @return object of PcepEroObject - * @throws PcepParseException when ERO object is not present in channel buffer - */ - public static PcepEroObject read(ChannelBuffer cb) throws PcepParseException { - - PcepObjectHeader eroObjHeader; - LinkedList<PcepValueType> llSubObjects = new LinkedList<>(); - - eroObjHeader = PcepObjectHeader.read(cb); - - if (eroObjHeader.getObjClass() != PcepEroObjectVer1.ERO_OBJ_CLASS) { - log.debug("ErrorType:" + PcepErrorDetailInfo.ERROR_TYPE_6 + " ErrorValue:" - + PcepErrorDetailInfo.ERROR_VALUE_9); - throw new PcepParseException(PcepErrorDetailInfo.ERROR_TYPE_6, PcepErrorDetailInfo.ERROR_VALUE_9); - } - - if (eroObjHeader.getObjLen() > OBJECT_HEADER_LENGTH) { - ChannelBuffer tempCb = cb.readBytes(eroObjHeader.getObjLen() - OBJECT_HEADER_LENGTH); - llSubObjects = parseSubObjects(tempCb); - } - return new PcepEroObjectVer1(eroObjHeader, llSubObjects); - } - - /** - * Parse list of Sub Objects. - * - * @param cb channel buffer - * @return list of Sub Objects - * @throws PcepParseException when fails to parse sub object list - */ - protected static LinkedList<PcepValueType> parseSubObjects(ChannelBuffer cb) throws PcepParseException { - - LinkedList<PcepValueType> llSubObjects = new LinkedList<>(); - - while (0 < cb.readableBytes()) { - - //check the Type of the TLV - byte yType = cb.readByte(); - yType = (byte) (yType & (YTYPE_SHIFT_VALUE)); - byte hLength = cb.readByte(); - - PcepValueType subObj; - - switch (yType) { - - case IPv4SubObject.TYPE: - subObj = IPv4SubObject.read(cb); - break; - case IPv6SubObject.TYPE: - byte[] ipv6Value = new byte[IPv6SubObject.VALUE_LENGTH]; - cb.readBytes(ipv6Value, 0, IPv6SubObject.VALUE_LENGTH); - subObj = new IPv6SubObject(ipv6Value); - break; - case AutonomousSystemTlv.TYPE: - subObj = AutonomousSystemTlv.read(cb); - break; - case PathKeySubObject.TYPE: - subObj = PathKeySubObject.read(cb); - break; - case SrEroSubObject.TYPE: - subObj = SrEroSubObject.read(cb); - break; - default: - throw new PcepParseException("Unexpected sub object. Type: " + (int) yType); - } - // Check for the padding - int pad = hLength % 4; - if (0 < pad) { - pad = 4 - pad; - if (pad <= cb.readableBytes()) { - cb.skipBytes(pad); - } - } - - llSubObjects.add(subObj); - } - if (0 < cb.readableBytes()) { - throw new PcepParseException("Subobject parsing error. Extra bytes received."); - } - return llSubObjects; - } - - @Override - public int write(ChannelBuffer cb) throws PcepParseException { - - //write Object header - int objStartIndex = cb.writerIndex(); - - int objLenIndex = eroObjHeader.write(cb); - - if (objLenIndex <= 0) { - throw new PcepParseException("Failed to write ERO object header. Index " + objLenIndex); - } - - ListIterator<PcepValueType> listIterator = llSubObjects.listIterator(); - - while (listIterator.hasNext()) { - listIterator.next().write(cb); - } - - //Update object length now - int length = cb.writerIndex() - objStartIndex; - cb.setShort(objLenIndex, (short) length); - //will be helpful during print(). - eroObjHeader.setObjLen((short) length); - - //As per RFC the length of object should be multiples of 4 - int pad = length % 4; - - if (pad != 0) { - pad = 4 - pad; - for (int i = 0; i < pad; i++) { - cb.writeByte((byte) 0); - } - length = length + pad; - } - - objLenIndex = cb.writerIndex(); - return objLenIndex; - } - - /** - * Builder class for PCEP ERO object. - */ - public static class Builder implements PcepEroObject.Builder { - - private boolean bIsHeaderSet = false; - - private boolean bIsPFlagSet = false; - private boolean bPFlag; - - private boolean bIsIFlagSet = false; - private boolean bIFlag; - - private PcepObjectHeader eroObjHeader; - LinkedList<PcepValueType> llSubObjects = new LinkedList<>(); - - @Override - public PcepEroObject build() { - - PcepObjectHeader eroObjHeader = this.bIsHeaderSet ? this.eroObjHeader : DEFAULT_ERO_OBJECT_HEADER; - - if (bIsPFlagSet) { - eroObjHeader.setPFlag(bPFlag); - } - - if (bIsIFlagSet) { - eroObjHeader.setIFlag(bIFlag); - } - - return new PcepEroObjectVer1(eroObjHeader, this.llSubObjects); - } - - @Override - public PcepObjectHeader getEroObjHeader() { - return this.eroObjHeader; - } - - @Override - public Builder setEroObjHeader(PcepObjectHeader obj) { - this.eroObjHeader = obj; - this.bIsHeaderSet = true; - return this; - } - - @Override - public LinkedList<PcepValueType> getSubObjects() { - return this.llSubObjects; - } - - @Override - public Builder setSubObjects(LinkedList<PcepValueType> llSubObjects) { - this.llSubObjects = llSubObjects; - 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("EroObjHeader", eroObjHeader).add("SubObjects", llSubObjects) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepErrorInfoVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepErrorInfoVer1.java deleted file mode 100644 index 594e40c1..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepErrorInfoVer1.java +++ /dev/null @@ -1,204 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.pcepio.protocol.ver1; - -import java.util.LinkedList; -import java.util.ListIterator; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepError; -import org.onosproject.pcepio.protocol.PcepErrorInfo; -import org.onosproject.pcepio.protocol.PcepErrorObject; -import org.onosproject.pcepio.protocol.PcepRPObject; -import org.onosproject.pcepio.protocol.PcepTEObject; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP Error Info. - * Reference :PCEP Extension for Transporting TE Data draft-dhodylee-pce-pcep-te-data-extn-02. - */ -public class PcepErrorInfoVer1 implements PcepErrorInfo { - - protected static final Logger log = LoggerFactory.getLogger(PcepErrorInfoVer1.class); - //Error list is optional - private LinkedList<PcepError> errList; - - /** - * Constructor to add PCEP error object to the list. - * - * @param llRPObjList list of PCEP RP object - * @param llTEObjList list of PCEP TE object - * @param llErrObjList list of PCEP error object - */ - public PcepErrorInfoVer1(LinkedList<PcepRPObject> llRPObjList, LinkedList<PcepTEObject> llTEObjList, - LinkedList<PcepErrorObject> llErrObjList) { - this.errList = new LinkedList<>(); - if ((llErrObjList != null) && (!llErrObjList.isEmpty())) { - this.errList.add(new PcepErrorVer1(llRPObjList, llTEObjList, llErrObjList)); - } - } - - /** - * Constructor to initialize error info. - * - * @param errll linked list or pcep error - */ - public PcepErrorInfoVer1(LinkedList<PcepError> errll) { - this.errList = errll; - } - - @Override - public boolean isErrorInfoPresent() { - return !this.errList.isEmpty(); - } - - @Override - public void read(ChannelBuffer cb) throws PcepParseException { - PcepObjectHeader tempObjHeader; - - while (0 < cb.readableBytes()) { - cb.markReaderIndex(); - tempObjHeader = PcepObjectHeader.read(cb); - cb.resetReaderIndex(); - byte yObjClass = tempObjHeader.getObjClass(); - if ((yObjClass != PcepRPObjectVer1.RP_OBJ_CLASS) && (yObjClass != PcepTEObjectVer1.TE_OBJ_CLASS) - && (yObjClass != PcepErrorObjectVer1.ERROR_OBJ_CLASS)) { - throw new PcepParseException("Unknown Object is present in PCEP-ERROR. Object Class: " + yObjClass); - } - - this.errList.add(PcepErrorVer1.read(cb)); - } - } - - @Override - public void write(ChannelBuffer cb) throws PcepParseException { - //write <error> - ListIterator<PcepError> listIterator = errList.listIterator(); - while (listIterator.hasNext()) { - PcepError pcepError = listIterator.next(); - - //RP Object list is optional - LinkedList<PcepRPObject> llRPObjList = pcepError.getRPObjList(); - if (llRPObjList != null) { - ListIterator<PcepRPObject> rpListIterator = llRPObjList.listIterator(); - while (rpListIterator.hasNext()) { - rpListIterator.next().write(cb); - } - } - - //TE Object list is optional - LinkedList<PcepTEObject> llTEObjList = pcepError.getTEObjList(); - if (llTEObjList != null) { - ListIterator<PcepTEObject> teListIterator = llTEObjList.listIterator(); - while (teListIterator.hasNext()) { - teListIterator.next().write(cb); - } - } - - // <error-obj-list> is mandatory - boolean bIsErrorObjListFound = false; - - LinkedList<PcepErrorObject> llErrObjList = pcepError.getErrorObjList(); - if (llErrObjList != null) { - ListIterator<PcepErrorObject> errObjListIterator = llErrObjList.listIterator(); - while (errObjListIterator.hasNext()) { - errObjListIterator.next().write(cb); - bIsErrorObjListFound = true; - } - } - - if (!bIsErrorObjListFound) { - throw new PcepParseException("<error-obj-list> is mandatory."); - } - } - } - - @Override - public LinkedList<Integer> getErrorType() { - LinkedList<Integer> errorType = new LinkedList<>(); - ListIterator<PcepError> listIterator = errList.listIterator(); - PcepErrorObject errObj; - int error; - while (listIterator.hasNext()) { - PcepError pcepError = listIterator.next(); - LinkedList<PcepErrorObject> llErrObjList = pcepError.getErrorObjList(); - if (llErrObjList != null) { - ListIterator<PcepErrorObject> errObjListIterator = llErrObjList.listIterator(); - while (errObjListIterator.hasNext()) { - errObj = errObjListIterator.next(); - error = errObj.getErrorType(); - errorType.add(error); - } - } - } - return errorType; - } - - @Override - public LinkedList<Integer> getErrorValue() { - LinkedList<Integer> errorValue = new LinkedList<>(); - ListIterator<PcepError> listIterator = errList.listIterator(); - PcepErrorObject errObj; - int error; - while (listIterator.hasNext()) { - PcepError pcepError = listIterator.next(); - LinkedList<PcepErrorObject> llErrObjList = pcepError.getErrorObjList(); - if (llErrObjList != null) { - ListIterator<PcepErrorObject> errObjListIterator = llErrObjList.listIterator(); - while (errObjListIterator.hasNext()) { - errObj = errObjListIterator.next(); - error = errObj.getErrorValue(); - errorValue.add(error); - } - } - } - return errorValue; - } - - /** - * Builder class for PCEP error info. - */ - public static class Builder implements PcepErrorInfo.Builder { - private LinkedList<PcepError> errll; - - @Override - public PcepErrorInfo build() { - return new PcepErrorInfoVer1(errll); - } - - @Override - public LinkedList<PcepError> getPcepErrorList() { - return this.errll; - } - - @Override - public Builder setPcepErrorList(LinkedList<PcepError> errll) { - this.errll = errll; - return this; - } - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("ErrorList", errList).toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepErrorMsgVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepErrorMsgVer1.java deleted file mode 100644 index 927d83d6..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepErrorMsgVer1.java +++ /dev/null @@ -1,383 +0,0 @@ -/* - * 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 org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepErrorInfo; -import org.onosproject.pcepio.protocol.PcepErrorMsg; -import org.onosproject.pcepio.protocol.PcepErrorObject; -import org.onosproject.pcepio.protocol.PcepMessageReader; -import org.onosproject.pcepio.protocol.PcepMessageWriter; -import org.onosproject.pcepio.protocol.PcepOpenObject; -import org.onosproject.pcepio.protocol.PcepType; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.onosproject.pcepio.types.ErrorObjListWithOpen; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; -import com.google.common.base.MoreObjects.ToStringHelper; - -/** - * Provides PCEP Error Message. - */ -public class PcepErrorMsgVer1 implements PcepErrorMsg { - - /* - * PCE Error message format. - - <PCErr Message> ::= <Common Header> - ( <error-obj-list> [<Open>] ) | <error> - [<error-list>] - - <error-obj-list> ::=<PCEP-ERROR>[<error-obj-list>] - - <error> ::=[<request-id-list> | <te-id-list>] - <error-obj-list> - - <request-id-list> ::=<RP>[<request-id-list>] - - <te-id-list> ::=<TE>[<te-id-list>] - - <error-list> ::=<error>[<error-list>] - */ - - protected static final Logger log = LoggerFactory.getLogger(PcepOpenMsgVer1.class); - public static final byte PACKET_VERSION = 1; - public static final int PACKET_MINIMUM_LENGTH = 12; - public static final PcepType MSG_TYPE = PcepType.ERROR; - - //Below either one should be present. - private ErrorObjListWithOpen errObjListWithOpen; //optional ( <error-obj-list> [<Open>] ) - private PcepErrorInfo errInfo; //optional <error> [<error-list>] - - public static final PcepErrorMsgVer1.Reader READER = new Reader(); - - /** - * constructor to initialize variables. - */ - public PcepErrorMsgVer1() { - errObjListWithOpen = null; - errInfo = null; - } - - /** - * Constructor to initialize variables. - * - * @param errObjListWithOpen error-object-list with open object - * @param errInfo error information - */ - public PcepErrorMsgVer1(ErrorObjListWithOpen errObjListWithOpen, PcepErrorInfo errInfo) { - this.errObjListWithOpen = errObjListWithOpen; - this.errInfo = errInfo; - } - - /** - * Reader class for reading PCEP error Message from channel buffer. - */ - public static class Reader implements PcepMessageReader<PcepErrorMsg> { - - ErrorObjListWithOpen errObjListWithOpen; - PcepErrorInfo errInfo; - PcepObjectHeader tempObjHeader; - - @Override - public PcepErrorMsg readFrom(ChannelBuffer cb) throws PcepParseException { - - errObjListWithOpen = null; - errInfo = null; - tempObjHeader = null; - - if (cb.readableBytes() < PACKET_MINIMUM_LENGTH) { - throw new PcepParseException("Packet size is less than the minimum length."); - } - - byte version = cb.readByte(); - version = (byte) (version >> PcepMessageVer1.SHIFT_FLAG); - if (version != PACKET_VERSION) { - throw new PcepParseException("Wrong version: Expected=PcepVersion.PCEP_1(1), got=" + version); - } - // fixed value property type == 1 - byte type = cb.readByte(); - if (type != MSG_TYPE.getType()) { - throw new PcepParseException("Wrong type: Expected=PcepType.ERROR(6), got=" + type); - } - int length = cb.readShort(); - if (length < PACKET_MINIMUM_LENGTH) { - throw new PcepParseException( - "Wrong length: Expected to be >= " + PACKET_MINIMUM_LENGTH + ", was: " + length); - } - - //parse <PCErr Message> - parsePCErrMsg(cb); - - // If other than RP or TE or PCEP-ERROR present then it is error. - if (0 < cb.readableBytes()) { - PcepObjectHeader tempObjHeader = PcepObjectHeader.read(cb); - throw new PcepParseException("Unexpected Object found. Object Class : " + tempObjHeader.getObjClass()); - } - - return new PcepErrorMsgVer1(errObjListWithOpen, errInfo); - } - - /** - * Parsing PCErr Message. - * - * @param cb channel buffer. - * @throws PcepParseException if mandatory fields are missing - * output: this.errObjListWithOpen, this.errInfo - */ - public void parsePCErrMsg(ChannelBuffer cb) throws PcepParseException { - //If PCEP-ERROR list is followed by OPEN Object then store into ErrorObjListWithOpen. - // ( <error-obj-list> [<Open>] - //If PCEP-ERROR list is followed by RP or TE Object then store into errInfo. <error> [<error-list>] - //If only PCEP-ERROR list is present then store into ErrorObjListWithOpen. - PcepObjectHeader tempObjHeader; - LinkedList<PcepErrorObject> llErrObjList; - - if (0 >= cb.readableBytes()) { - throw new PcepParseException("PCEP-ERROR message came with empty objects."); - } - - //parse PCEP-ERROR list - llErrObjList = new LinkedList<>(); - tempObjHeader = parseErrorObjectList(llErrObjList, cb); - - //check whether OPEN-OBJECT is present. - if ((tempObjHeader != null) - && (tempObjHeader.getObjClass() == PcepOpenObjectVer1.OPEN_OBJ_CLASS)) { - - if (llErrObjList.isEmpty()) { - throw new PcepParseException("<error-obj-list> should be present if OPEN-OBJECT exists"); - } - - PcepOpenObject pcepOpenObj = PcepOpenObjectVer1.read(cb); - this.errObjListWithOpen = new ErrorObjListWithOpen(llErrObjList, pcepOpenObj); - - } else if ((tempObjHeader != null) //check whether RP or TE Object is present. - && ((tempObjHeader.getObjClass() == PcepRPObjectVer1.RP_OBJ_CLASS) - || (tempObjHeader.getObjClass() == PcepTEObjectVer1.TE_OBJ_CLASS))) { - - this.errInfo = new PcepErrorInfoVer1(null, null, llErrObjList); - this.errInfo.read(cb); - - } else if (!llErrObjList.isEmpty()) { - //If only PCEP-ERROR list is present then store it in errObjListWithOpen. - this.errObjListWithOpen = new ErrorObjListWithOpen(llErrObjList); - } else { - throw new PcepParseException("Empty PCEP-ERROR message."); - } - } - - /** - * Parse error-obj-list. - * - * @param llErrObjList error object list output - * @param cb channel buffer input - * @throws PcepParseException if mandatory fields are missing - * @return error object header - */ - public PcepObjectHeader parseErrorObjectList(LinkedList<PcepErrorObject> llErrObjList, ChannelBuffer cb) - throws PcepParseException { - PcepObjectHeader tempObjHeader = null; - - while (0 < cb.readableBytes()) { - cb.markReaderIndex(); - tempObjHeader = PcepObjectHeader.read(cb); - cb.resetReaderIndex(); - if (tempObjHeader.getObjClass() == PcepErrorObjectVer1.ERROR_OBJ_CLASS) { - llErrObjList.add(PcepErrorObjectVer1.read(cb)); - } else { - break; - } - } - return tempObjHeader; - } - } - - /** - * Builder class for PCEP error message. - */ - public static class Builder implements PcepErrorMsg.Builder { - // Pcep error message fields - - private ErrorObjListWithOpen errObjListWithOpen = null; //optional ( <error-obj-list> [<Open>] ) - private PcepErrorInfo errInfo = null; //optional <error> [<error-list>] - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public PcepType getType() { - return PcepType.ERROR; - } - - @Override - public PcepErrorMsg build() { - return new PcepErrorMsgVer1(this.errObjListWithOpen, this.errInfo); - } - - @Override - public ErrorObjListWithOpen getErrorObjListWithOpen() { - return this.errObjListWithOpen; - } - - @Override - public Builder setErrorObjListWithOpen(ErrorObjListWithOpen errObjListWithOpen) { - this.errObjListWithOpen = errObjListWithOpen; - return this; - } - - @Override - public PcepErrorInfo getPcepErrorInfo() { - return this.errInfo; - } - - @Override - public Builder setPcepErrorInfo(PcepErrorInfo errInfo) { - this.errInfo = errInfo; - return this; - } - } - - @Override - public void writeTo(ChannelBuffer cb) throws PcepParseException { - WRITER.write(cb, this); - } - - public static final Writer WRITER = new Writer(); - - /** - * Writer class for writing PCEP error Message to channel buffer. - */ - static class Writer implements PcepMessageWriter<PcepErrorMsgVer1> { - @Override - public void write(ChannelBuffer cb, PcepErrorMsgVer1 message) throws PcepParseException { - int startIndex = cb.writerIndex(); - // first 3 bits set to version - cb.writeByte((byte) (PACKET_VERSION << PcepMessageVer1.SHIFT_FLAG)); - // message type 0xC - cb.writeByte(MSG_TYPE.getType()); - // length is length of variable message, will be updated at the end - // Store the position of message - // length in buffer - int msgLenIndex = cb.writerIndex(); - cb.writeShort(0); - ErrorObjListWithOpen errObjListWithOpen = message.getErrorObjListWithOpen(); - PcepErrorInfo errInfo = message.getPcepErrorInfo(); - - // write ( <error-obj-list> [<Open>] ) if exists. - // otherwise write <error> [<error-list>] - - if ((errObjListWithOpen != null) - && (errObjListWithOpen.isErrorObjListWithOpenPresent())) { - errObjListWithOpen.write(cb); - } else if ((errInfo != null) && (errInfo.isErrorInfoPresent())) { - errInfo.write(cb); - } else { - throw new PcepParseException("Empty PCEP-ERROR message."); - } - // PcepErrorMessage message length field - int length = cb.writerIndex() - startIndex; - cb.setShort(msgLenIndex, (short) length); - } - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public PcepType getType() { - return MSG_TYPE; - } - - @Override - public ErrorObjListWithOpen getErrorObjListWithOpen() { - return this.errObjListWithOpen; - } - - @Override - public void setErrorObjListWithOpen(ErrorObjListWithOpen errObjListWithOpen) { - this.errObjListWithOpen = errObjListWithOpen; - } - - @Override - public PcepErrorInfo getPcepErrorInfo() { - return this.errInfo; - } - - @Override - public void setPcepErrorInfo(PcepErrorInfo errInfo) { - this.errInfo = errInfo; - } - - /** - * Return list of Error types. - * - * @return error types list - */ - public LinkedList<Integer> getErrorType() { - LinkedList<Integer> llErrorType = new LinkedList<>(); - if ((errObjListWithOpen != null) - && (errObjListWithOpen.isErrorObjListWithOpenPresent())) { - llErrorType = errObjListWithOpen.getErrorType(); - } else if ((errInfo != null) && (errInfo.isErrorInfoPresent())) { - llErrorType = errInfo.getErrorType(); - } - - return llErrorType; - } - - /** - * Return list of Error values. - * - * @return error value list - */ - public LinkedList<Integer> getErrorValue() { - LinkedList<Integer> llErrorValue = new LinkedList<>(); - if ((errObjListWithOpen != null) - && (errObjListWithOpen.isErrorObjListWithOpenPresent())) { - llErrorValue = errObjListWithOpen.getErrorValue(); - } else if ((errInfo != null) && (errInfo.isErrorInfoPresent())) { - llErrorValue = errInfo.getErrorValue(); - } - - return llErrorValue; - } - - @Override - public String toString() { - ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass()); - - if ((errObjListWithOpen != null) - && (errObjListWithOpen.isErrorObjListWithOpenPresent())) { - toStrHelper.add("ErrorObjectListWithOpen", errObjListWithOpen); - } - if ((errInfo != null) && (errInfo.isErrorInfoPresent())) { - toStrHelper.add("ErrorInfo", errInfo); - } - - return toStrHelper.toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepErrorObjectVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepErrorObjectVer1.java deleted file mode 100644 index 48a337f4..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepErrorObjectVer1.java +++ /dev/null @@ -1,341 +0,0 @@ -/* - * 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.PcepErrorObject; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.onosproject.pcepio.types.PcepValueType; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP Error Object. - */ -public class PcepErrorObjectVer1 implements PcepErrorObject { - - /* - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Object-Class | OT |Res|P|I| Object Length (bytes) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Reserved | Flags | Error-Type | Error-value | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | | - // Optional TLVs // - | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - protected static final Logger log = LoggerFactory.getLogger(PcepErrorObjectVer1.class); - - public static final byte ERROR_OBJ_TYPE = 1; - public static final byte ERROR_OBJ_CLASS = 13; - public static final byte ERROR_OBJECT_VERSION = 1; - //ERROR_OBJ_MINIMUM_LENGTH = CommonHeaderLen(4)+ErrorObjectHeaderLen(4) - public static final short ERROR_OBJ_MINIMUM_LENGTH = 8; - public static final int OBJECT_HEADER_LENGTH = 4; - - public static final PcepObjectHeader DEFAULT_ERROR_OBJECT_HEADER = new PcepObjectHeader(ERROR_OBJ_CLASS, - ERROR_OBJ_TYPE, PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, - ERROR_OBJ_MINIMUM_LENGTH); - - private PcepObjectHeader errorObjHeader; - private byte yErrorType; - private byte yErrorValue; - private LinkedList<PcepValueType> llOptionalTlv; // Optional TLV - - /** - * Constructor to initialize variables. - * - * @param errorObjHeader ERROR Object header - * @param yErrorType Error Type - * @param yErrorValue Error Value - * @param llOptionalTlv list of optional TLV - */ - - public PcepErrorObjectVer1(PcepObjectHeader errorObjHeader, byte yErrorType, byte yErrorValue, - LinkedList<PcepValueType> llOptionalTlv) { - this.errorObjHeader = errorObjHeader; - this.yErrorType = yErrorType; - this.yErrorValue = yErrorValue; - this.llOptionalTlv = llOptionalTlv; - } - - /** - * sets Object Header. - * - * @param obj Error-Object header - */ - public void setLspObjHeader(PcepObjectHeader obj) { - this.errorObjHeader = obj; - } - - @Override - public void setErrorType(byte yErrorType) { - this.yErrorType = yErrorType; - } - - @Override - public void setErrorValue(byte yErrorValue) { - this.yErrorValue = yErrorValue; - } - - /** - * returns object header. - * - * @return errorObjHeader Error-Object header - */ - public PcepObjectHeader getErrorObjHeader() { - return this.errorObjHeader; - } - - @Override - public int getErrorType() { - return this.yErrorType; - } - - @Override - public byte getErrorValue() { - return this.yErrorValue; - } - - @Override - public LinkedList<PcepValueType> getOptionalTlv() { - return this.llOptionalTlv; - } - - @Override - public void setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) { - this.llOptionalTlv = llOptionalTlv; - } - - /** - * Reads from channel buffer and returns object of PcepErrorObject. - * - * @param cb of channel buffer. - * @return object of PCEP-ERROR-OBJECT - */ - public static PcepErrorObject read(ChannelBuffer cb) { - - PcepObjectHeader errorObjHeader; - byte yErrorType; - byte yErrorValue; - LinkedList<PcepValueType> llOptionalTlv; - - errorObjHeader = PcepObjectHeader.read(cb); - - //take only ErrorObject buffer. - ChannelBuffer tempCb = cb.readBytes(errorObjHeader.getObjLen() - OBJECT_HEADER_LENGTH); - tempCb.readByte(); //ignore Reserved - tempCb.readByte(); //ignore Flags - yErrorType = tempCb.readByte(); - yErrorValue = tempCb.readByte(); - - llOptionalTlv = parseOptionalTlv(tempCb); - - return new PcepErrorObjectVer1(errorObjHeader, yErrorType, yErrorValue, llOptionalTlv); - } - - /** - * returns Linked list of optional tlvs. - * - * @param cb channel buffer. - * @return Linked list of optional tlvs - */ - protected static LinkedList<PcepValueType> parseOptionalTlv(ChannelBuffer cb) { - - LinkedList<PcepValueType> llOutOptionalTlv = new LinkedList<>(); - - byte[] yTemp = new byte[cb.readableBytes()]; - cb.readBytes(yTemp); - - return llOutOptionalTlv; - } - - @Override - public int write(ChannelBuffer cb) throws PcepParseException { - - //write Object header - int objStartIndex = cb.writerIndex(); - - int objLenIndex = errorObjHeader.write(cb); - - if (objLenIndex <= 0) { - throw new PcepParseException("While writing Error Object Header."); - } - - //write Reserved - cb.writeByte(0); - //write Flags - cb.writeByte(0); - //write ErrorType and ErrorValue - cb.writeByte(this.yErrorType); - cb.writeByte(this.yErrorValue); - - // Add optional TLV - packOptionalTlv(cb); - - //Update object length now - int length = cb.writerIndex() - objStartIndex; - //will be helpful during print(). - errorObjHeader.setObjLen((short) length); - // As per RFC the length of object should be - // multiples of 4 - int pad = length % 4; - if (pad != 0) { - pad = 4 - pad; - for (int i = 0; i < pad; i++) { - cb.writeByte((byte) 0); - } - length = length + pad; - } - - cb.setShort(objLenIndex, (short) length); - return length; - } - - /** - * Pack the Optional tlvs. - * - * @param cb channel buffer. - * @return writer index. - */ - protected int packOptionalTlv(ChannelBuffer cb) { - - ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator(); - int startIndex = cb.writerIndex(); - while (listIterator.hasNext()) { - PcepValueType tlv = listIterator.next(); - - if (tlv == null) { - log.debug("TLV is null from OptionalTlv list"); - continue; - } - tlv.write(cb); - } - - return cb.writerIndex() - startIndex; - } - - /** - * Builder class for PCEP error object. - */ - public static class Builder implements PcepErrorObject.Builder { - - private boolean bIsHeaderSet = false; - - private PcepObjectHeader errorObjHeader; - private byte yErrorType; - private byte yErrorValue; - - private boolean bIsPFlagSet = false; - private boolean bPFlag; - - private boolean bIsIFlagSet = false; - private boolean bIFlag; - - private LinkedList<PcepValueType> llOptionalTlv = new LinkedList<>(); - - @Override - public PcepErrorObject build() { - - PcepObjectHeader errorObjHeader = this.bIsHeaderSet ? this.errorObjHeader : DEFAULT_ERROR_OBJECT_HEADER; - - if (bIsPFlagSet) { - errorObjHeader.setPFlag(bPFlag); - } - - if (bIsIFlagSet) { - errorObjHeader.setIFlag(bIFlag); - } - - return new PcepErrorObjectVer1(errorObjHeader, yErrorType, yErrorValue, llOptionalTlv); - } - - @Override - public PcepObjectHeader getErrorObjHeader() { - return this.errorObjHeader; - } - - @Override - public Builder setErrorObjHeader(PcepObjectHeader obj) { - this.errorObjHeader = obj; - this.bIsHeaderSet = true; - return this; - } - - @Override - public int getErrorType() { - return this.yErrorType; - } - - @Override - public Builder setErrorType(byte value) { - this.yErrorType = value; - return this; - } - - @Override - public byte getErrorValue() { - return this.yErrorValue; - } - - @Override - public Builder setErrorValue(byte value) { - this.yErrorValue = value; - return this; - } - - @Override - public Builder setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) { - this.llOptionalTlv = llOptionalTlv; - return this; - } - - @Override - public LinkedList<PcepValueType> getOptionalTlv() { - return this.llOptionalTlv; - } - - @Override - public Builder setPFlag(boolean value) { - this.bPFlag = value; - this.bIsPFlagSet = true; - return this; - } - - @Override - public Builder setIFlag(boolean value) { - this.bIFlag = value; - this.bIsIFlagSet = true; - return this; - } - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("ObjectHeader", errorObjHeader).add("ErrorType", yErrorType) - .add("ErrorValue", yErrorValue).add("OptionalTlv", llOptionalTlv).toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepErrorVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepErrorVer1.java deleted file mode 100644 index 0ea51410..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepErrorVer1.java +++ /dev/null @@ -1,399 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.pcepio.protocol.ver1; - -import java.util.LinkedList; -import java.util.ListIterator; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepError; -import org.onosproject.pcepio.protocol.PcepErrorObject; -import org.onosproject.pcepio.protocol.PcepRPObject; -import org.onosproject.pcepio.protocol.PcepTEObject; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PcepError list which contains RP or TE objects. - * Reference:PCEP Extension for Transporting TE Data draft-dhodylee-pce-pcep-te-data-extn-02. - */ -public class PcepErrorVer1 implements PcepError { - - /* - <error>::=[<request-id-list> | <te-id-list>] - <error-obj-list> - - <request-id-list>::=<RP>[<request-id-list>] - - <te-id-list>::=<TE>[<te-id-list>] - */ - - protected static final Logger log = LoggerFactory.getLogger(PcepErrorVer1.class); - - private boolean isErroInfoSet; - //PcepErrorObject list - private LinkedList<PcepErrorObject> llErrObjList; - //PcepRPObject list - private LinkedList<PcepRPObject> llRPObjList; - //PcepTEObject list - private LinkedList<PcepTEObject> llTEObjList; - private boolean isTEObjListSet; - - public static final int OBJECT_HEADER_LENGTH = 4; - - /** - * Constructor to initialize variable. - */ - public PcepErrorVer1() { - this.llRPObjList = null; - this.llTEObjList = null; - this.llErrObjList = null; - } - - /** - * Constructor to initialize variable. - * - * @param llRPObjList list of PcepRPObject - * @param llTEObjList list of PcepTEObject - * @param llErrObjListObjList list of PcepErrorObject - */ - public PcepErrorVer1(LinkedList<PcepRPObject> llRPObjList, LinkedList<PcepTEObject> llTEObjList, - LinkedList<PcepErrorObject> llErrObjListObjList) { - this.llRPObjList = llRPObjList; - this.llTEObjList = llTEObjList; - this.llErrObjList = llErrObjListObjList; - } - - /** - * Constructor to initialize PcepError. - * - * @param llErrObjList list of PcepErrorObject - */ - public PcepErrorVer1(LinkedList<PcepErrorObject> llErrObjList) { - this.llRPObjList = null; - this.llTEObjList = null; - this.llErrObjList = llErrObjList; - } - - @Override - public LinkedList<PcepRPObject> getRPObjList() { - return this.llRPObjList; - } - - @Override - public LinkedList<PcepTEObject> getTEObjList() { - return this.llTEObjList; - } - - @Override - public LinkedList<PcepErrorObject> getErrorObjList() { - return this.llErrObjList; - } - - /** - * Parse RP List from the channel buffer. - * - * @param cb of type channel buffer - * @throws PcepParseException if mandatory fields are missing - */ - public void parseRPList(ChannelBuffer cb) throws PcepParseException { - byte yObjClass; - byte yObjType; - - llRPObjList = new LinkedList<>(); - - // caller should verify for RP object - if (cb.readableBytes() < OBJECT_HEADER_LENGTH) { - log.debug("Unable to find RP Object"); - return; - } - - cb.markReaderIndex(); - PcepObjectHeader tempObjHeader = PcepObjectHeader.read(cb); - cb.resetReaderIndex(); - yObjClass = tempObjHeader.getObjClass(); - yObjType = tempObjHeader.getObjType(); - PcepRPObject rpObj; - while ((yObjClass == PcepRPObjectVer1.RP_OBJ_CLASS) && (yObjType == PcepRPObjectVer1.RP_OBJ_TYPE)) { - rpObj = PcepRPObjectVer1.read(cb); - llRPObjList.add(rpObj); - - if (cb.readableBytes() > OBJECT_HEADER_LENGTH) { - cb.markReaderIndex(); - tempObjHeader = PcepObjectHeader.read(cb); - cb.resetReaderIndex(); - yObjClass = tempObjHeader.getObjClass(); - yObjType = tempObjHeader.getObjType(); - } else { - break; - } - } - } - - /** - * Parse TE List from the channel buffer. - * - * @param cb of type channel buffer - * @throws PcepParseException if mandatory fields are missing - */ - public void parseTEList(ChannelBuffer cb) throws PcepParseException { - byte yObjClass; - byte yObjType; - - llTEObjList = new LinkedList<>(); - - // caller should verify for TE object - if (cb.readableBytes() < OBJECT_HEADER_LENGTH) { - log.debug("Unable to find TE Object"); - return; - } - - cb.markReaderIndex(); - PcepObjectHeader tempObjHeader = PcepObjectHeader.read(cb); - cb.resetReaderIndex(); - yObjClass = tempObjHeader.getObjClass(); - yObjType = tempObjHeader.getObjType(); - PcepTEObject teObj; - while ((yObjClass == PcepTEObjectVer1.TE_OBJ_CLASS) && ((yObjType == PcepTEObjectVer1.TE_OBJ_TYPE_NODE_VALUE) - || (yObjType == PcepTEObjectVer1.TE_OBJ_TYPE_LINK_VALUE))) { - teObj = PcepTEObjectVer1.read(cb); - llTEObjList.add(teObj); - - if (cb.readableBytes() > OBJECT_HEADER_LENGTH) { - cb.markReaderIndex(); - tempObjHeader = PcepObjectHeader.read(cb); - cb.resetReaderIndex(); - yObjClass = tempObjHeader.getObjClass(); - yObjType = tempObjHeader.getObjType(); - } else { - break; - } - } - } - - /** - * parseErrObjList from the channel buffer. - * - * @param cb of type channel buffer - * @throws PcepParseException if mandatory fields are missing - */ - public void parseErrObjList(ChannelBuffer cb) throws PcepParseException { - byte yObjClass; - byte yObjType; - boolean bIsErrorObjFound = false; - - llErrObjList = new LinkedList<>(); - - // caller should verify for RP object - if (cb.readableBytes() < OBJECT_HEADER_LENGTH) { - throw new PcepParseException("Unable to find PCEP-ERROR Object"); - } - - cb.markReaderIndex(); - PcepObjectHeader tempObjHeader = PcepObjectHeader.read(cb); - cb.resetReaderIndex(); - yObjClass = tempObjHeader.getObjClass(); - yObjType = tempObjHeader.getObjType(); - PcepErrorObject errorObject; - while ((yObjClass == PcepErrorObjectVer1.ERROR_OBJ_CLASS) && (yObjType == PcepErrorObjectVer1.ERROR_OBJ_TYPE)) { - errorObject = PcepErrorObjectVer1.read(cb); - llErrObjList.add(errorObject); - bIsErrorObjFound = true; - - if (cb.readableBytes() > OBJECT_HEADER_LENGTH) { - cb.markReaderIndex(); - tempObjHeader = PcepObjectHeader.read(cb); - cb.resetReaderIndex(); - yObjClass = tempObjHeader.getObjClass(); - yObjType = tempObjHeader.getObjType(); - } else { - break; - } - } - - if (!bIsErrorObjFound) { - throw new PcepParseException("At least one PCEP-ERROR Object should be present."); - } - } - - /** - * Reads the byte stream of PcepError from channel buffer. - * - * @param cb of type channel buffer - * @return PcepError error part of PCEP-ERROR - * @throws PcepParseException if mandatory fields are missing - */ - public static PcepErrorVer1 read(ChannelBuffer cb) throws PcepParseException { - if (cb.readableBytes() < OBJECT_HEADER_LENGTH) { - throw new PcepParseException("Unknown Object"); - } - - PcepErrorVer1 pcepError = new PcepErrorVer1(); - // check whether any PCEP Error Info is present - cb.markReaderIndex(); - PcepObjectHeader tempObjHeader = PcepObjectHeader.read(cb); - cb.resetReaderIndex(); - byte yObjClass = tempObjHeader.getObjClass(); - - //If RPlist present then store it.RPList and TEList are optional - if (yObjClass == PcepRPObjectVer1.RP_OBJ_CLASS) { - log.debug("RP_LIST"); - pcepError.parseRPList(cb); - yObjClass = checkNextObject(cb); - } else if (yObjClass == PcepTEObjectVer1.TE_OBJ_CLASS) { - log.debug("TE_LIST"); - pcepError.parseTEList(cb); - yObjClass = checkNextObject(cb); - } - - if (yObjClass == PcepErrorObjectVer1.ERROR_OBJ_CLASS) { - log.debug("PCEP-ERROR obj list"); - pcepError.parseErrObjList(cb); - yObjClass = checkNextObject(cb); - } - - return pcepError; - } - - /** - * Checks Next Object. - * - * @param cb of type channel buffer. - * @return object type class. - */ - private static byte checkNextObject(ChannelBuffer cb) { - if (cb.readableBytes() < OBJECT_HEADER_LENGTH) { - return 0; - } - cb.markReaderIndex(); - PcepObjectHeader tempObjHeader = PcepObjectHeader.read(cb); - cb.resetReaderIndex(); - return tempObjHeader.getObjClass(); - } - - /** - * Writes the byte stream of PCEP error to the channel buffer. - * - * @param cb of type channel buffer - * @return object length index - * @throws PcepParseException if mandatory fields are missing - */ - @Override - public int write(ChannelBuffer cb) throws PcepParseException { - int iLenStartIndex = cb.writerIndex(); - - // RPlist is optional - if (this.isErroInfoSet) { - ListIterator<PcepRPObject> rpObjlistIterator = this.llRPObjList.listIterator(); - while (rpObjlistIterator.hasNext()) { - rpObjlistIterator.next().write(cb); - } - } - - // TElist is optional - if (this.isTEObjListSet) { - ListIterator<PcepTEObject> teObjlistIterator = this.llTEObjList.listIterator(); - while (teObjlistIterator.hasNext()) { - teObjlistIterator.next().write(cb); - } - } - //ErrList is mandatory - ListIterator<PcepErrorObject> errlistIterator = this.llErrObjList.listIterator(); - while (errlistIterator.hasNext()) { - errlistIterator.next().write(cb); - } - - return cb.writerIndex() - iLenStartIndex; - } - - /** - * Builder for error part of PCEP-ERROR. - */ - public static class Builder implements PcepError.Builder { - - private LinkedList<PcepRPObject> llRPObjList; - private LinkedList<PcepTEObject> llTEObjList; - private LinkedList<PcepErrorObject> llErrObjList; - - @Override - public PcepError build() { - return new PcepErrorVer1(llRPObjList, llTEObjList, llErrObjList); - } - - @Override - public LinkedList<PcepRPObject> getRPObjList() { - return this.llRPObjList; - } - - @Override - public Builder setRPObjList(LinkedList<PcepRPObject> llRPObjList) { - this.llRPObjList = llRPObjList; - return this; - } - - @Override - public LinkedList<PcepTEObject> getTEObjList() { - return this.llTEObjList; - } - - @Override - public Builder setTEObjList(LinkedList<PcepTEObject> llTEObjList) { - this.llTEObjList = llTEObjList; - return this; - } - - @Override - public LinkedList<PcepErrorObject> getErrorObjList() { - return this.llErrObjList; - } - - @Override - public Builder setErrorObjList(LinkedList<PcepErrorObject> llErrObjList) { - this.llErrObjList = llErrObjList; - return this; - } - - } - - @Override - public void setRPObjList(LinkedList<PcepRPObject> llRPObjList) { - this.llRPObjList = llRPObjList; - } - - @Override - public void setTEObjList(LinkedList<PcepTEObject> llTEObjList) { - this.llTEObjList = llTEObjList; - } - - @Override - public void setErrorObjList(LinkedList<PcepErrorObject> llErrObjList) { - this.llErrObjList = llErrObjList; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .omitNullValues() - .add("RpObjectList", llRPObjList) - .add("TeObjectList", llTEObjList) - .add("ErrorObjectList", llErrObjList) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFactoryVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFactoryVer1.java deleted file mode 100644 index 6b5d450a..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFactoryVer1.java +++ /dev/null @@ -1,226 +0,0 @@ -/* - * 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.onosproject.pcepio.protocol.PcInitiatedLspRequest; -import org.onosproject.pcepio.protocol.PcepAttribute; -import org.onosproject.pcepio.protocol.PcepBandwidthObject; -import org.onosproject.pcepio.protocol.PcepCloseMsg; -import org.onosproject.pcepio.protocol.PcepEndPointsObject; -import org.onosproject.pcepio.protocol.PcepEroObject; -import org.onosproject.pcepio.protocol.PcepErrorInfo; -import org.onosproject.pcepio.protocol.PcepError; -import org.onosproject.pcepio.protocol.PcepErrorMsg; -import org.onosproject.pcepio.protocol.PcepErrorObject; -import org.onosproject.pcepio.protocol.PcepFactory; -import org.onosproject.pcepio.protocol.PcepFecObjectIPv4Adjacency; -import org.onosproject.pcepio.protocol.PcepInitiateMsg; -import org.onosproject.pcepio.protocol.PcepIroObject; -import org.onosproject.pcepio.protocol.PcepKeepaliveMsg; -import org.onosproject.pcepio.protocol.PcepLabelObject; -import org.onosproject.pcepio.protocol.PcepLabelRangeObject; -import org.onosproject.pcepio.protocol.PcepLabelRangeResvMsg; -import org.onosproject.pcepio.protocol.PcepLabelUpdate; -import org.onosproject.pcepio.protocol.PcepLabelUpdateMsg; -import org.onosproject.pcepio.protocol.PcepLspObject; -import org.onosproject.pcepio.protocol.PcepLspaObject; -import org.onosproject.pcepio.protocol.PcepMessage; -import org.onosproject.pcepio.protocol.PcepMessageReader; -import org.onosproject.pcepio.protocol.PcepMetricObject; -import org.onosproject.pcepio.protocol.PcepMsgPath; -import org.onosproject.pcepio.protocol.PcepOpenMsg; -import org.onosproject.pcepio.protocol.PcepOpenObject; -import org.onosproject.pcepio.protocol.PcepReportMsg; -import org.onosproject.pcepio.protocol.PcepRroObject; -import org.onosproject.pcepio.protocol.PcepSrpObject; -import org.onosproject.pcepio.protocol.PcepStateReport; -import org.onosproject.pcepio.protocol.PcepUpdateMsg; -import org.onosproject.pcepio.protocol.PcepUpdateRequest; -import org.onosproject.pcepio.protocol.PcepVersion; - -/** - * Provides PCEP Factory and returns builder classes for all objects and messages. - */ -public class PcepFactoryVer1 implements PcepFactory { - - public static final PcepFactoryVer1 INSTANCE = new PcepFactoryVer1(); - - @Override - public PcepOpenMsg.Builder buildOpenMsg() { - return new PcepOpenMsgVer1.Builder(); - } - - @Override - public PcepOpenObject.Builder buildOpenObject() { - return new PcepOpenObjectVer1.Builder(); - } - - @Override - public PcepKeepaliveMsg.Builder buildKeepaliveMsg() { - return new PcepKeepaliveMsgVer1.Builder(); - } - - @Override - public PcepCloseMsg.Builder buildCloseMsg() { - return new PcepCloseMsgVer1.Builder(); - } - - @Override - public PcepUpdateMsg.Builder buildUpdateMsg() { - return new PcepUpdateMsgVer1.Builder(); - } - - @Override - public PcepReportMsg.Builder buildReportMsg() { - return new PcepReportMsgVer1.Builder(); - } - - @Override - public PcepInitiateMsg.Builder buildPcepInitiateMsg() { - return new PcepInitiateMsgVer1.Builder(); - } - - @Override - public PcepLspObject.Builder buildLspObject() { - return new PcepLspObjectVer1.Builder(); - } - - @Override - public PcepMessageReader<PcepMessage> getReader() { - return PcepMessageVer1.READER; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public PcepSrpObject.Builder buildSrpObject() { - return new PcepSrpObjectVer1.Builder(); - } - - @Override - public PcepEndPointsObject.Builder buildEndPointsObject() { - return new PcepEndPointsObjectVer1.Builder(); - } - - @Override - public PcepEroObject.Builder buildEroObject() { - return new PcepEroObjectVer1.Builder(); - } - - @Override - public PcepRroObject.Builder buildRroObject() { - return new PcepRroObjectVer1.Builder(); - } - - @Override - public PcepLspaObject.Builder buildLspaObject() { - return new PcepLspaObjectVer1.Builder(); - } - - @Override - public PcepIroObject.Builder buildIroObject() { - return new PcepIroObjectVer1.Builder(); - } - - @Override - public PcepMetricObject.Builder buildMetricObject() { - return new PcepMetricObjectVer1.Builder(); - } - - @Override - public PcepBandwidthObject.Builder buildBandwidthObject() { - return new PcepBandwidthObjectVer1.Builder(); - } - - @Override - public PcepMsgPath.Builder buildPcepMsgPath() { - return new PcepMsgPathVer1.Builder(); - } - - @Override - public PcepStateReport.Builder buildPcepStateReport() { - return new PcepStateReportVer1.Builder(); - } - - @Override - public PcepUpdateRequest.Builder buildPcepUpdateRequest() { - return new PcepUpdateRequestVer1.Builder(); - } - - @Override - public PcInitiatedLspRequest.Builder buildPcInitiatedLspRequest() { - return new PcInitiatedLspRequestVer1.Builder(); - } - - @Override - public PcepAttribute.Builder buildPcepAttribute() { - return new PcepAttributeVer1.Builder(); - } - - @Override - public PcepLabelUpdateMsg.Builder buildPcepLabelUpdateMsg() { - return new PcepLabelUpdateMsgVer1.Builder(); - } - - @Override - public PcepLabelUpdate.Builder buildPcepLabelUpdateObject() { - return new PcepLabelUpdateVer1.Builder(); - } - - @Override - public PcepLabelObject.Builder buildLabelObject() { - return new PcepLabelObjectVer1.Builder(); - } - - @Override - public PcepErrorMsg.Builder buildPcepErrorMsg() { - return new PcepErrorMsgVer1.Builder(); - } - - @Override - public PcepErrorObject.Builder buildPcepErrorObject() { - return new PcepErrorObjectVer1.Builder(); - } - - @Override - public PcepFecObjectIPv4Adjacency.Builder buildFecIpv4Adjacency() { - return new PcepFecObjectIPv4AdjacencyVer1.Builder(); - } - - @Override - public PcepErrorInfo.Builder buildPcepErrorInfo() { - return new PcepErrorInfoVer1.Builder(); - } - - @Override - public PcepError.Builder buildPcepError() { - return new PcepErrorVer1.Builder(); - } - - @Override - public PcepLabelRangeObject.Builder buildPcepLabelRangeObject() { - return new PcepLabelRangeObjectVer1.Builder(); - } - - @Override - public PcepLabelRangeResvMsg.Builder buildPcepLabelRangeResvMsg() { - return new PcepLabelRangeResvMsgVer1.Builder(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv4AdjacencyVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv4AdjacencyVer1.java deleted file mode 100644 index 51c672d3..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv4AdjacencyVer1.java +++ /dev/null @@ -1,253 +0,0 @@ -/* - * 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; - -/** - * Provides PCEP fec Object IPv4 Adjacency object. - */ -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/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv4UnnumberedAdjacencyVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv4UnnumberedAdjacencyVer1.java deleted file mode 100644 index f2f54cda..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv4UnnumberedAdjacencyVer1.java +++ /dev/null @@ -1,334 +0,0 @@ -/* - * 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; - -/** - * Provides Pcep Fec Object IPv4 Unnumbered Adjacency object. - */ -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/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv4Ver1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv4Ver1.java deleted file mode 100644 index 354547a1..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv4Ver1.java +++ /dev/null @@ -1,217 +0,0 @@ -/* - * 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; - -/** - * Provides Pcep Fec Object IPv4 object. - */ -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/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv6AdjacencyVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv6AdjacencyVer1.java deleted file mode 100644 index f8ea7869..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv6AdjacencyVer1.java +++ /dev/null @@ -1,249 +0,0 @@ -/* - * 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; - -/** - * Provides Pcep Fec Object IPv6 Adjacency object. - */ -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/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv6Ver1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv6Ver1.java deleted file mode 100644 index 240a96f7..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv6Ver1.java +++ /dev/null @@ -1,220 +0,0 @@ -/* - * 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; - -/** - * Provides Pcep Fec Object IPv6 object. - */ -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/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepInitiateMsgVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepInitiateMsgVer1.java deleted file mode 100644 index 60d14b07..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepInitiateMsgVer1.java +++ /dev/null @@ -1,332 +0,0 @@ -/* - * 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.PcInitiatedLspRequest; -import org.onosproject.pcepio.protocol.PcepAttribute; -import org.onosproject.pcepio.protocol.PcepEndPointsObject; -import org.onosproject.pcepio.protocol.PcepEroObject; -import org.onosproject.pcepio.protocol.PcepInitiateMsg; -import org.onosproject.pcepio.protocol.PcepLspObject; -import org.onosproject.pcepio.protocol.PcepMessageReader; -import org.onosproject.pcepio.protocol.PcepMessageWriter; -import org.onosproject.pcepio.protocol.PcepSrpObject; -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; - -/** - * Provides PCEP initiate message. - */ -class PcepInitiateMsgVer1 implements PcepInitiateMsg { - - protected static final Logger log = LoggerFactory.getLogger(PcepInitiateMsgVer1.class); - - // Ref : PCE initiated tunnel setup draft-ietf-pce-pce-initiated-lsp-03, section 5.1 - /* <PCInitiate Message> ::= <Common Header> - * <PCE-initiated-lsp-list> - * Where: - * <PCE-initiated-lsp-list> ::= <PCE-initiated-lsp-request>[<PCE-initiated-lsp-list>] - * <PCE-initiated-lsp-request> ::= (<PCE-initiated-lsp-instantiation>|<PCE-initiated-lsp-deletion>) - * <PCE-initiated-lsp-instantiation> ::= <SRP> - * <LSP> - * <END-POINTS> - * <ERO> - * [<attribute-list>] - * <PCE-initiated-lsp-deletion> ::= <SRP> - * <LSP> - */ - - static final byte PACKET_VERSION = 1; - /* considering LspDelete Request PcInitiate msg will contain - * common header - * srp object - * lsp object - * so min length for this can be - * PACKET_MINIMUM_LENGTH = CommonHeaderLen(4)+SrpObjectMinLen(12)+LspObjectMinLen(8) - */ - public static final short PACKET_MINIMUM_LENGTH = 24; - public static final short MINIMUM_COMMON_HEADER_LENGTH = 4; - public static final PcepType MSG_TYPE = PcepType.INITIATE; - private LinkedList<PcInitiatedLspRequest> llPcInitiatedLspRequestList; - public static final PcepInitiateMsgVer1.Reader READER = new Reader(); - - /** - * Reader class for reading of Pcep initiate message from channel buffer. - */ - static class Reader implements PcepMessageReader<PcepInitiateMsg> { - - LinkedList<PcInitiatedLspRequest> llPcInitiatedLspRequestList; - - @Override - public PcepInitiateMsg readFrom(ChannelBuffer cb) throws PcepParseException { - - if (cb.readableBytes() < PACKET_MINIMUM_LENGTH) { - return null; - } - - llPcInitiatedLspRequestList = new LinkedList<>(); - - byte version = cb.readByte(); - version = (byte) (version >> PcepMessageVer1.SHIFT_FLAG); - if (version != PACKET_VERSION) { - throw new PcepParseException("Wrong version. Expected=PcepVersion.PCEP_1(1), received=" + version); - } - byte type = cb.readByte(); - if (type != MSG_TYPE.getType()) { - throw new PcepParseException("Wrong type. Expected=PcepType.INITIATE(12), recived=" + type); - } - short length = cb.readShort(); - - if (length < PACKET_MINIMUM_LENGTH) { - throw new PcepParseException("Wrong length. Initiate message length expected to be >= " - + PACKET_MINIMUM_LENGTH + ", but received=" + length); - } - - log.debug("reading PcInitiate message of length " + length); - - // parse Start initiate/deletion list - if (!parsePcInitiatedLspRequestList(cb)) { - throw new PcepParseException("Parsing PCE-initiated-lsp-Request-list failed"); - } - - return new PcepInitiateMsgVer1(llPcInitiatedLspRequestList); - } - - /** - * To parse PcInitiatedLspRequestList from PcInitiate Message. - * - * @param cb of type channel buffer - * @return true if parsing PcInitiatedLspRequestList is success, false otherwise - * @throws PcepParseException while parsing from channel buffer - */ - public boolean parsePcInitiatedLspRequestList(ChannelBuffer cb) throws PcepParseException { - - boolean isDelLspRequest = false; - - if (cb == null) { - throw new PcepParseException("Channel buffer is empty"); - } - - while (0 < cb.readableBytes()) { - PcInitiatedLspRequest pceInitLspReq = new PcInitiatedLspRequestVer1(); - - //store SRP object - PcepSrpObject srpObj; - srpObj = PcepSrpObjectVer1.read(cb); - pceInitLspReq.setSrpObject(srpObj); - isDelLspRequest = srpObj.getRFlag(); - - //store LSP object - PcepLspObject lspObj; - lspObj = PcepLspObjectVer1.read(cb); - pceInitLspReq.setLspObject(lspObj); - - /* if R bit will be set then pcInitiate msg will contain only LSp and SRP objects - * so if R bit is not set then we should read for Ero and EndPoint objects also. - */ - if (!isDelLspRequest) { - - //store EndPoint object - PcepEndPointsObject endPointObj; - endPointObj = PcepEndPointsObjectVer1.read(cb); - pceInitLspReq.setEndPointsObject(endPointObj); - - //store ERO object - PcepEroObject eroObj; - eroObj = PcepEroObjectVer1.read(cb); - pceInitLspReq.setEroObject(eroObj); - - if (cb.readableBytes() > MINIMUM_COMMON_HEADER_LENGTH) { - pceInitLspReq.setPcepAttribute(PcepAttributeVer1.read(cb)); - } - } - llPcInitiatedLspRequestList.add(pceInitLspReq); - } - return true; - } - } - - /** - * Constructor to initialize PcInitiatedLspRequest. - * - * @param llPcInitiatedLspRequestList list of PcInitiatedLspRequest - */ - PcepInitiateMsgVer1(LinkedList<PcInitiatedLspRequest> llPcInitiatedLspRequestList) { - - if (llPcInitiatedLspRequestList == null) { - throw new NullPointerException("PcInitiatedLspRequestList cannot be null."); - } - this.llPcInitiatedLspRequestList = llPcInitiatedLspRequestList; - } - - /** - * Builder class for PCEP initiate message. - */ - static class Builder implements PcepInitiateMsg.Builder { - - // Pcep initiate message fields - LinkedList<PcInitiatedLspRequest> llPcInitiatedLspRequestList; - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public PcepType getType() { - return PcepType.INITIATE; - } - - @Override - public PcepInitiateMsg build() { - return new PcepInitiateMsgVer1(this.llPcInitiatedLspRequestList); - } - - @Override - public LinkedList<PcInitiatedLspRequest> getPcInitiatedLspRequestList() { - return this.llPcInitiatedLspRequestList; - } - - @Override - public Builder setPcInitiatedLspRequestList(LinkedList<PcInitiatedLspRequest> ll) { - this.llPcInitiatedLspRequestList = ll; - return this; - } - } - - @Override - public void writeTo(ChannelBuffer cb) throws PcepParseException { - WRITER.write(cb, this); - } - - static final Writer WRITER = new Writer(); - - /** - * Writer class for writing pcep initiate message to channel buffer. - */ - static class Writer implements PcepMessageWriter<PcepInitiateMsgVer1> { - - @Override - public void write(ChannelBuffer cb, PcepInitiateMsgVer1 message) throws PcepParseException { - - boolean isDelLspRequest = false; - int startIndex = cb.writerIndex(); - // first 3 bits set to version - cb.writeByte((byte) (PACKET_VERSION << PcepMessageVer1.SHIFT_FLAG)); - // message type 0xC - cb.writeByte(MSG_TYPE.getType()); - // length is length of variable message, will be updated at the end - // Store the position of message - // length in buffer - int msgLenIndex = cb.writerIndex(); - cb.writeShort(0); - - ListIterator<PcInitiatedLspRequest> listIterator = message.llPcInitiatedLspRequestList.listIterator(); - - while (listIterator.hasNext()) { - - PcInitiatedLspRequest listReq = listIterator.next(); - - //Srp Object is mandatory - PcepSrpObject srpObj = listReq.getSrpObject(); - if (srpObj != null) { - isDelLspRequest = srpObj.getRFlag(); - srpObj.write(cb); - } else { - throw new PcepParseException("SRP Object is mandatory for PcInitiate message."); - } - - //LSP Object is mandatory - PcepLspObject lspObj = listReq.getLspObject(); - if (lspObj != null) { - lspObj.write(cb); - } else { - throw new PcepParseException("LSP Object is mandatory for PcInitiate message."); - } - - /* if R bit will be set then pcInitiate msg will contain only LSp and SRP objects - * so if R bit is not set then we should read for Ero and EndPoint objects also. - */ - - if (!isDelLspRequest) { - - //EndPoints object is mandatory - PcepEndPointsObject endPointObj = listReq.getEndPointsObject(); - if (endPointObj != null) { - endPointObj.write(cb); - } else { - throw new PcepParseException("End points Object is mandatory for PcInitiate message."); - } - - //Ero object is mandatory - PcepEroObject eroObj = listReq.getEroObject(); - if (eroObj != null) { - eroObj.write(cb); - } else { - throw new PcepParseException("ERO Object is mandatory for PcInitiate message."); - } - - //PcepAttribute is optional - PcepAttribute pcepAttribute = listReq.getPcepAttribute(); - if (pcepAttribute != null) { - pcepAttribute.write(cb); - } - } - } - - // PCInitiate 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<PcInitiatedLspRequest> getPcInitiatedLspRequestList() { - return this.llPcInitiatedLspRequestList; - } - - @Override - public void setPcInitiatedLspRequestList(LinkedList<PcInitiatedLspRequest> ll) { - this.llPcInitiatedLspRequestList = ll; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("PcInitiaitedLspRequestList", llPcInitiatedLspRequestList) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepInterLayerObjectVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepInterLayerObjectVer1.java deleted file mode 100644 index 5130d9e9..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepInterLayerObjectVer1.java +++ /dev/null @@ -1,263 +0,0 @@ -/* - * 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.PcepInterLayerObject; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP inter layer object. - */ -public class PcepInterLayerObjectVer1 implements PcepInterLayerObject { - - /* - * 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 |N|I| - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - protected static final Logger log = LoggerFactory.getLogger(PcepInterLayerObjectVer1.class); - - public static final byte INTER_LAYER_OBJ_TYPE = 1; - public static final byte INTER_LAYER_OBJ_CLASS = 18; - public static final byte INTER_LAYER_OBJECT_VERSION = 1; - public static final short INTER_LAYER_OBJ_MINIMUM_LENGTH = 8; - public static final boolean DEFAULT_IFLAG = false; - public static final boolean DEFAULT_NFLAG = false; - public static final int OBJECT_HEADER_LENGTH = 4; - public static final int NFLAG_SHIFT_VALUE = 0x02; - public static final int IFLAG_SHIFT_VALUE = 0x01; - - static final PcepObjectHeader DEFAULT_INTER_LAYER_OBJECT_HEADER = new PcepObjectHeader(INTER_LAYER_OBJ_CLASS, - INTER_LAYER_OBJ_TYPE, PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, - INTER_LAYER_OBJ_MINIMUM_LENGTH); - - private PcepObjectHeader interLayerObjHeader; - private boolean bNFlag; - private boolean bIFlag; - - /** - * Constructor to initialize all parameters for Pcep Inter Layer Object. - * - * @param interLayerObjHeader inter layer object header - * @param bNFlag N flag - * @param bIFlag I flag - */ - public PcepInterLayerObjectVer1(PcepObjectHeader interLayerObjHeader, boolean bNFlag, boolean bIFlag) { - - this.interLayerObjHeader = interLayerObjHeader; - this.bNFlag = bNFlag; - this.bIFlag = bIFlag; - } - - /** - * Sets Object Header. - * - * @param obj object header - */ - public void setInterLayerObjHeader(PcepObjectHeader obj) { - this.interLayerObjHeader = obj; - } - - @Override - public void setbNFlag(boolean bNFlag) { - this.bNFlag = bNFlag; - } - - @Override - public void setbIFlag(boolean bIFlag) { - this.bIFlag = bIFlag; - } - - /** - * Returns object header. - * - * @return inter Layer Object Header - */ - public PcepObjectHeader getInterLayerObjHeader() { - return this.interLayerObjHeader; - } - - @Override - public boolean getbNFlag() { - return this.bNFlag; - } - - @Override - public boolean getbIFlag() { - return this.bIFlag; - } - - /** - * Reads channel buffer and returns object of PcepInterLayerObject. - * - * @param cb of type channel buffer - * @return object of PcepInterLayerObject - * @throws PcepParseException when fails to read from channel buffer - */ - public static PcepInterLayerObject read(ChannelBuffer cb) throws PcepParseException { - - PcepObjectHeader interLayerObjHeader; - boolean bNFlag; - boolean bIFlag; - - interLayerObjHeader = PcepObjectHeader.read(cb); - - //take only InterLayerObject buffer. - ChannelBuffer tempCb = cb.readBytes(interLayerObjHeader.getObjLen() - OBJECT_HEADER_LENGTH); - - int iTemp = tempCb.readInt(); - bIFlag = ((iTemp & (byte) IFLAG_SHIFT_VALUE) == IFLAG_SHIFT_VALUE); - bNFlag = ((iTemp & (byte) NFLAG_SHIFT_VALUE) == NFLAG_SHIFT_VALUE); - - return new PcepInterLayerObjectVer1(interLayerObjHeader, bNFlag, bIFlag); - } - - @Override - public int write(ChannelBuffer cb) throws PcepParseException { - - //write Object header - int objStartIndex = cb.writerIndex(); - - int objLenIndex = interLayerObjHeader.write(cb); - - if (objLenIndex <= 0) { - throw new PcepParseException(" ObjectLength Index is " + objLenIndex); - } - - int iTemp = 0; - - if (bIFlag) { - iTemp = iTemp | (byte) IFLAG_SHIFT_VALUE; - } - if (bNFlag) { - iTemp = iTemp | (byte) NFLAG_SHIFT_VALUE; - } - - cb.writeInt(iTemp); - - //Update object length now - int length = cb.writerIndex() - objStartIndex; - //will be helpful during print(). - interLayerObjHeader.setObjLen((short) length); - cb.setShort(objLenIndex, (short) length); - - objLenIndex = cb.writerIndex(); - return objLenIndex; - } - - /** - * Builder class for PCEP inter layer object. - */ - public static class Builder implements PcepInterLayerObject.Builder { - - private boolean bIsHeaderSet = false; - private boolean bIsNFlagset = false; - private boolean bIsIFlagset = false; - - private PcepObjectHeader interLayerObjHeader; - private boolean bNFlag; - private boolean bIFlag; - - private boolean bIsPFlagSet = false; - private boolean bPFalg; - - private boolean bIsIFlagSet = false; - private boolean iFlag; - - @Override - public PcepInterLayerObject build() { - PcepObjectHeader interLayerObjHeader = this.bIsHeaderSet ? this.interLayerObjHeader - : DEFAULT_INTER_LAYER_OBJECT_HEADER; - - boolean bNFlag = this.bIsNFlagset ? this.bNFlag : DEFAULT_NFLAG; - boolean bIFlag = this.bIsIFlagset ? this.bIFlag : DEFAULT_IFLAG; - - if (bIsPFlagSet) { - interLayerObjHeader.setPFlag(bPFalg); - } - - if (bIsIFlagSet) { - interLayerObjHeader.setIFlag(iFlag); - } - return new PcepInterLayerObjectVer1(interLayerObjHeader, bNFlag, bIFlag); - } - - @Override - public PcepObjectHeader getInterLayerObjHeader() { - return this.interLayerObjHeader; - } - - @Override - public Builder setInterLayerObjHeader(PcepObjectHeader obj) { - this.interLayerObjHeader = obj; - this.bIsHeaderSet = true; - return this; - } - - @Override - public boolean getbNFlag() { - return this.bNFlag; - } - - @Override - public Builder setbNFlag(boolean value) { - this.bNFlag = value; - this.bIsNFlagset = true; - return this; - } - - @Override - public boolean getbIFlag() { - return this.bIFlag; - } - - @Override - public Builder setbIFlag(boolean value) { - this.bIFlag = value; - this.bIsIFlagset = true; - return this; - } - - @Override - public Builder setPFlag(boolean value) { - this.bPFalg = value; - this.bIsPFlagSet = true; - return this; - } - - @Override - public Builder setIFlag(boolean value) { - this.iFlag = value; - this.bIsIFlagSet = true; - return this; - } - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("IFlag", bIFlag) - .add("NFlag", bNFlag).toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepIroObjectVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepIroObjectVer1.java deleted file mode 100644 index 2e01bdaa..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepIroObjectVer1.java +++ /dev/null @@ -1,299 +0,0 @@ -/* - * 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.PcepIroObject; -import org.onosproject.pcepio.types.IPv4SubObject; -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; - -/** - * Provides PCEP iro object. - */ -public class PcepIroObjectVer1 implements PcepIroObject { - - /* - 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 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | | - // (Sub-objects) // - | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - The IRO Object format - - Each IPV4 suboject - - 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 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - |L| Type | Length | IPv4 address (4 bytes) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | IPv4 address (continued) | Prefix Length | Resvd | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - protected static final Logger log = LoggerFactory.getLogger(PcepIroObjectVer1.class); - - public static final byte IRO_OBJ_TYPE = 1; - public static final byte IRO_OBJ_CLASS = 10; - public static final byte IRO_OBJECT_VERSION = 1; - public static final short IRO_OBJ_MINIMUM_LENGTH = 12; - public static final int OBJECT_HEADER_LENGTH = 4; - public static final int YTYPE_SHIFT_VALUE = 0x7F; - - public static final PcepObjectHeader DEFAULT_IRO_OBJECT_HEADER = new PcepObjectHeader(IRO_OBJ_CLASS, IRO_OBJ_TYPE, - PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, IRO_OBJ_MINIMUM_LENGTH); - - private short iroObjType = 0; - private byte yLength; - private byte yPrefixLength; - private byte yResvd; - private PcepObjectHeader iroObjHeader; - private LinkedList<PcepValueType> llSubObjects = new LinkedList<>(); - - /** - * Default constructor. - */ - public PcepIroObjectVer1() { - this.iroObjHeader = null; - this.iroObjType = 0; - this.yLength = 0; - } - - /** - * Constructor to initialize member variables. - * - * @param iroObjHeader IRO object header - * @param llSubObjects list of sub-objects - */ - public PcepIroObjectVer1(PcepObjectHeader iroObjHeader, LinkedList<PcepValueType> llSubObjects) { - this.iroObjHeader = iroObjHeader; - this.llSubObjects = llSubObjects; - } - - /** - * Returns object header. - * - * @return iroObjHeader IRO object header - */ - public PcepObjectHeader getIroObjHeader() { - return this.iroObjHeader; - } - - /** - * Sets IRO Object Header. - * - * @param obj IRO object header - */ - public void setIroObjHeader(PcepObjectHeader obj) { - this.iroObjHeader = obj; - } - - @Override - public LinkedList<PcepValueType> getSubObjects() { - return this.llSubObjects; - } - - @Override - public void setSubObjects(LinkedList<PcepValueType> llSubObjects) { - this.llSubObjects = llSubObjects; - } - - /** - * Reads from channel buffer and return object of PcepIroObject. - * - * @param cb of type channel buffer - * @return object of PcepIroObject - * @throws PcepParseException while parsing from channel buffer - */ - public static PcepIroObject read(ChannelBuffer cb) throws PcepParseException { - - PcepObjectHeader iroObjHeader; - LinkedList<PcepValueType> llSubObjects; - - iroObjHeader = PcepObjectHeader.read(cb); - - //take only IroObject buffer. - ChannelBuffer tempCb = cb.readBytes(iroObjHeader.getObjLen() - OBJECT_HEADER_LENGTH); - llSubObjects = parseSubObjects(tempCb); - return new PcepIroObjectVer1(iroObjHeader, llSubObjects); - } - - /** - * Returns linked list of sub objects. - * - * @param cb of type channel buffer - * @return linked list of sub objects - * @throws PcepParseException while parsing subobjects from channel buffer - */ - protected static LinkedList<PcepValueType> parseSubObjects(ChannelBuffer cb) throws PcepParseException { - - LinkedList<PcepValueType> llSubObjects = new LinkedList<>(); - - while (0 < cb.readableBytes()) { - - //check the Type of the Subobjects. - byte yType = cb.readByte(); - yType = (byte) (yType & (YTYPE_SHIFT_VALUE)); - byte hLength = cb.readByte(); - - PcepValueType subObj; - switch (yType) { - - case IPv4SubObject.TYPE: - subObj = IPv4SubObject.read(cb); - break; - - default: - throw new PcepParseException("Invalid sub object. Type: " + (int) yType); - } - - // Check for the padding - int pad = hLength % 4; - if (0 < pad) { - pad = 4 - pad; - if (pad <= cb.readableBytes()) { - cb.skipBytes(pad); - } - } - llSubObjects.add(subObj); - } - return llSubObjects; - } - - @Override - public int write(ChannelBuffer cb) throws PcepParseException { - //write Object header - int objStartIndex = cb.writerIndex(); - - int objLenIndex = iroObjHeader.write(cb); - - if (objLenIndex <= 0) { - throw new PcepParseException(" ObjectLength is " + objLenIndex); - } - - ListIterator<PcepValueType> listIterator = llSubObjects.listIterator(); - while (listIterator.hasNext()) { - listIterator.next().write(cb); - } - - //Update object length now - int length = cb.writerIndex() - objStartIndex; - //will be helpful during print(). - iroObjHeader.setObjLen((short) length); - // As per RFC the length of object should be - // multiples of 4 - int pad = length % 4; - if (pad != 0) { - pad = 4 - pad; - for (int i = 0; i < pad; i++) { - cb.writeByte((byte) 0); - } - length = length + pad; - } - cb.setShort(objLenIndex, (short) length); - objLenIndex = cb.writerIndex(); - return objLenIndex; - } - - /** - * Builder class for PCEP iro object. - */ - public static class Builder implements PcepIroObject.Builder { - - private boolean bIsHeaderSet = false; - - private PcepObjectHeader iroObjHeader; - LinkedList<PcepValueType> llSubObjects = new LinkedList<>(); - - private boolean bIsPFlagSet = false; - private boolean bPFlag; - - private boolean bIsIFlagSet = false; - private boolean bIFlag; - - @Override - public PcepIroObject build() { - - PcepObjectHeader iroObjHeader = this.bIsHeaderSet ? this.iroObjHeader : DEFAULT_IRO_OBJECT_HEADER; - - if (bIsPFlagSet) { - iroObjHeader.setPFlag(bPFlag); - } - - if (bIsIFlagSet) { - iroObjHeader.setIFlag(bIFlag); - } - - return new PcepIroObjectVer1(iroObjHeader, this.llSubObjects); - } - - @Override - public PcepObjectHeader getIroObjHeader() { - return this.iroObjHeader; - } - - @Override - public Builder setIroObjHeader(PcepObjectHeader obj) { - this.iroObjHeader = obj; - this.bIsHeaderSet = true; - return this; - } - - @Override - public LinkedList<PcepValueType> getSubObjects() { - return this.llSubObjects; - } - - @Override - public Builder setSubObjects(LinkedList<PcepValueType> llSubObjects) { - this.llSubObjects = llSubObjects; - 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("IroObjectHeader", iroObjHeader) - .add("SubObjects", llSubObjects).toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepKeepaliveMsgVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepKeepaliveMsgVer1.java deleted file mode 100644 index 8b6e9382..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepKeepaliveMsgVer1.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * 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.PcepKeepaliveMsg; -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; - -/** - * Provides PCEP keep alive message. - */ -class PcepKeepaliveMsgVer1 implements PcepKeepaliveMsg { - - /* - <Keepalive Message>::= <Common Header> - - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Ver | Flags | Message-Type | Message-Length | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - - protected static final Logger log = LoggerFactory.getLogger(PcepKeepaliveMsgVer1.class); - // Pcep version: 1 - public static final byte PACKET_VERSION = 1; - public static final int PACKET_MINIMUM_LENGTH = 4; - public static final PcepType MSG_TYPE = PcepType.KEEP_ALIVE; - - public static final PcepKeepaliveMsgVer1.Reader READER = new Reader(); - - /** - * Reader class for reading PCEP keepalive message from channel buffer. - */ - static class Reader implements PcepMessageReader<PcepKeepaliveMsg> { - - @Override - public PcepKeepaliveMsg readFrom(ChannelBuffer cb) throws PcepParseException { - - if (cb.readableBytes() < PACKET_MINIMUM_LENGTH) { - throw new PcepParseException("Packet size is less than the minimum required 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.KEEP_ALIVE_1(2), got=" + version); - } - // fixed value property type == 2 - byte type = cb.readByte(); - if (type != MSG_TYPE.getType()) { - throw new PcepParseException("Wrong type: Expected=PcepType.KEEP_ALIVE_1(2), got=" + type); - } - short length = cb.readShort(); - if (length < PACKET_MINIMUM_LENGTH) { - throw new PcepParseException("Wrong length: Expected to be >= " + PACKET_MINIMUM_LENGTH + ", was: " - + length); - } - return new PcepKeepaliveMsgVer1(); - } - } - - /** - * Default constructor. - */ - PcepKeepaliveMsgVer1() { - } - - /** - * Builder class for PCEP keepalive message. - */ - static class Builder implements PcepKeepaliveMsg.Builder { - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public PcepType getType() { - return PcepType.KEEP_ALIVE; - } - - @Override - public PcepKeepaliveMsg build() { - return new PcepKeepaliveMsgVer1(); - } - } - - @Override - public void writeTo(ChannelBuffer cb) { - WRITER.write(cb, this); - } - - static final Writer WRITER = new Writer(); - - /** - * Writer class for writing the PCEP keepalive message to channel buffer. - */ - static class Writer implements PcepMessageWriter<PcepKeepaliveMsgVer1> { - - @Override - public void write(ChannelBuffer cb, PcepKeepaliveMsgVer1 message) { - int startIndex = cb.writerIndex(); - // first 3 bits set to version - cb.writeByte((byte) (PACKET_VERSION << PcepMessageVer1.SHIFT_FLAG)); - // message type - cb.writeByte(MSG_TYPE.getType()); - // length is length of variable message, will be updated at the end - // Store the position of message - // length in buffer - int msgLenIndex = cb.writerIndex(); - cb.writeShort((short) 0); - // 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 String toString() { - return MoreObjects.toStringHelper(getClass()).toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelObjectVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelObjectVer1.java deleted file mode 100644 index a4ac87c3..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelObjectVer1.java +++ /dev/null @@ -1,370 +0,0 @@ -/* - * 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; - -/** - * Provides PCEP label object. - */ -public class PcepLabelObjectVer1 implements PcepLabelObject { - - /* - * 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 - */ - 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<>(); - 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; - 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<>(); - - 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 (tlv == null) { - 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<>(); - - 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/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelRangeObjectVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelRangeObjectVer1.java deleted file mode 100644 index 9e4be911..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelRangeObjectVer1.java +++ /dev/null @@ -1,377 +0,0 @@ -/* - * 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.PcepLabelRangeObject; -import org.onosproject.pcepio.types.PathSetupTypeTlv; -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; - -/** - * Provides PCEP label range object. - */ -public class PcepLabelRangeObjectVer1 implements PcepLabelRangeObject { - - /* - * ref : draft-zhao-pce-pcep-extension-for-pce-controller-01, section : 7.2 - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | label type | range size | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | label base | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | | - // Optional TLVs // - | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - LABEL-RANGE Object - */ - protected static final Logger log = LoggerFactory.getLogger(PcepLabelRangeObjectVer1.class); - - public static final byte LABEL_RANGE_OBJ_TYPE = 1; - public static final byte LABEL_RANGE_OBJ_CLASS = 60; //to be defined - public static final byte LABEL_RANGE_OBJECT_VERSION = 1; - public static final short LABEL_RANGE_OBJ_MINIMUM_LENGTH = 12; - public static final int MINIMUM_COMMON_HEADER_LENGTH = 4; - //P flag and I flag must be set to 0 - static final PcepObjectHeader DEFAULT_LABELRANGE_OBJECT_HEADER = new PcepObjectHeader(LABEL_RANGE_OBJ_CLASS, - LABEL_RANGE_OBJ_TYPE, PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, - LABEL_RANGE_OBJ_MINIMUM_LENGTH); - - private PcepObjectHeader labelRangeObjHeader; - private byte labelType; - private int rangeSize; - private int labelBase; - //Optional TLV - private LinkedList<PcepValueType> llOptionalTlv; - - /** - * Constructor to initialize parameters for PCEP label range object. - * - * @param labelRangeObjHeader label range object header - * @param labelType label type - * @param rangeSize range size - * @param labelBase label base - * @param llOptionalTlv list of optional tlvs - */ - public PcepLabelRangeObjectVer1(PcepObjectHeader labelRangeObjHeader, byte labelType, int rangeSize, int labelBase, - LinkedList<PcepValueType> llOptionalTlv) { - this.labelRangeObjHeader = labelRangeObjHeader; - this.labelType = labelType; - this.rangeSize = rangeSize; - this.llOptionalTlv = llOptionalTlv; - this.labelBase = labelBase; - } - - @Override - public void setLabelRangeObjHeader(PcepObjectHeader obj) { - this.labelRangeObjHeader = obj; - } - - @Override - public void setLabelType(byte labelType) { - this.labelType = labelType; - } - - @Override - public void setRangeSize(int rangeSize) { - this.rangeSize = rangeSize; - } - - @Override - public void setLabelBase(int labelBase) { - this.labelBase = labelBase; - } - - @Override - public PcepObjectHeader getLabelRangeObjHeader() { - return this.labelRangeObjHeader; - } - - @Override - public byte getLabelType() { - return this.labelType; - } - - @Override - public int getRangeSize() { - return this.rangeSize; - } - - @Override - public int getLabelBase() { - return this.labelBase; - } - - /** - * Reads from the channel buffer and returns object of PcepLabelRangeObject. - * - * @param cb of type channel buffer - * @return object of PcepLabelRangeObject - * @throws PcepParseException when fails to read from channel buffer - */ - public static PcepLabelRangeObject read(ChannelBuffer cb) throws PcepParseException { - - PcepObjectHeader labelRangeObjHeader; - byte labelType; - int rangeSize; - int labelBase; - - LinkedList<PcepValueType> llOptionalTlv = new LinkedList<>(); - - labelRangeObjHeader = PcepObjectHeader.read(cb); - - //take only LabelRangeObject buffer. - ChannelBuffer tempCb = cb.readBytes(labelRangeObjHeader.getObjLen() - MINIMUM_COMMON_HEADER_LENGTH); - int temp = 0; - temp = tempCb.readInt(); - rangeSize = temp & 0x00FFFFFF; - labelType = (byte) (temp >> 24); - labelBase = tempCb.readInt(); - llOptionalTlv = parseOptionalTlv(tempCb); - return new PcepLabelRangeObjectVer1(labelRangeObjHeader, labelType, rangeSize, labelBase, llOptionalTlv); - } - - @Override - public int write(ChannelBuffer cb) throws PcepParseException { - - int objStartIndex = cb.writerIndex(); - - //write common header - int objLenIndex = labelRangeObjHeader.write(cb); - int temp = 0; - temp = labelType; - temp = temp << 24; - temp = temp | rangeSize; - cb.writeInt(temp); - - // Add optional TLV - if (!packOptionalTlv(cb)) { - throw new PcepParseException("Error while writing Optional tlv."); - } - - //now write LabelRange Object Length - cb.setShort(objLenIndex, (short) (cb.writerIndex() - objStartIndex)); - return cb.writerIndex() - objStartIndex; - } - - /** - * Returns list of optional tlvs. - * - * @param cb of type channle buffer - * @return list of optional tlvs - * @throws PcepParseException whne fails to parse list of optional tlvs - */ - public static LinkedList<PcepValueType> parseOptionalTlv(ChannelBuffer cb) throws PcepParseException { - - LinkedList<PcepValueType> llOutOptionalTlv = new LinkedList<>(); - - while (MINIMUM_COMMON_HEADER_LENGTH <= cb.readableBytes()) { - - PcepValueType tlv; - int iValue; - short hType = cb.readShort(); - short hLength = cb.readShort(); - - switch (hType) { - - case PathSetupTypeTlv.TYPE: - iValue = cb.readInt(); - tlv = new PathSetupTypeTlv(iValue); - break; - - default: - throw new PcepParseException("Unsupported TLV in LabelRange Object."); - } - - // Check for the padding - int pad = hLength % 4; - if (0 < pad) { - pad = 4 - pad; - if (pad <= cb.readableBytes()) { - cb.skipBytes(pad); - } - } - llOutOptionalTlv.add(tlv); - } - return llOutOptionalTlv; - } - - /** - * Pack optional tlvs. - * - * @param cb of channel buffer - * @return true - */ - protected boolean packOptionalTlv(ChannelBuffer cb) { - - ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator(); - - while (listIterator.hasNext()) { - PcepValueType tlv = listIterator.next(); - - if (tlv == null) { - log.debug("tlv is null from OptionalTlv list"); - continue; - } - tlv.write(cb); - - // need to take care of padding - int pad = tlv.getLength() % 4; - if (0 != pad) { - pad = 4 - pad; - for (int i = 0; i < pad; ++i) { - cb.writeByte((byte) 0); - } - } - } - return true; - } - - /** - * Builder class for PCEP label range object. - */ - public static class Builder implements PcepLabelRangeObject.Builder { - private boolean bIsHeaderSet = false; - private boolean bIsLabelType = false; - private boolean bIsRangeSize = false; - private boolean bIsLabelBase = false; - - byte labelType; - int rangeSize; - int labelBase; - private boolean bIsPFlagSet = false; - private boolean bPFlag; - - private boolean bIsIFlagSet = false; - private boolean bIFlag; - private PcepObjectHeader labelRangeObjHeader; - - LinkedList<PcepValueType> llOptionalTlv = new LinkedList<>(); - - @Override - public PcepLabelRangeObject build() throws PcepParseException { - PcepObjectHeader labelRangeObjHeader = this.bIsHeaderSet ? this.labelRangeObjHeader - : DEFAULT_LABELRANGE_OBJECT_HEADER; - - if (!this.bIsLabelType) { - throw new PcepParseException("LabelType NOT Set while building label range object."); - } - - if (!this.bIsRangeSize) { - throw new PcepParseException("RangeSize NOT Set while building label range object."); - } - - if (!this.bIsLabelBase) { - throw new PcepParseException("LabelBase NOT Set while building label range object."); - } - - if (bIsPFlagSet) { - labelRangeObjHeader.setPFlag(bPFlag); - } - - if (bIsIFlagSet) { - labelRangeObjHeader.setIFlag(bIFlag); - } - return new PcepLabelRangeObjectVer1(labelRangeObjHeader, this.labelType, this.rangeSize, this.labelBase, - this.llOptionalTlv); - } - - @Override - public PcepObjectHeader getLabelRangeObjHeader() { - return this.labelRangeObjHeader; - } - - @Override - public Builder setLabelRangeObjHeader(PcepObjectHeader obj) { - this.labelRangeObjHeader = obj; - this.bIsHeaderSet = true; - return this; - } - - @Override - public byte getLabelType() { - return this.labelType; - } - - @Override - public Builder setLabelType(byte labelType) { - this.labelType = labelType; - this.bIsLabelType = true; - return this; - } - - @Override - public int getRangeSize() { - return this.rangeSize; - } - - @Override - public Builder setRangeSize(int rangeSize) { - this.rangeSize = rangeSize; - this.bIsRangeSize = true; - return this; - } - - @Override - public int getLabelBase() { - return this.labelBase; - } - - @Override - public Builder setLabelBase(int labelBase) { - this.labelBase = labelBase; - this.bIsLabelBase = true; - 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("LabelType", labelType) - .add("rangeSize", rangeSize) - .add("labelBase", labelBase) - .add("optionalTlvList", llOptionalTlv) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelRangeResvMsgVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelRangeResvMsgVer1.java deleted file mode 100644 index 6f3648af..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelRangeResvMsgVer1.java +++ /dev/null @@ -1,198 +0,0 @@ -/* - * 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.PcepLabelRange; -import org.onosproject.pcepio.protocol.PcepLabelRangeResvMsg; -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; - -/** - * Provides PCEP label range reserve message. - */ -class PcepLabelRangeResvMsgVer1 implements PcepLabelRangeResvMsg { - - // Pcep version: 1 - - /* - The format of a PCLRResv message is as follows: - - PCLRResv Message>::= <Common Header> - <label-range> - Where: - - <label-range> ::= <SRP> - <labelrange-list> - - Where - <labelrange-list>::=<LABEL-RANGE>[<labelrange-list>] - */ - protected static final Logger log = LoggerFactory.getLogger(PcepLabelRangeResvMsgVer1.class); - - public static final byte PACKET_VERSION = 1; - // LabelRangeResvMsgMinLength = COMMON-HEADER(4)+SrpObjMinLentgh(12)+LABEL-RANGE-MIN-LENGTH(12) - public static final int PACKET_MINIMUM_LENGTH = 28; - public static final PcepType MSG_TYPE = PcepType.LABEL_RANGE_RESERV; - //<label-range> - PcepLabelRange labelRange; - - public static final PcepLabelRangeResvMsgVer1.Reader READER = new Reader(); - - /** - * Reader reads LabelRangeResv Message from the channel. - */ - static class Reader implements PcepMessageReader<PcepLabelRangeResvMsg> { - - @Override - public PcepLabelRangeResvMsg readFrom(ChannelBuffer cb) throws PcepParseException { - - if (cb.readableBytes() < PACKET_MINIMUM_LENGTH) { - throw new PcepParseException("Channel buffer has less readable bytes 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 == 15 - byte type = cb.readByte(); - if (type != MSG_TYPE.getType()) { - throw new PcepParseException("Wrong type. Expected=PcepType.LABEL_RANGE_RESERV(15), 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 <label-range> - PcepLabelRange labelRange = PcepLabelRangeVer1.read(cb); - return new PcepLabelRangeResvMsgVer1(labelRange); - } - } - - /** - * Constructor to initialize PCEP label range. - * - * @param labelRange PCEP label range - */ - PcepLabelRangeResvMsgVer1(PcepLabelRange labelRange) { - this.labelRange = labelRange; - } - - /** - * Builder class for PCEP label range reserve message. - */ - static class Builder implements PcepLabelRangeResvMsg.Builder { - - PcepLabelRange labelRange = new PcepLabelRangeVer1(); - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public PcepType getType() { - return PcepType.LABEL_RANGE_RESERV; - } - - @Override - public PcepLabelRangeResvMsg build() { - return new PcepLabelRangeResvMsgVer1(this.labelRange); - } - - @Override - public PcepLabelRange getLabelRange() { - return this.labelRange; - } - - @Override - public Builder setLabelRange(PcepLabelRange labelRange) { - this.labelRange = labelRange; - return this; - } - } - - @Override - public void writeTo(ChannelBuffer cb) throws PcepParseException { - WRITER.write(cb, this); - } - - static final Writer WRITER = new Writer(); - - /** - * Writer writes LabelRangeResv Message to the channel. - */ - static class Writer implements PcepMessageWriter<PcepLabelRangeResvMsgVer1> { - - @Override - public void write(ChannelBuffer cb, PcepLabelRangeResvMsgVer1 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); - //write Label Range - message.labelRange.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 PcepLabelRange getLabelRange() { - return this.labelRange; - } - - @Override - public void setLabelRange(PcepLabelRange lr) { - this.labelRange = lr; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("labelRange", labelRange) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelRangeVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelRangeVer1.java deleted file mode 100644 index 411c9604..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelRangeVer1.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * 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.PcepLabelRange; -import org.onosproject.pcepio.protocol.PcepLabelRangeObject; -import org.onosproject.pcepio.protocol.PcepSrpObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP Label Range. - */ -public class PcepLabelRangeVer1 implements PcepLabelRange { - - protected static final Logger log = LoggerFactory.getLogger(PcepLabelRangeVer1.class); - - /* - <label-range> ::= <SRP> - <labelrange-list> - Where - <labelrange-list>::=<LABEL-RANGE>[<labelrange-list>] - */ - - // PCEP SRP Object - private PcepSrpObject srpObject; - //<labelrange-list> of type PcepLabelRangeObject. - private LinkedList<PcepLabelRangeObject> llLabelRangeList; - - /** - * Default Constructor. - */ - public PcepLabelRangeVer1() { - srpObject = null; - llLabelRangeList = null; - } - - /** - * Constructor to initialize objects. - * - * @param srpObj PCEP Srp object. - * @param llLabelRangeList list of PcepLabelRangeObject. - */ - PcepLabelRangeVer1(PcepSrpObject srpObj, LinkedList<PcepLabelRangeObject> llLabelRangeList) { - this.srpObject = srpObj; - this.llLabelRangeList = llLabelRangeList; - } - - @Override - public PcepSrpObject getSrpObject() { - return srpObject; - } - - @Override - public void setSrpObject(PcepSrpObject srpObject) { - this.srpObject = srpObject; - - } - - @Override - public LinkedList<PcepLabelRangeObject> getLabelRangeList() { - return llLabelRangeList; - } - - @Override - public void setLabelRangeList(LinkedList<PcepLabelRangeObject> ll) { - this.llLabelRangeList = ll; - } - - /** - * Reads channel buffer and returns object of PcepLabelRange. - * - * @param cb of type channel buffer. - * @return object of PcepLabelRange - * @throws PcepParseException when fails to read from channel buffer - */ - public static PcepLabelRange read(ChannelBuffer cb) throws PcepParseException { - - //parse and store SRP mandatory object - PcepSrpObject srpObj = null; - srpObj = PcepSrpObjectVer1.read(cb); - if (srpObj == null) { - throw new PcepParseException("Exception while parsing srp object"); - } - - LinkedList<PcepLabelRangeObject> llLabelRangeList = new LinkedList<>(); - boolean bFoundLabelRangeObj = false; - while (0 < cb.readableBytes()) { - //parse and store <labelrange-list> - PcepLabelRangeObject lrObj; - lrObj = PcepLabelRangeObjectVer1.read(cb); - if (lrObj == null) { - throw new PcepParseException("Exception while parsing label range object"); - } else { - llLabelRangeList.add(lrObj); - bFoundLabelRangeObj = true; - } - } - - if (!bFoundLabelRangeObj) { - throw new PcepParseException("At least one LABEL-RANGE MUST be present."); - } - return new PcepLabelRangeVer1(srpObj, llLabelRangeList); - } - - @Override - public int write(ChannelBuffer cb) throws PcepParseException { - //write Object header - int objStartIndex = cb.writerIndex(); - - //write <SRP> - int objLenIndex = srpObject.write(cb); - - if (objLenIndex <= 0) { - throw new PcepParseException("bjectLength is " + objLenIndex); - } - - //write <labelrange-list> - ListIterator<PcepLabelRangeObject> listIterator = llLabelRangeList.listIterator(); - while (listIterator.hasNext()) { - listIterator.next().write(cb); - } - - //Update object length now - int length = cb.writerIndex() - objStartIndex; - // As per RFC the length of object should be - // multiples of 4 - int pad = length % 4; - if (pad != 0) { - pad = 4 - pad; - for (int i = 0; i < pad; i++) { - cb.writeByte((byte) 0); - } - length = length + pad; - } - cb.setShort(objLenIndex, (short) length); - return length; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("srpObject", srpObject) - .add("LabelRangeList", llLabelRangeList) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelUpdateMsgVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelUpdateMsgVer1.java deleted file mode 100644 index 89347f42..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelUpdateMsgVer1.java +++ /dev/null @@ -1,239 +0,0 @@ -/* - * 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; - -/** - * Provides PCEP lable update message. - */ -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<>(); - - 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; - } - - /** - * Builder class for PCEP label update message. - */ - 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/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelUpdateVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelUpdateVer1.java deleted file mode 100644 index a2293d35..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelUpdateVer1.java +++ /dev/null @@ -1,356 +0,0 @@ -/* - * 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; - -/** - * 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 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() { - return MoreObjects.toStringHelper(getClass()) - .omitNullValues() - .add("LabelDownload", labelDownload) - .add("LabelMap", labelMap) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLspObjectVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLspObjectVer1.java deleted file mode 100644 index 2b319c12..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLspObjectVer1.java +++ /dev/null @@ -1,575 +0,0 @@ -/* - * 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.PcepLspObject; -import org.onosproject.pcepio.types.PcepErrorDetailInfo; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.onosproject.pcepio.types.PcepValueType; -import org.onosproject.pcepio.types.StatefulIPv4LspIdentidiersTlv; -import org.onosproject.pcepio.types.StatefulLspDbVerTlv; -import org.onosproject.pcepio.types.StatefulLspErrorCodeTlv; -import org.onosproject.pcepio.types.StatefulRsvpErrorSpecTlv; -import org.onosproject.pcepio.types.SymbolicPathNameTlv; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP lsp object. - */ -public class PcepLspObjectVer1 implements PcepLspObject { - - /* - message format. - Reference : draft-ietf-pce-stateful-pce-11, section 7.3. - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Object-Class | OT |Res|P|I| Object Length (bytes) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | PLSP-ID | Flag | O|A|R|S|D| - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // TLVs // - | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - The LSP Object format - */ - protected static final Logger log = LoggerFactory.getLogger(PcepLspObjectVer1.class); - - public static final byte LSP_OBJ_TYPE = 1; - public static final byte LSP_OBJ_CLASS = 32; - public static final byte LSP_OBJECT_VERSION = 1; - - // LSP_OBJ_MINIMUM_LENGTH = CommonHeaderLen(4)+ LspObjectHeaderLen(4)+TlvAssumedMinLength(8) - public static final short LSP_OBJ_MINIMUM_LENGTH = 16; - - public static final int DEFAULT_PLSPID = 0; - public static final byte DEFAULT_OFLAG = 1; - public static final boolean DEFAULT_AFLAG = false; - public static final boolean DEFAULT_RFLAG = false; - public static final boolean DEFAULT_SFLAG = false; - public static final boolean DEFAULT_DFLAG = false; - public static final int OBJECT_HEADER_LENGTH = 4; - public static final int PLSPID_SHIFT_VALUE = 12; - public static final int OFLAG_SHIFT_VALUE = 4; - public static final int AFLAG_SHIFT_VALUE = 3; - public static final int RFLAG_SHIFT_VALUE = 2; - public static final int SFLAG_SHIFT_VALUE = 1; - public static final int PLSPID_TEMP_SHIFT_VALUE = 0xFFFFF000; - public static final int OFLAG_TEMP_SHIFT_VALUE = 0x70; - public static final int AFLAG_TEMP_SHIFT_VALUE = 0x08; - public static final int RFLAG_TEMP_SHIFT_VALUE = 0x04; - public static final int SFLAG_TEMP_SHIFT_VALUE = 0x02; - public static final int DFLAG_TEMP_SHIFT_VALUE = 0x01; - public static final int BIT_SET = 1; - public static final int BIT_RESET = 0; - public static final int MINIMUM_COMMON_HEADER_LENGTH = 4; - - static final PcepObjectHeader DEFAULT_LSP_OBJECT_HEADER = new PcepObjectHeader(LSP_OBJ_CLASS, LSP_OBJ_TYPE, - PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, LSP_OBJ_MINIMUM_LENGTH); - - private PcepObjectHeader lspObjHeader; - private int iPlspId; - // 3-bits - private byte yOFlag; - private boolean bAFlag; - private boolean bRFlag; - private boolean bSFlag; - private boolean bDFlag; - - // Optional TLV - private LinkedList<PcepValueType> llOptionalTlv; - - /** - * Constructor to initialize all the member variables. - * - * @param lspObjHeader lsp object header - * @param iPlspId plsp id - * @param yOFlag O flag - * @param bAFlag A flag - * @param bRFlag R flag - * @param bSFlag S flag - * @param bDFlag D flag - * @param llOptionalTlv list of optional tlv - */ - public PcepLspObjectVer1(PcepObjectHeader lspObjHeader, int iPlspId, byte yOFlag, boolean bAFlag, boolean bRFlag, - boolean bSFlag, boolean bDFlag, LinkedList<PcepValueType> llOptionalTlv) { - - this.lspObjHeader = lspObjHeader; - this.iPlspId = iPlspId; - this.yOFlag = yOFlag; - this.bAFlag = bAFlag; - this.bRFlag = bRFlag; - this.bSFlag = bSFlag; - this.bDFlag = bDFlag; - this.llOptionalTlv = llOptionalTlv; - } - - /** - * Sets lsp Object Header. - * - * @param obj lsp object header - */ - public void setLspObjHeader(PcepObjectHeader obj) { - this.lspObjHeader = obj; - } - - @Override - public void setPlspId(int iPlspId) { - this.iPlspId = iPlspId; - } - - @Override - public void setOFlag(byte yOFlag) { - this.yOFlag = yOFlag; - } - - @Override - public void setAFlag(boolean bAFlag) { - this.bAFlag = bAFlag; - } - - @Override - public void setRFlag(boolean bRFlag) { - this.bRFlag = bRFlag; - } - - @Override - public void setSFlag(boolean bSFlag) { - this.bSFlag = bSFlag; - } - - @Override - public void setDFlag(boolean bDFlag) { - this.bDFlag = bDFlag; - } - - /** - * Returns lsp object header. - * - * @return lspObjHeader - */ - public PcepObjectHeader getLspObjHeader() { - return this.lspObjHeader; - } - - @Override - public int getPlspId() { - return this.iPlspId; - } - - @Override - public byte getOFlag() { - return this.yOFlag; - } - - @Override - public boolean getAFlag() { - return this.bAFlag; - } - - @Override - public boolean getRFlag() { - return this.bRFlag; - } - - @Override - public boolean getSFlag() { - return this.bSFlag; - } - - @Override - public boolean getDFlag() { - return this.bDFlag; - } - - @Override - public LinkedList<PcepValueType> getOptionalTlv() { - return this.llOptionalTlv; - } - - @Override - public void setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) { - this.llOptionalTlv = llOptionalTlv; - } - - /** - * Parse channel buffer and returns object of PcepLspObject. - * - * @param cb of type channel buffer - * @return object of PcepLspObject - * @throws PcepParseException when lsp object is not present in channel buffer - */ - public static PcepLspObject read(ChannelBuffer cb) throws PcepParseException { - - PcepObjectHeader lspObjHeader; - int iPlspId; - // 3-bits - byte yOFlag; - boolean bAFlag; - boolean bRFlag; - boolean bSFlag; - boolean bDFlag; - - // Optional TLV - LinkedList<PcepValueType> llOptionalTlv = new LinkedList<>(); - - lspObjHeader = PcepObjectHeader.read(cb); - - if (lspObjHeader.getObjClass() != PcepLspObjectVer1.LSP_OBJ_CLASS) { - throw new PcepParseException(PcepErrorDetailInfo.ERROR_TYPE_6, PcepErrorDetailInfo.ERROR_VALUE_8); - } - //take only LspObject buffer. - ChannelBuffer tempCb = cb.readBytes(lspObjHeader.getObjLen() - OBJECT_HEADER_LENGTH); - - Integer iTemp = tempCb.readInt(); - iPlspId = (iTemp & PLSPID_TEMP_SHIFT_VALUE) >> PLSPID_SHIFT_VALUE; - Integer iX = (iTemp & OFLAG_TEMP_SHIFT_VALUE) >> OFLAG_SHIFT_VALUE; - yOFlag = iX.byteValue(); - iX = (iTemp & AFLAG_TEMP_SHIFT_VALUE) >> AFLAG_SHIFT_VALUE; - bAFlag = iX > 0; - iX = (iTemp & RFLAG_TEMP_SHIFT_VALUE) >> RFLAG_SHIFT_VALUE; - bRFlag = iX > 0; - iX = (iTemp & SFLAG_TEMP_SHIFT_VALUE) >> SFLAG_SHIFT_VALUE; - bSFlag = iX > 0; - iX = iTemp & DFLAG_TEMP_SHIFT_VALUE; - bDFlag = iX > 0; - - // parse optional TLV - llOptionalTlv = parseOptionalTlv(tempCb); - - return new PcepLspObjectVer1(lspObjHeader, iPlspId, yOFlag, bAFlag, bRFlag, bSFlag, bDFlag, llOptionalTlv); - } - - @Override - public int write(ChannelBuffer cb) throws PcepParseException { - - //write Object header - int objStartIndex = cb.writerIndex(); - - int objLenIndex = lspObjHeader.write(cb); - - if (objLenIndex <= 0) { - throw new PcepParseException("Failed to write lsp object header. Index " + objLenIndex); - } - - int iTemp = iPlspId << PLSPID_SHIFT_VALUE; - iTemp = iTemp | (yOFlag << OFLAG_SHIFT_VALUE); - byte bFlag; - iTemp = bAFlag ? (iTemp | AFLAG_TEMP_SHIFT_VALUE) : iTemp; - - bFlag = (bRFlag) ? (byte) BIT_SET : BIT_RESET; - iTemp = iTemp | (bFlag << RFLAG_SHIFT_VALUE); - bFlag = (bSFlag) ? (byte) BIT_SET : BIT_RESET; - iTemp = iTemp | (bFlag << SFLAG_SHIFT_VALUE); - bFlag = (bDFlag) ? (byte) BIT_SET : BIT_RESET; - iTemp = iTemp | bFlag; - cb.writeInt(iTemp); - - // Add optional TLV - packOptionalTlv(cb); - - //Update object length now - int length = cb.writerIndex() - objStartIndex; - //will be helpful during print(). - lspObjHeader.setObjLen((short) length); - // As per RFC the length of object should be - // multiples of 4 - - cb.setShort(objLenIndex, (short) length); - - return length; - } - - /** - * Returns Linked list of optional tlvs. - * - * @param cb of channel buffer. - * @return list of optional tlvs - * @throws PcepParseException when unsupported tlv is received - */ - protected static LinkedList<PcepValueType> parseOptionalTlv(ChannelBuffer cb) throws PcepParseException { - - LinkedList<PcepValueType> llOutOptionalTlv; - - llOutOptionalTlv = new LinkedList<>(); - - while (MINIMUM_COMMON_HEADER_LENGTH <= cb.readableBytes()) { - - PcepValueType tlv; - short hType = cb.readShort(); - short hLength = cb.readShort(); - int iValue = 0; - - switch (hType) { - - case StatefulIPv4LspIdentidiersTlv.TYPE: - tlv = StatefulIPv4LspIdentidiersTlv.read(cb); - break; - case StatefulLspErrorCodeTlv.TYPE: - iValue = cb.readInt(); - tlv = new StatefulLspErrorCodeTlv(iValue); - break; - case StatefulRsvpErrorSpecTlv.TYPE: - tlv = StatefulRsvpErrorSpecTlv.read(cb); - break; - case SymbolicPathNameTlv.TYPE: - tlv = SymbolicPathNameTlv.read(cb, hLength); - break; - case StatefulLspDbVerTlv.TYPE: - tlv = StatefulLspDbVerTlv.read(cb); - break; - default: - throw new PcepParseException("Received 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 writer index. - * - * @param cb of type channel buffer - * @return length of bytes written to channel buffer - */ - protected int packOptionalTlv(ChannelBuffer cb) { - - ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator(); - int startIndex = cb.writerIndex(); - - while (listIterator.hasNext()) { - PcepValueType tlv = listIterator.next(); - - if (tlv == null) { - log.debug("tlv is null from OptionalTlv list"); - continue; - } - - tlv.write(cb); - - // need to take care of padding - int pad = tlv.getLength() % 4; - - if (0 != pad) { - pad = 4 - pad; - for (int i = 0; i < pad; ++i) { - cb.writeByte((byte) 0); - } - } - } - - return cb.writerIndex() - startIndex; - } - - /** - * Builder class for PCEP lsp Object. - */ - public static class Builder implements PcepLspObject.Builder { - - private boolean bIsHeaderSet = false; - private boolean bIsPlspIdSet = false; - private boolean bIsOFlagSet = false; - private boolean bIsRFlagSet = false; - private boolean bIsAFlagSet = false; - private boolean bIsDFlagSet = false; - private boolean bIsSFlagSet = false; - - private PcepObjectHeader lspObjHeader; - private byte yOFlag; - private boolean bAFlag; - private boolean bDFlag; - private boolean bSFlag; - private boolean bRFlag; - LinkedList<PcepValueType> llOptionalTlv = null; - - private int plspId; - - private boolean bIsPFlagSet = false; - private boolean bPFlag; - - private boolean bIsIFlagSet = false; - private boolean bIFlag; - - @Override - public PcepLspObject build() { - PcepObjectHeader lspObjHeader = this.bIsHeaderSet ? this.lspObjHeader : DEFAULT_LSP_OBJECT_HEADER; - - int plspId = this.bIsPlspIdSet ? this.plspId : DEFAULT_PLSPID; - byte yOFlag = this.bIsOFlagSet ? this.yOFlag : DEFAULT_OFLAG; - boolean bAFlag = this.bIsAFlagSet ? this.bAFlag : DEFAULT_AFLAG; - boolean bRFlag = this.bIsRFlagSet ? this.bRFlag : DEFAULT_RFLAG; - boolean bSFlag = this.bIsSFlagSet ? this.bSFlag : DEFAULT_SFLAG; - boolean bDFlag = this.bIsDFlagSet ? this.bDFlag : DEFAULT_DFLAG; - - if (bIsPFlagSet) { - lspObjHeader.setPFlag(bPFlag); - } - - if (bIsIFlagSet) { - lspObjHeader.setIFlag(bIFlag); - } - - return new PcepLspObjectVer1(lspObjHeader, plspId, yOFlag, bAFlag, bRFlag, bSFlag, bDFlag, llOptionalTlv); - } - - @Override - public PcepObjectHeader getLspObjHeader() { - return this.lspObjHeader; - } - - @Override - public Builder setLspObjHeader(PcepObjectHeader obj) { - this.lspObjHeader = obj; - this.bIsHeaderSet = true; - return this; - } - - @Override - public int getPlspId() { - return this.plspId; - } - - @Override - public Builder setPlspId(int value) { - this.plspId = value; - this.bIsPlspIdSet = true; - return this; - } - - @Override - public byte getOFlag() { - return this.yOFlag; - } - - @Override - public Builder setOFlag(byte value) { - this.yOFlag = value; - this.bIsOFlagSet = true; - return this; - } - - @Override - public boolean getAFlag() { - return this.bAFlag; - } - - @Override - public Builder setAFlag(boolean value) { - this.bAFlag = value; - this.bIsAFlagSet = true; - return this; - } - - @Override - public boolean getRFlag() { - return this.bRFlag; - } - - @Override - public Builder setRFlag(boolean value) { - this.bRFlag = value; - this.bIsRFlagSet = true; - return this; - } - - @Override - public boolean getSFlag() { - return this.bSFlag; - } - - @Override - public Builder setSFlag(boolean value) { - this.bSFlag = value; - this.bIsSFlagSet = true; - return this; - } - - @Override - public boolean getDFlag() { - return this.bDFlag; - } - - @Override - public Builder setDFlag(boolean value) { - this.bDFlag = value; - this.bIsDFlagSet = true; - return this; - } - - @Override - public Builder setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) { - this.llOptionalTlv = llOptionalTlv; - return this; - } - - @Override - public LinkedList<PcepValueType> getOptionalTlv() { - return this.llOptionalTlv; - } - - @Override - public Builder setPFlag(boolean value) { - this.bPFlag = value; - this.bIsPFlagSet = true; - return this; - } - - @Override - public Builder setIFlag(boolean value) { - this.bIFlag = value; - this.bIsIFlagSet = true; - return this; - } - - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("PlspIDValue", iPlspId) - .add("OFlag", yOFlag) - .add("AFlag", bAFlag) - .add("RFlag", bRFlag) - .add("SFlag", bSFlag) - .add("DFlag", bDFlag) - .add("OptionalTlvList", llOptionalTlv) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLspaObjectVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLspaObjectVer1.java deleted file mode 100644 index f4000509..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLspaObjectVer1.java +++ /dev/null @@ -1,529 +0,0 @@ -/* - * 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.PcepLspaObject; -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; - -/** - * Provides PCEP label Object . - */ -public class PcepLspaObjectVer1 implements PcepLspaObject { - - /* LSPA Object Body Format - - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Exclude-any | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Include-any | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Include-all | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Setup Prio | Holding Prio | Flags |L| Reserved | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | | - | Optional TLVs | - | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - - protected static final Logger log = LoggerFactory.getLogger(PcepLspaObjectVer1.class); - - public static final byte LSPA_OBJ_TYPE = 1; - public static final byte LSPA_OBJ_CLASS = 9; - public static final byte LSPA_OBJECT_VERSION = 1; - public static final short LSPA_OBJ_MINIMUM_LENGTH = 20; - public static final int OBJECT_HEADER_LENGTH = 4; - - static final PcepObjectHeader DEFAULT_LSPA_OBJECT_HEADER = new PcepObjectHeader(LSPA_OBJ_CLASS, LSPA_OBJ_TYPE, - PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, LSPA_OBJ_MINIMUM_LENGTH); - - public static final int SETUP_PRIORITY_SHIFT_VALUE = 24; - public static final int HOLD_PRIORITY_SHIFT_VALUE = 16; - public static final int BFLAG_SHIFT_VALUE = 8; - public static final int LFLAG_SET = 1; - public static final int LFLAG_RESET = 0; - private PcepObjectHeader lspaObjHeader; - private int iExcludeAny; - private int iIncludeAny; - private int iIncludeAll; - private byte cSetupPriority; - private byte cHoldPriority; - private boolean bLFlag; - private LinkedList<PcepValueType> llOptionalTlv; //Optional TLV - - /** - * Constructor to initialize member variables. - * - * @param lspaObjHeader lspa object header - * @param bLFlag b l flag - * @param iExcludeAny excludeAny value - * @param iIncludeAny includeAny value - * @param iIncludeAll includeAll value - * @param cSetupPriority setup priority value - * @param cHoldPriority hold priority value - * @param llOptionalTlv list of optional tlv - */ - public PcepLspaObjectVer1(PcepObjectHeader lspaObjHeader, boolean bLFlag, int iExcludeAny, int iIncludeAny, - int iIncludeAll, byte cSetupPriority, byte cHoldPriority, LinkedList<PcepValueType> llOptionalTlv) { - - this.lspaObjHeader = lspaObjHeader; - this.bLFlag = bLFlag; - this.iExcludeAny = iExcludeAny; - this.iIncludeAny = iIncludeAny; - this.iIncludeAll = iIncludeAll; - this.cSetupPriority = cSetupPriority; - this.cHoldPriority = cHoldPriority; - this.llOptionalTlv = llOptionalTlv; - } - - /** - * Sets Object Header. - * - * @param obj lspa object header - */ - public void setLspaObjHeader(PcepObjectHeader obj) { - this.lspaObjHeader = obj; - } - - @Override - public void setExcludeAny(int iExcludeAny) { - this.iExcludeAny = iExcludeAny; - } - - @Override - public void setIncludeAny(int iIncludeAny) { - this.iIncludeAny = iIncludeAny; - } - - @Override - public void setSetupPriority(byte cSetupPriority) { - this.cSetupPriority = cSetupPriority; - } - - @Override - public void setHoldPriority(byte cHoldPriority) { - this.cHoldPriority = cHoldPriority; - } - - @Override - public void setLFlag(boolean bLFlag) { - this.bLFlag = bLFlag; - } - - /** - * Returns lspa Object Header. - * - * @return lspa Object Header - */ - public PcepObjectHeader getLspaObjHeader() { - return this.lspaObjHeader; - } - - @Override - public int getExcludeAny() { - return this.iExcludeAny; - } - - @Override - public int getIncludeAny() { - return this.iIncludeAny; - } - - @Override - public int getIncludeAll() { - return this.iIncludeAll; - } - - @Override - public byte getSetupPriority() { - return this.cSetupPriority; - } - - @Override - public byte getHoldPriority() { - return this.cHoldPriority; - } - - @Override - public boolean getLFlag() { - return this.bLFlag; - } - - @Override - public void setIncludeAll(int value) { - this.iIncludeAll = value; - - } - - @Override - public LinkedList<PcepValueType> getOptionalTlv() { - return this.llOptionalTlv; - } - - @Override - public void setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) { - this.llOptionalTlv = llOptionalTlv; - - } - - /** - * Reads channel buffer and returns object of PcepLspaObject. - * - * @param cb of type channel buffer. - * @return object of PcepLspaObject - * @throws PcepParseException while parsing lspa object from channel buffer - */ - public static PcepLspaObject read(ChannelBuffer cb) throws PcepParseException { - - log.debug("LspaObject::read"); - PcepObjectHeader lspaObjHeader; - int iExcludeAny; - int iIncludeAny; - int iIncludeAll; - byte cSetupPriority; - byte cHoldPriority; - boolean bLFlag; - byte flags; - - // Optional TLV - LinkedList<PcepValueType> llOptionalTlv; - - lspaObjHeader = PcepObjectHeader.read(cb); - - //take only Lspa Object buffer. - ChannelBuffer tempCb = cb.readBytes(lspaObjHeader.getObjLen() - OBJECT_HEADER_LENGTH); - iExcludeAny = tempCb.readInt(); - iIncludeAny = tempCb.readInt(); - iIncludeAll = tempCb.readInt(); - cSetupPriority = tempCb.readByte(); - cHoldPriority = tempCb.readByte(); - flags = tempCb.readByte(); - tempCb.readByte(); - - bLFlag = (flags & (byte) LFLAG_SET) == LFLAG_SET; - - llOptionalTlv = parseOptionalTlv(tempCb); - - return new PcepLspaObjectVer1(lspaObjHeader, bLFlag, iExcludeAny, iIncludeAny, iIncludeAll, cSetupPriority, - cHoldPriority, llOptionalTlv); - } - - @Override - public int write(ChannelBuffer cb) throws PcepParseException { - - //write Object header - int objStartIndex = cb.writerIndex(); - - int objLenIndex = lspaObjHeader.write(cb); - - if (objLenIndex <= 0) { - throw new PcepParseException("Failed to write lspa object header. Index " + objLenIndex); - } - - cb.writeInt(iExcludeAny); - cb.writeInt(iIncludeAny); - cb.writeInt(iIncludeAll); - - int iTemp = cSetupPriority << SETUP_PRIORITY_SHIFT_VALUE; - iTemp = iTemp | (cHoldPriority << HOLD_PRIORITY_SHIFT_VALUE); - byte bFlag; - bFlag = (bLFlag) ? (byte) LFLAG_SET : LFLAG_RESET; - iTemp = iTemp | (bFlag << BFLAG_SHIFT_VALUE); - cb.writeInt(iTemp); - - // Add optional TLV - if (!packOptionalTlv(cb)) { - throw new PcepParseException("Faild to write lspa objects tlv to channel buffer"); - } - - short length = (short) (cb.writerIndex() - objStartIndex); - - lspaObjHeader.setObjLen(length); //will be helpful during print(). - - //As per RFC the length of object should be multiples of 4 - short pad = (short) (length % 4); - - if (pad != 0) { - pad = (short) (4 - pad); - for (int i = 0; i < pad; i++) { - cb.writeByte((byte) 0); - } - length = (short) (length + pad); - } - cb.setShort(objLenIndex, length); - return cb.writerIndex(); - } - - /** - * Parse list of optional tlvs. - * - * @param cb channel buffer - * @return list of optional tlvs. - * @throws PcepParseException when fails to parse optional tlv list. - */ - public static LinkedList<PcepValueType> parseOptionalTlv(ChannelBuffer cb) throws PcepParseException { - - LinkedList<PcepValueType> llOutOptionalTlv = new LinkedList<>(); - - return llOutOptionalTlv; - } - - /** - * Writes optional tlvs to channel buffer. - * - * @param cb channel buffer - * @return true - */ - protected boolean packOptionalTlv(ChannelBuffer cb) { - int hTlvType; - int hTlvLength; - - ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator(); - while (listIterator.hasNext()) { - PcepValueType tlv = listIterator.next(); - if (tlv == null) { - log.debug("Warning: tlv is null from OptionalTlv list"); - continue; - } - hTlvType = tlv.getType(); - hTlvLength = tlv.getLength(); - if (0 == hTlvLength) { - log.debug("Warning: invalid length in tlv of OptionalTlv list"); - continue; - } - - cb.writeShort(hTlvType); - cb.writeShort(hTlvLength); - - switch (hTlvType) { - //TODO: optional TLV for LSPA to be added - - default: - log.debug("Warning: PcepLspaObject: unknown tlv"); - } - - // As per RFC the length of object should - // be multiples of 4 - int pad = hTlvLength % 4; - - if (0 < pad) { - pad = 4 - pad; - if (pad <= cb.readableBytes()) { - cb.skipBytes(pad); - } - } - } - return true; - } - - /** - * Builder class for PCEP lspa object. - */ - public static class Builder implements PcepLspaObject.Builder { - private boolean bIsHeaderSet = false; - - private PcepObjectHeader lspaObjHeader; - - private boolean bLFlag; - private int iExcludeAny; - private boolean bIsExcludeAnySet = false; - private int iIncludeAny; - private boolean bIsIncludeAnySet = false; - private int iIncludeAll; - private boolean bIsIncludeAllSet = false; - private byte cSetupPriority; - private boolean bIsSetupPrioritySet = false; - private byte cHoldPriority; - private boolean bIsHoldPrioritySet = false; - private LinkedList<PcepValueType> llOptionalTlv; - - private boolean bIsPFlagSet = false; - private boolean bPFlag; - - private boolean bIsIFlagSet = false; - private boolean bIFlag; - - @Override - public PcepLspaObject build() throws PcepParseException { - - PcepObjectHeader lspaObjHeader = this.bIsHeaderSet ? this.lspaObjHeader : DEFAULT_LSPA_OBJECT_HEADER; - - if (!this.bIsExcludeAnySet) { - throw new PcepParseException("ExcludeAny NOT Set while building PcepLspaObject."); - } - if (!this.bIsIncludeAnySet) { - throw new PcepParseException("IncludeAny NOT Set while building PcepLspaObject."); - } - if (!this.bIsIncludeAllSet) { - throw new PcepParseException("IncludeAll NOT Set while building PcepLspaObject."); - } - if (!this.bIsSetupPrioritySet) { - throw new PcepParseException("Setup Priority NOT Set while building PcepLspaObject."); - } - if (!this.bIsHoldPrioritySet) { - throw new PcepParseException("Hold Priority NOT Set while building PcepLspaObject."); - } - - if (bIsPFlagSet) { - lspaObjHeader.setPFlag(bPFlag); - } - - if (bIsIFlagSet) { - lspaObjHeader.setIFlag(bIFlag); - } - - return new PcepLspaObjectVer1(lspaObjHeader, bLFlag, iExcludeAny, iIncludeAny, iIncludeAll, cSetupPriority, - cHoldPriority, llOptionalTlv); - } - - @Override - public PcepObjectHeader getLspaObjHeader() { - return this.lspaObjHeader; - } - - @Override - public Builder setLspaObjHeader(PcepObjectHeader obj) { - this.lspaObjHeader = obj; - this.bIsHeaderSet = true; - return this; - } - - @Override - public boolean getLFlag() { - return this.bLFlag; - } - - @Override - public Builder setLFlag(boolean value) { - this.bLFlag = value; - return this; - } - - @Override - public int getExcludeAny() { - return this.iExcludeAny; - } - - @Override - public Builder setExcludeAny(int value) { - this.iExcludeAny = value; - this.bIsExcludeAnySet = true; - return this; - } - - @Override - public int getIncludeAny() { - return this.iIncludeAny; - } - - @Override - public Builder setIncludeAny(int value) { - this.iIncludeAny = value; - this.bIsIncludeAnySet = true; - return this; - } - - @Override - public int getIncludeAll() { - return this.iIncludeAll; - } - - @Override - public Builder setIncludeAll(int value) { - this.iIncludeAll = value; - this.bIsIncludeAllSet = true; - return this; - } - - @Override - public byte getSetupPriority() { - return this.cSetupPriority; - } - - @Override - public Builder setSetupPriority(byte value) { - this.cSetupPriority = value; - this.bIsSetupPrioritySet = true; - return this; - } - - @Override - public byte getHoldPriority() { - return this.cHoldPriority; - } - - @Override - public Builder setHoldPriority(byte value) { - this.cHoldPriority = value; - this.bIsHoldPrioritySet = 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("LFlag", bLFlag) - .add("SetupPriority", cSetupPriority) - .add("HoldPriority", cHoldPriority) - .add("IncludeAll", iIncludeAll) - .add("IncludeAny", iIncludeAny) - .add("ExcludeAny", iExcludeAny) - .add("OptionalTlvList", llOptionalTlv) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepMessageVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepMessageVer1.java deleted file mode 100644 index 2169a673..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepMessageVer1.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * 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.PcepFactories; -import org.onosproject.pcepio.protocol.PcepMessage; -import org.onosproject.pcepio.protocol.PcepMessageReader; -import org.onosproject.pcepio.types.PcepErrorDetailInfo; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Provides PCEP messages. - */ -public abstract class PcepMessageVer1 { - - protected static final Logger log = LoggerFactory.getLogger(PcepFactories.class); - - // version: 1.0 - static final byte WIRE_VERSION = 1; - static final int MINIMUM_LENGTH = 4; - static final int PACKET_VERSION = 1; - static final byte OPEN_MSG_TYPE = 0x1; - static final byte KEEPALIVE_MSG_TYPE = 0x2; - static final byte REPORT_MSG_TYPE = 0xa; - static final byte TE_REPORT_MSG_TYPE = 0xe; - static final byte UPDATE_MSG_TYPE = 0xb; - static final byte INITIATE_MSG_TYPE = 0xc; - static final byte CLOSE_MSG_TYPE = 0x7; - static final byte ERROR_MSG_TYPE = 0x6; - static final byte LABEL_UPDATE_MSG_TYPE = 0xD; - static final byte LABEL_RANGE_RESV_MSG_TYPE = 0xF; - public static final int SHIFT_FLAG = 5; - static final int MINIMUM_COMMON_HEADER_LENGTH = 4; - - public static final PcepMessageVer1.Reader READER = new Reader(); - - /** - * Reader class for reading PCEP messages from channel buffer. - */ - static class Reader implements PcepMessageReader<PcepMessage> { - @Override - public PcepMessage readFrom(ChannelBuffer cb) throws PcepParseException { - - if (cb.readableBytes() < MINIMUM_LENGTH) { - throw new PcepParseException("Packet should have minimum length: " + MINIMUM_LENGTH); - } - - try { - int start = cb.readerIndex(); - // fixed value property version == 1 - byte version = cb.readByte(); - version = (byte) (version >> PcepMessageVer1.SHIFT_FLAG); - if (version != (byte) PACKET_VERSION) { - throw new PcepParseException("Wrong version. Expected=PcepVersion.Message_1(1), got=" + version); - } - - byte type = cb.readByte(); - short length = cb.readShort(); - cb.readerIndex(start); - - switch (type) { - - case OPEN_MSG_TYPE: - log.debug("OPEN MESSAGE is received"); - // message type value 1 means it is open message - return PcepOpenMsgVer1.READER.readFrom(cb.readBytes(length)); - case KEEPALIVE_MSG_TYPE: - log.debug("KEEPALIVE MESSAGE is received"); - // message type value 2 means it is Keepalive message - return PcepKeepaliveMsgVer1.READER.readFrom(cb.readBytes(length)); - case ERROR_MSG_TYPE: - log.debug("ERROR MESSAGE is received"); - // message type value 6 means it is error message - return PcepErrorMsgVer1.READER.readFrom(cb.readBytes(length)); - case REPORT_MSG_TYPE: - log.debug("REPORT MESSAGE is received"); - // message type value 10 means it is Report message - // return - return PcepReportMsgVer1.READER.readFrom(cb.readBytes(length)); - case UPDATE_MSG_TYPE: - log.debug("UPDATE MESSAGE is received"); - //message type value 11 means it is Update message - return PcepUpdateMsgVer1.READER.readFrom(cb.readBytes(length)); - case INITIATE_MSG_TYPE: - log.debug("INITIATE MESSAGE is received"); - //message type value 12 means it is PcInitiate message - return PcepInitiateMsgVer1.READER.readFrom(cb.readBytes(length)); - case CLOSE_MSG_TYPE: - log.debug("CLOSE MESSAGE is received"); - // message type value 7 means it is Close message - return PcepCloseMsgVer1.READER.readFrom(cb.readBytes(length)); - case TE_REPORT_MSG_TYPE: - log.debug("TE REPORT MESSAGE is received"); - // message type value 14 means it is TE REPORT message - // return - return PcepTEReportMsgVer1.READER.readFrom(cb.readBytes(length)); - case LABEL_UPDATE_MSG_TYPE: - log.debug("LABEL UPDATE MESSAGE is received"); - // message type value 13 means it is LABEL UPDATE message - // return - return PcepLabelUpdateMsgVer1.READER.readFrom(cb.readBytes(length)); - case LABEL_RANGE_RESV_MSG_TYPE: - log.debug("LABEL RANGE RESERVE MESSAGE is received"); - // message type value 15 means it is LABEL RANGE RESERVE message - // return - return PcepLabelRangeResvMsgVer1.READER.readFrom(cb.readBytes(length)); - default: - throw new PcepParseException("ERROR: UNKNOWN MESSAGE is received. Msg Type: " + type); - } - } catch (IndexOutOfBoundsException e) { - throw new PcepParseException(PcepErrorDetailInfo.ERROR_TYPE_1, PcepErrorDetailInfo.ERROR_VALUE_1); - } - } - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepMetricObjectVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepMetricObjectVer1.java deleted file mode 100644 index 31c27870..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepMetricObjectVer1.java +++ /dev/null @@ -1,376 +0,0 @@ -/* - * 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.PcepMetricObject; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP metric object. - */ -public class PcepMetricObjectVer1 implements PcepMetricObject { - - /* - METRIC Object Body Format. - - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Reserved | Flags |C|B| T | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | metric-value | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - - protected static final Logger log = LoggerFactory.getLogger(PcepMetricObjectVer1.class); - - public static final byte METRIC_OBJ_TYPE = 1; - public static final byte METRIC_OBJ_CLASS = 6; - public static final byte METRIC_OBJECT_VERSION = 1; - public static final short METRIC_OBJ_MINIMUM_LENGTH = 12; - public static final int OBJECT_HEADER_LENGTH = 4; - public static final int IFLAG_SHIFT_VALUE = 9; - public static final int BTYPE_SHIFT_VALUE = 8; - public static final int CFLAG_SET = 1; - public static final int CFLAG_RESET = 0; - public static final int BFLAG_SET = 1; - public static final int BFLAG_RESET = 0; - public static final byte CFLAG_CHECK = 0x02; - - static final PcepObjectHeader DEFAULT_METRIC_OBJECT_HEADER = new PcepObjectHeader(METRIC_OBJ_CLASS, - METRIC_OBJ_TYPE, PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, - METRIC_OBJ_MINIMUM_LENGTH); - - private PcepObjectHeader metricObjHeader; - private int iMetricVal; - private byte yFlag; // 6-flags - private boolean bCFlag; - private boolean bBFlag; - private byte bType; - - /** - * Default constructor. - */ - public PcepMetricObjectVer1() { - this.metricObjHeader = null; - this.iMetricVal = 0; - this.yFlag = 0; - this.bCFlag = false; - this.bBFlag = false; - this.bType = 0; - - } - - /** - * Constructor to initialize all member variables. - * - * @param metricObjHeader metric object header - * @param iMetricVal metric value - * @param yFlag Y flag - * @param bCFlag C flag - * @param bBFlag B flag - * @param bType Type value - */ - public PcepMetricObjectVer1(PcepObjectHeader metricObjHeader, int iMetricVal, byte yFlag, boolean bCFlag, - boolean bBFlag, byte bType) { - - this.metricObjHeader = metricObjHeader; - this.iMetricVal = iMetricVal; - this.yFlag = yFlag; - this.bCFlag = bCFlag; - this.bBFlag = bBFlag; - this.bType = bType; - - } - - @Override - public void setMetricVal(int value) { - this.iMetricVal = value; - - } - - @Override - public int getMetricVal() { - return this.iMetricVal; - } - - @Override - public byte getYFlag() { - return this.yFlag; - } - - @Override - public void setYFlag(byte value) { - this.yFlag = value; - } - - @Override - public boolean getCFlag() { - return this.bCFlag; - } - - @Override - public void setCFlag(boolean value) { - this.bCFlag = value; - } - - @Override - public boolean getBFlag() { - return this.bBFlag; - } - - @Override - public void setBFlag(boolean value) { - this.bBFlag = value; - } - - @Override - public byte getBType() { - return this.bType; - } - - @Override - public void setBType(byte value) { - this.bType = value; - } - - /** - * Sets metric Object Header. - * - * @param obj metric object header - */ - public void setMetricObjHeader(PcepObjectHeader obj) { - this.metricObjHeader = obj; - } - - /** - * Returns metric Object Header. - * - * @return metricObjHeader - */ - public PcepObjectHeader getMetricObjHeader() { - return this.metricObjHeader; - } - - /** - * Reads from channel buffer and returns object of PcepMetricObject. - * - * @param cb of channel buffer. - * @return object of PcepMetricObject - * @throws PcepParseException when metric object is not present in channel buffer - */ - public static PcepMetricObject read(ChannelBuffer cb) throws PcepParseException { - - log.debug("MetricObject::read"); - PcepObjectHeader metricObjHeader; - int iMetricVal; - byte yFlag; // 6-flags - boolean bCFlag; - boolean bBFlag; - byte bType; - - metricObjHeader = PcepObjectHeader.read(cb); - - if (metricObjHeader.getObjClass() != METRIC_OBJ_CLASS) { - throw new PcepParseException("This object is not a Metric Object. Object Class: " - + metricObjHeader.getObjClass()); - } - - //take only metric buffer. - ChannelBuffer tempCb = cb.readBytes(metricObjHeader.getObjLen() - OBJECT_HEADER_LENGTH); - - tempCb.readShort(); - yFlag = tempCb.readByte(); - bType = tempCb.readByte(); - bCFlag = (yFlag & CFLAG_CHECK) == CFLAG_CHECK; - bBFlag = (yFlag & BFLAG_SET) == BFLAG_SET; - iMetricVal = tempCb.readInt(); - - return new PcepMetricObjectVer1(metricObjHeader, iMetricVal, yFlag, bCFlag, bBFlag, bType); - } - - @Override - public int write(ChannelBuffer cb) throws PcepParseException { - //write Object header - int objStartIndex = cb.writerIndex(); - - int objLenIndex = metricObjHeader.write(cb); - - if (objLenIndex <= 0) { - throw new PcepParseException("Error: ObjectLength is " + objLenIndex); - } - - int iFlag = (bCFlag) ? CFLAG_SET : CFLAG_RESET; - int iTemp = iFlag << IFLAG_SHIFT_VALUE; - iFlag = (bBFlag) ? BFLAG_SET : BFLAG_RESET; - iTemp = iTemp | (iFlag << BTYPE_SHIFT_VALUE); - iTemp = iTemp | bType; - cb.writeInt(iTemp); - cb.writeInt(iMetricVal); - - short hLength = (short) (cb.writerIndex() - objStartIndex); - cb.setShort(objLenIndex, hLength); - //will be helpful during print(). - metricObjHeader.setObjLen(hLength); - return hLength; - } - - /** - * Builder class for PCEP metric object. - */ - public static class Builder implements PcepMetricObject.Builder { - - private boolean bIsHeaderSet = false; - private PcepObjectHeader metricObjHeader; - private int iMetricVal; - private boolean bIsMetricValSet = false; - private byte yFlag; // 6-flags - private boolean bCFlag; - private boolean bBFlag; - private byte bType; - private boolean bIsbTypeSet = false; - - private boolean bIsPFlagSet = false; - private boolean bPFlag; - - private boolean bIsIFlagSet = false; - private boolean bIFlag; - - @Override - public PcepMetricObject build() throws PcepParseException { - - PcepObjectHeader metricObjHeader = this.bIsHeaderSet ? this.metricObjHeader : DEFAULT_METRIC_OBJECT_HEADER; - - if (!this.bIsMetricValSet) { - throw new PcepParseException(" Metric Value NOT Set while building PcepMetricObject."); - } - if (!this.bIsbTypeSet) { - throw new PcepParseException(" Type NOT Set while building PcepMetricObject."); - } - - if (bIsPFlagSet) { - metricObjHeader.setPFlag(bPFlag); - } - - if (bIsIFlagSet) { - metricObjHeader.setIFlag(bIFlag); - } - - return new PcepMetricObjectVer1(metricObjHeader, iMetricVal, yFlag, bCFlag, bBFlag, bType); - } - - @Override - public PcepObjectHeader getMetricObjHeader() { - return this.metricObjHeader; - } - - @Override - public Builder setMetricObjHeader(PcepObjectHeader obj) { - this.metricObjHeader = obj; - this.bIsHeaderSet = true; - return this; - } - - @Override - public int getMetricVal() { - return this.iMetricVal; - } - - @Override - public Builder setMetricVal(int value) { - this.iMetricVal = value; - this.bIsMetricValSet = true; - return this; - } - - @Override - public byte getYFlag() { - return this.yFlag; - } - - @Override - public Builder setYFlag(byte value) { - this.yFlag = value; - return this; - } - - @Override - public boolean getCFlag() { - return this.bCFlag; - } - - @Override - public Builder setCFlag(boolean value) { - this.bCFlag = value; - return this; - } - - @Override - public boolean getBFlag() { - return this.bBFlag; - } - - @Override - public Builder setBFlag(boolean value) { - this.bBFlag = value; - return this; - } - - @Override - public byte getBType() { - return this.bType; - } - - @Override - public Builder setBType(byte value) { - this.bType = value; - this.bIsbTypeSet = true; - 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("MetricValue", iMetricVal) - .add("BFlag", bBFlag) - .add("CFlag", bCFlag) - .add("BType", bType) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepMsgPathVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepMsgPathVer1.java deleted file mode 100644 index 49c738fc..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepMsgPathVer1.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * 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.PcepAttribute; -import org.onosproject.pcepio.protocol.PcepEroObject; -import org.onosproject.pcepio.protocol.PcepMsgPath; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP Message PAth for update message. - * Reference :PCE extensions for stateful draft-ietf-pce-stateful-pce-10. - */ -public class PcepMsgPathVer1 implements PcepMsgPath { - - /* - * <path> ::= <ERO><attribute-list> - */ - - protected static final Logger log = LoggerFactory.getLogger(PcepMsgPathVer1.class); - //PcepEroObject - private PcepEroObject eroObj; - private boolean isEroObjectSet; - // PcepAttribute - private PcepAttribute attrList; - private boolean isAttributeListSet; - - /** - * constructor to initialize objects. - */ - public PcepMsgPathVer1() { - eroObj = null; - attrList = null; - isEroObjectSet = false; - isAttributeListSet = false; - } - - @Override - public PcepEroObject getEroObject() { - return eroObj; - } - - @Override - public PcepAttribute getPcepAttribute() { - return attrList; - } - - @Override - public void setEroObject(PcepEroObject eroObj) { - this.eroObj = eroObj; - } - - @Override - public void setPcepAttribute(PcepAttribute attrList) { - this.attrList = attrList; - } - - /** - * constructor to initialize member variables. - * - * @param eroObj pcep ero object - * @param attrList pcep attribute - */ - public PcepMsgPathVer1(PcepEroObject eroObj, PcepAttribute attrList) { - this.eroObj = eroObj; - isEroObjectSet = true; - this.attrList = attrList; - if (attrList == null) { - isAttributeListSet = false; - } else { - isAttributeListSet = true; - } - } - - @Override - public PcepMsgPath read(ChannelBuffer cb) throws PcepParseException { - PcepEroObject eroObj; - PcepAttribute attrList; - - eroObj = PcepEroObjectVer1.read(cb); - attrList = PcepAttributeVer1.read(cb); - - return new PcepMsgPathVer1(eroObj, attrList); - } - - @Override - public int write(ChannelBuffer cb) throws PcepParseException { - int iLenStartIndex = cb.writerIndex(); - - //write Object header - if (this.isEroObjectSet) { - this.eroObj.write(cb); - } - if (this.isAttributeListSet) { - attrList.write(cb); - } - - return cb.writerIndex() - iLenStartIndex; - } - - /** - * Builder class for PCEP Message path. - */ - public static class Builder implements PcepMsgPath.Builder { - - private boolean bIsEROObjectSet = false; - private boolean bIsPcepAttributeSet = false; - - //PCEP ERO Object - private PcepEroObject eroObject; - //PCEP Attribute list - private PcepAttribute pcepAttribute; - - @Override - public PcepMsgPath build() throws PcepParseException { - - //PCEP ERO Object - PcepEroObject eroObject = null; - //PCEP Attribute list - PcepAttribute pcepAttribute = null; - - if (!this.bIsEROObjectSet) { - throw new PcepParseException("ERO Object NOT Set while building PcepMsgPath."); - } else { - eroObject = this.eroObject; - } - if (!this.bIsPcepAttributeSet) { - throw new PcepParseException("Pcep Attributes NOT Set while building PcepMsgPath."); - } else { - pcepAttribute = this.pcepAttribute; - } - - return new PcepMsgPathVer1(eroObject, pcepAttribute); - } - - @Override - public PcepEroObject getEroObject() { - return this.eroObject; - } - - @Override - public PcepAttribute getPcepAttribute() { - return this.pcepAttribute; - } - - @Override - public Builder setEroObject(PcepEroObject eroObject) { - this.eroObject = eroObject; - this.bIsEROObjectSet = true; - return this; - } - - @Override - public Builder setPcepAttribute(PcepAttribute pcepAttribute) { - this.pcepAttribute = pcepAttribute; - this.bIsPcepAttributeSet = true; - return this; - } - - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("EroObject", eroObj) - .add("AttributeList", attrList) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepOpenMsgVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepOpenMsgVer1.java deleted file mode 100644 index 902226e9..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepOpenMsgVer1.java +++ /dev/null @@ -1,204 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onosproject.pcepio.protocol.ver1; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepMessageReader; -import org.onosproject.pcepio.protocol.PcepMessageWriter; -import org.onosproject.pcepio.protocol.PcepOpenMsg; -import org.onosproject.pcepio.protocol.PcepOpenObject; -import org.onosproject.pcepio.protocol.PcepType; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.onosproject.pcepio.types.PcepErrorDetailInfo; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP open message. - */ -public class PcepOpenMsgVer1 implements PcepOpenMsg { - - /* - * <Open Message>::= <Common Header> <OPEN> - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Ver | Flags | Message-Type | Message-Length | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Object-Class | OT |Res|P|I| Object Length (bytes) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Ver | Flags | Keepalive | DeadTimer | SID | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | | - // Optional TLVs // - | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - - protected static final Logger log = LoggerFactory.getLogger(PcepOpenMsgVer1.class); - - public static final byte PACKET_VERSION = 1; - public static final int PACKET_MINIMUM_LENGTH = 12; - public static final PcepType MSG_TYPE = PcepType.OPEN; - private PcepOpenObject pcepOpenObj; - - public static final PcepOpenMsgVer1.Reader READER = new Reader(); - - /** - * Constructor to initialize PcepOpenObject. - * - * @param pcepOpenObj PCEP-OPEN-OBJECT - */ - public PcepOpenMsgVer1(PcepOpenObject pcepOpenObj) { - this.pcepOpenObj = pcepOpenObj; - } - - @Override - public PcepOpenObject getPcepOpenObject() { - return this.pcepOpenObj; - } - - @Override - public void setPcepOpenObject(PcepOpenObject pcepOpenObj) { - this.pcepOpenObj = pcepOpenObj; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public PcepType getType() { - return MSG_TYPE; - } - - /** - * Reader class for reading PCEP open message from channel buffer. - */ - public static class Reader implements PcepMessageReader<PcepOpenMsg> { - - @Override - public PcepOpenMsg readFrom(ChannelBuffer cb) throws PcepParseException { - - if (cb.readableBytes() < PACKET_MINIMUM_LENGTH) { - throw new PcepParseException("Packet size is less than the minimum length."); - } - - byte version = cb.readByte(); - version = (byte) (version >> PcepMessageVer1.SHIFT_FLAG); - if (version != PACKET_VERSION) { - log.error("[readFrom] Invalid version: " + version); - throw new PcepParseException(PcepErrorDetailInfo.ERROR_TYPE_1, PcepErrorDetailInfo.ERROR_VALUE_1); - } - // fixed value property type == 1 - byte type = cb.readByte(); - - if (type != MSG_TYPE.getType()) { - log.error("[readFrom] Unexpected type: " + type); - throw new PcepParseException(PcepErrorDetailInfo.ERROR_TYPE_1, PcepErrorDetailInfo.ERROR_VALUE_1); - } - int length = cb.readShort(); - if (length < PACKET_MINIMUM_LENGTH) { - throw new PcepParseException( - "Wrong length: Expected to be >= " + PACKET_MINIMUM_LENGTH + ", was: " + length); - } - return new PcepOpenMsgVer1(PcepOpenObjectVer1.read(cb)); - } - } - - /** - * Builder class for PCEP open message. - */ - static class Builder implements PcepOpenMsg.Builder { - - private PcepOpenObject pcepOpenObj; - - @Override - public PcepOpenMsg build() throws PcepParseException { - if (!(pcepOpenObj instanceof PcepOpenObjectVer1)) { - throw new NullPointerException("PcepOpenObject is null."); - } - return new PcepOpenMsgVer1(pcepOpenObj); - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public PcepType getType() { - return PcepType.OPEN; - } - - @Override - public PcepOpenObject getPcepOpenObj() { - return this.pcepOpenObj; - } - - @Override - public Builder setPcepOpenObj(PcepOpenObject obj) { - this.pcepOpenObj = obj; - return this; - } - } - - @Override - public void writeTo(ChannelBuffer cb) throws PcepParseException { - WRITER.write(cb, this); - } - - public static final Writer WRITER = new Writer(); - - /** - * Writer class for writing PCEP opne message to channel buffer. - */ - public static class Writer implements PcepMessageWriter<PcepOpenMsgVer1> { - - @Override - public void write(ChannelBuffer cb, PcepOpenMsgVer1 message) throws PcepParseException { - int startIndex = cb.writerIndex(); - // first 3 bits set to version - cb.writeByte((byte) (PACKET_VERSION << PcepMessageVer1.SHIFT_FLAG)); - // message type - cb.writeByte(MSG_TYPE.getType()); - // length is length of variable message, will be updated at the end - // Store the position of message - // length in buffer - - int msgLenIndex = cb.writerIndex(); - cb.writeShort(0); - - message.getPcepOpenObject().write(cb); - - // update message length field - int iLength = cb.writerIndex() - startIndex; - cb.setShort(msgLenIndex, (short) iLength); - } - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("OpenObject", pcepOpenObj) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepOpenObjectVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepOpenObjectVer1.java deleted file mode 100644 index d5e58694..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepOpenObjectVer1.java +++ /dev/null @@ -1,491 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onosproject.pcepio.protocol.ver1; - -import java.util.LinkedList; -import java.util.ListIterator; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepOpenObject; -import org.onosproject.pcepio.protocol.PcepType; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.onosproject.pcepio.types.GmplsCapabilityTlv; -import org.onosproject.pcepio.types.PceccCapabilityTlv; -import org.onosproject.pcepio.types.PcepLabelDbVerTlv; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.onosproject.pcepio.types.PcepValueType; -import org.onosproject.pcepio.types.StatefulLspDbVerTlv; -import org.onosproject.pcepio.types.StatefulPceCapabilityTlv; -import org.onosproject.pcepio.types.TedCapabilityTlv; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP open object. - */ -public class PcepOpenObjectVer1 implements PcepOpenObject { - - /* - message format. - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Object-Class | OT |Res|P|I| Object Length (bytes) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Ver | Flags | Keepalive | DeadTimer | SID | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | | - // Optional TLVs // - | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - The OPEN Object format - */ - protected static final Logger log = LoggerFactory.getLogger(PcepOpenObjectVer1.class); - - public static final PcepType MSG_TYPE = PcepType.OPEN; - public static final byte OPEN_OBJECT_VERSION = 1; - public static final byte OPEN_OBJ_TYPE = 1; - public static final byte OPEN_OBJ_CLASS = 1; - public static final byte DEFAULT_KEEPALIVE_TIME = 30; - public static final byte DEFAULT_DEAD_TIME = 120; - public static final short OPEN_OBJ_MINIMUM_LENGTH = 8; - public static final int DEFAULT_GMPLS_CAPABILITY_TLV_IVALUE = 0X0; - public static final int DEFAULT_STATEFUL_PCE_CAPABILITY_TLV_IVALUE = 0xf; - public static final int DEFAULT_PCECC_CAPABILITY_TLV_IVALUE = 0x7; - public static final int DEFAULT_PCEP_LABEL_DB_VER_TLV_IVALUE = 0X0; - - public static final PcepObjectHeader DEFAULT_OPEN_HEADER = new PcepObjectHeader(OPEN_OBJ_CLASS, OPEN_OBJ_TYPE, - PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, OPEN_OBJ_MINIMUM_LENGTH); - - private PcepObjectHeader openObjHeader; - private byte keepAliveTime; - private byte deadTime; - private byte sessionId; - private LinkedList<PcepValueType> llOptionalTlv; - - /** - * Default constructor. - */ - public PcepOpenObjectVer1() { - this.openObjHeader = null; - this.keepAliveTime = 0; - this.deadTime = 0; - this.sessionId = 0; - this.llOptionalTlv = null; - } - - /** - * Constructor to initialize all member variables. - * - * @param openObjHeader Open Object Header - * @param keepAliveTime Keepalive timer value - * @param deadTime Dead timer value - * @param sessionID session id - * @param llOptionalTlv Optional TLV - */ - public PcepOpenObjectVer1(PcepObjectHeader openObjHeader, byte keepAliveTime, byte deadTime, byte sessionID, - LinkedList<PcepValueType> llOptionalTlv) { - this.openObjHeader = openObjHeader; - this.keepAliveTime = keepAliveTime; - this.deadTime = deadTime; - this.sessionId = sessionID; - this.llOptionalTlv = llOptionalTlv; - } - - @Override - public PcepObjectHeader getOpenObjHeader() { - return this.openObjHeader; - } - - @Override - public void setOpenObjHeader(PcepObjectHeader obj) { - this.openObjHeader = obj; - } - - @Override - public byte getKeepAliveTime() { - return this.keepAliveTime; - } - - @Override - public void setKeepAliveTime(byte value) { - this.keepAliveTime = value; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public byte getDeadTime() { - return this.deadTime; - } - - @Override - public void setDeadTime(byte value) { - this.deadTime = value; - } - - @Override - public byte getSessionId() { - return this.sessionId; - } - - @Override - public void setSessionId(byte value) { - this.sessionId = value; - } - - @Override - public LinkedList<PcepValueType> getOptionalTlv() { - return this.llOptionalTlv; - } - - @Override - public void setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) { - this.llOptionalTlv = llOptionalTlv; - } - - /** - * Reads from channel buffer and returns object of PcepOpenObject. - * - * @param cb of type channel buffer - * @return object of PcepOpenObject - * @throws PcepParseException if mandatory fields are missing - */ - public static PcepOpenObject read(ChannelBuffer cb) throws PcepParseException { - - PcepObjectHeader openObjHeader; - byte version; - byte keepAliveTime; - byte deadTime; - byte sessionID; - LinkedList<PcepValueType> llOptionalTlv; - - openObjHeader = PcepObjectHeader.read(cb); - version = cb.readByte(); - version = (byte) (version >> PcepMessageVer1.SHIFT_FLAG); - if (version != OPEN_OBJECT_VERSION) { - throw new PcepParseException("Wrong version: Expected=PcepVersion.PCEP_1(1), got=" + version); - } - /* Keepalive */ - keepAliveTime = cb.readByte(); - - /* DeadTimer */ - deadTime = cb.readByte(); - - /* SID */ - sessionID = cb.readByte(); - - // Optional TLV - llOptionalTlv = parseOptionalTlv(cb); - - return new PcepOpenObjectVer1(openObjHeader, keepAliveTime, deadTime, sessionID, llOptionalTlv); - } - - /** - * Returns linkedlist of optional tlvs. - * - * @param cb of type channel buffer - * @return llOptionalTlv Optional TLV - * @throws PcepParseException if mandatory fields are missing - */ - protected static LinkedList<PcepValueType> parseOptionalTlv(ChannelBuffer cb) throws PcepParseException { - - LinkedList<PcepValueType> llOptionalTlv; - - llOptionalTlv = new LinkedList<>(); - - while (4 <= cb.readableBytes()) { - PcepValueType tlv; - short hType = cb.readShort(); - short hLength = cb.readShort(); - - switch (hType) { - case GmplsCapabilityTlv.TYPE: - log.debug("GmplsCapabilityTlv"); - if (GmplsCapabilityTlv.LENGTH != hLength) { - throw new PcepParseException("Invalid length received for Gmpls_Capability_Tlv."); - } - int iValue = cb.readInt(); - tlv = new GmplsCapabilityTlv(iValue); - break; - case StatefulPceCapabilityTlv.TYPE: - log.debug("StatefulPceCapabilityTlv"); - if (StatefulPceCapabilityTlv.LENGTH != hLength) { - throw new PcepParseException("Invalid length received for StatefulPceCapabilityTlv."); - } - tlv = StatefulPceCapabilityTlv.read(cb); - break; - case PceccCapabilityTlv.TYPE: - log.debug("PceccCapabilityTlv"); - if (PceccCapabilityTlv.LENGTH != hLength) { - throw new PcepParseException("Invalid length for PceccCapabilityTlv."); - } - iValue = cb.readInt(); - tlv = new PceccCapabilityTlv(iValue); - break; - case StatefulLspDbVerTlv.TYPE: - log.debug("StatefulLspDbVerTlv"); - if (StatefulLspDbVerTlv.LENGTH != hLength) { - throw new PcepParseException("Invalid length received for StatefulLspDbVerTlv."); - } - long lValue = cb.readLong(); - tlv = new StatefulLspDbVerTlv(lValue); - break; - case TedCapabilityTlv.TYPE: - log.debug("TedCapabilityTlv"); - if (TedCapabilityTlv.LENGTH != hLength) { - throw new PcepParseException("Invalid length received for TedCapabilityTlv."); - } - iValue = cb.readInt(); - tlv = new TedCapabilityTlv(iValue); - break; - case PcepLabelDbVerTlv.TYPE: - log.debug("PcepLabelDbVerTlv"); - if (PcepLabelDbVerTlv.LENGTH != hLength) { - throw new PcepParseException("Invalid length received for PcepLabelDbVerTlv."); - } - lValue = cb.readLong(); - tlv = new PcepLabelDbVerTlv(lValue); - break; - default: - log.debug("Unsupported TLV: " + hType); - cb.skipBytes(hLength); - continue; - } - - llOptionalTlv.add(tlv); - } - - if (0 < cb.readableBytes()) { - throw new PcepParseException("Optional Tlv parsing error. Extra bytes received."); - } - - return llOptionalTlv; - } - - @Override - public int write(ChannelBuffer cb) throws PcepParseException { - - int objStartIndex = cb.writerIndex(); - - //write common header - int objLenIndex = openObjHeader.write(cb); - - if (objLenIndex <= 0) { - throw new PcepParseException("Unable to write Open object header."); - } - - cb.writeByte((byte) (OPEN_OBJECT_VERSION << PcepMessageVer1.SHIFT_FLAG)); - cb.writeByte(this.keepAliveTime); - cb.writeByte(this.deadTime); - cb.writeByte(this.sessionId); - - //Pack optional TLV - packOptionalTlv(cb); - - //now write OPEN Object Length - int length = cb.writerIndex() - objStartIndex; - cb.setShort(objLenIndex, (short) length); - //will be helpful during print(). - this.openObjHeader.setObjLen((short) length); - - return length; - } - - /** - * Returns writer index. - * - * @param cb of type channel buffer. - * @return writer index - */ - protected int packOptionalTlv(ChannelBuffer cb) { - int startIndex = cb.writerIndex(); - - LinkedList<PcepValueType> llOptionalTlv = this.llOptionalTlv; - ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator(); - while (listIterator.hasNext()) { - PcepValueType tlv = listIterator.next(); - if (tlv == null) { - log.debug("TLV is null from OptionalTlv list"); - continue; - } - - tlv.write(cb); - - // need to take care of padding - int pad = tlv.getLength() % 4; - - if (0 != pad) { - pad = 4 - pad; - for (int i = 0; i < pad; ++i) { - cb.writeByte((byte) 0); - } - } - } - return cb.writerIndex() - startIndex; - } - - /** - * Builder class for PCPE open object. - */ - public static class Builder implements PcepOpenObject.Builder { - // Pcep open message fields - private boolean bIsHeaderSet = false; - private PcepObjectHeader openObjHeader; - private boolean bIsKeepAliveTimeSet = false; - private byte keepAliveTime; - private boolean bIsDeadTimeSet = false; - private byte deadTime; - private boolean bIsSessionIDSet = false; - private byte sessionID; - private boolean bIsOptionalTlvSet = false; - private LinkedList<PcepValueType> llOptionalTlv = new LinkedList<>(); - - private boolean bIsPFlagSet = false; - private boolean bPFlag; - - private boolean bIsIFlagSet = false; - private boolean bIFlag; - - @Override - public PcepOpenObject build() throws PcepParseException { - PcepObjectHeader openObjHeader = this.bIsHeaderSet ? this.openObjHeader : DEFAULT_OPEN_HEADER; - byte keepAliveTime = this.bIsKeepAliveTimeSet ? this.keepAliveTime : DEFAULT_KEEPALIVE_TIME; - byte deadTime = this.bIsDeadTimeSet ? this.deadTime : DEFAULT_DEAD_TIME; - - if (!this.bIsSessionIDSet) { - throw new PcepParseException("SessionID is not set (mandatory)"); - } - if (!this.bIsOptionalTlvSet) { - //Add tlv to list - //Add GmplsCapabilityTlv - PcepValueType tlv; - int iValue = DEFAULT_GMPLS_CAPABILITY_TLV_IVALUE; - tlv = new GmplsCapabilityTlv(iValue); - this.llOptionalTlv.add(tlv); - - //Add StatefulPceCapabilityTlv - iValue = DEFAULT_STATEFUL_PCE_CAPABILITY_TLV_IVALUE; - tlv = new StatefulPceCapabilityTlv(iValue); - this.llOptionalTlv.add(tlv); - - } - - if (bIsPFlagSet) { - openObjHeader.setPFlag(bPFlag); - } - - if (bIsIFlagSet) { - openObjHeader.setIFlag(bIFlag); - } - - return new PcepOpenObjectVer1(openObjHeader, keepAliveTime, deadTime, this.sessionID, this.llOptionalTlv); - } - - @Override - public PcepObjectHeader getOpenObjHeader() { - return this.openObjHeader; - } - - @Override - public Builder setOpenObjHeader(PcepObjectHeader obj) { - this.openObjHeader = obj; - this.bIsHeaderSet = true; - return this; - } - - @Override - public byte getKeepAliveTime() { - return this.keepAliveTime; - } - - @Override - public Builder setKeepAliveTime(byte value) { - this.keepAliveTime = value; - this.bIsKeepAliveTimeSet = true; - return this; - } - - @Override - public byte getDeadTime() { - return this.deadTime; - } - - @Override - public Builder setDeadTime(byte value) { - this.deadTime = value; - this.bIsDeadTimeSet = true; - return this; - } - - @Override - public byte getSessionId() { - return this.sessionID; - } - - @Override - public Builder setSessionId(byte value) { - this.sessionID = value; - this.bIsSessionIDSet = true; - return this; - } - - @Override - public Builder setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) { - this.llOptionalTlv = llOptionalTlv; - this.bIsOptionalTlvSet = true; - return this; - } - - @Override - public LinkedList<PcepValueType> getOptionalTlv() { - return this.llOptionalTlv; - } - - @Override - public Builder setPFlag(boolean value) { - this.bPFlag = value; - this.bIsPFlagSet = true; - return this; - } - - @Override - public Builder setIFlag(boolean value) { - this.bIFlag = value; - this.bIsIFlagSet = true; - return this; - } - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("ObjectHeader", openObjHeader) - .add("Keepalive", keepAliveTime) - .add("DeadTimer", deadTime) - .add("SessionId", sessionId) - .add("OptionalTlv", llOptionalTlv) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepRPObjectVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepRPObjectVer1.java deleted file mode 100644 index 7234a467..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepRPObjectVer1.java +++ /dev/null @@ -1,445 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.pcepio.protocol.ver1; - -import java.util.LinkedList; -import java.util.ListIterator; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepRPObject; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.onosproject.pcepio.types.PcepValueType; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP RP object. - */ -public class PcepRPObjectVer1 implements PcepRPObject { - - /* - * RP Object. - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Flags |O|B|R| Pri | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Request-ID-number | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | | - // Optional TLVs // - | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - - protected static final Logger log = LoggerFactory.getLogger(PcepRPObjectVer1.class); - - public static final byte RP_OBJ_TYPE = 1; - public static final byte RP_OBJ_CLASS = 2; - public static final byte RP_OBJECT_VERSION = 1; - public static final short RP_OBJ_MINIMUM_LENGTH = 12; - - public static final int DEFAULT_REQUEST_ID_NUM = 0; - //Signalled , all default values to be checked. - public static final boolean DEFAULT_OFLAG = false; - public static final boolean DEFAULT_BFLAG = false; - public static final boolean DEFAULT_RFLAG = false; - public static final byte DEFAULT_PRIFLAG = 0; - public static final int OBJECT_HEADER_LENGTH = 4; - public static final int OFLAG_SHIFT_VALUE = 5; - public static final int BFLAG_SHIFT_VALUE = 4; - public static final int RFLAG_SHIFT_VALUE = 3; - public static final int OFLAG_TEMP_SHIFT_VALUE = 0x20; - public static final int BFLAG_TEMP_SHIFT_VALUE = 0x10; - public static final int RFLAG_TEMP_SHIFT_VALUE = 0x08; - public static final int PRIFLAG_TEMP_SHIFT_VALUE = 0x07; - public static final int BIT_SET = 1; - public static final int BIT_RESET = 0; - public static final int MINIMUM_COMMON_HEADER_LENGTH = 4; - - public static final PcepObjectHeader DEFAULT_RP_OBJECT_HEADER = new PcepObjectHeader(RP_OBJ_CLASS, RP_OBJ_TYPE, - PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, RP_OBJ_MINIMUM_LENGTH); - - private PcepObjectHeader rpObjHeader; - private int iRequestIdNum; - private boolean bOFlag; - private boolean bBFlag; - private boolean bRFlag; - private byte yPriFlag; // 3bytes - private LinkedList<PcepValueType> llOptionalTlv; - - /** - * Constructor to initialize variables. - * - * @param rpObjHeader RP-OBJECT header - * @param iRequestIdNum Request-ID-number - * @param bOFlag O-flag - * @param bBFlag B-flag - * @param bRFlag R-flag - * @param yPriFlag Pri-flag - * @param llOptionalTlv linked list of Optional TLV - */ - public PcepRPObjectVer1(PcepObjectHeader rpObjHeader, int iRequestIdNum, boolean bOFlag, boolean bBFlag, - boolean bRFlag, byte yPriFlag, LinkedList<PcepValueType> llOptionalTlv) { - this.rpObjHeader = rpObjHeader; - this.iRequestIdNum = iRequestIdNum; - this.bOFlag = bOFlag; - this.bBFlag = bBFlag; - this.bRFlag = bRFlag; - this.yPriFlag = yPriFlag; - this.llOptionalTlv = llOptionalTlv; - } - - /** - * Sets RP Object header. - * - * @param obj RP Object header - */ - public void setRPObjHeader(PcepObjectHeader obj) { - this.rpObjHeader = obj; - } - - @Override - public void setRequestIdNum(int iRequestIdNum) { - this.iRequestIdNum = iRequestIdNum; - } - - @Override - public void setOFlag(boolean bOFlag) { - this.bOFlag = bOFlag; - } - - @Override - public void setBFlag(boolean bBFlag) { - this.bBFlag = bBFlag; - } - - @Override - public void setRFlag(boolean bRFlag) { - this.bRFlag = bRFlag; - } - - @Override - public void setPriFlag(byte yPriFlag) { - this.yPriFlag = yPriFlag; - } - - /** - * Returns RP Object header. - * - * @return rpObjHeader - */ - public PcepObjectHeader getRPObjHeader() { - return this.rpObjHeader; - } - - @Override - public int getRequestIdNum() { - return this.iRequestIdNum; - } - - @Override - public boolean getOFlag() { - return this.bOFlag; - } - - @Override - public boolean getBFlag() { - return this.bBFlag; - } - - @Override - public boolean getRFlag() { - return this.bRFlag; - } - - @Override - public byte getPriFlag() { - return this.yPriFlag; - } - - /** - * Reads the channel buffer and returns the object of PcepRPObject. - * - * @param cb of type channel buffer - * @return the object of PcepRPObject - * @throws PcepParseException if mandatory fields are missing - */ - public static PcepRPObject read(ChannelBuffer cb) throws PcepParseException { - log.debug("read"); - PcepObjectHeader rpObjHeader; - int iRequestIdNum; - boolean bOFlag; - boolean bBFlag; - boolean bRFlag; - byte yPriFlag; // 3bytes - LinkedList<PcepValueType> llOptionalTlv = new LinkedList<>(); - - rpObjHeader = PcepObjectHeader.read(cb); - - //take only LspObject buffer. - ChannelBuffer tempCb = cb.readBytes(rpObjHeader.getObjLen() - OBJECT_HEADER_LENGTH); - - int iTemp = tempCb.readInt(); - yPriFlag = (byte) (iTemp & PRIFLAG_TEMP_SHIFT_VALUE); - bOFlag = (iTemp & OFLAG_TEMP_SHIFT_VALUE) == OFLAG_TEMP_SHIFT_VALUE; - bBFlag = (iTemp & BFLAG_TEMP_SHIFT_VALUE) == BFLAG_TEMP_SHIFT_VALUE; - bRFlag = (iTemp & RFLAG_TEMP_SHIFT_VALUE) == RFLAG_TEMP_SHIFT_VALUE; - - iRequestIdNum = tempCb.readInt(); - - // parse optional TLV - llOptionalTlv = parseOptionalTlv(tempCb); - - return new PcepRPObjectVer1(rpObjHeader, iRequestIdNum, bOFlag, bBFlag, bRFlag, yPriFlag, llOptionalTlv); - } - - @Override - public int write(ChannelBuffer cb) throws PcepParseException { - - //write Object header - int objStartIndex = cb.writerIndex(); - - int objLenIndex = rpObjHeader.write(cb); - - if (objLenIndex <= 0) { - throw new PcepParseException("ObjectLength Index is " + objLenIndex); - } - int iTemp; - iTemp = (yPriFlag); - - iTemp = (bOFlag) ? (iTemp | OFLAG_SHIFT_VALUE) : iTemp; - iTemp = (bBFlag) ? (iTemp | BFLAG_SHIFT_VALUE) : iTemp; - iTemp = (bRFlag) ? (iTemp | RFLAG_SHIFT_VALUE) : iTemp; - - cb.writeInt(iTemp); - cb.writeInt(iRequestIdNum); - - // Add optional TLV - packOptionalTlv(cb); - - //Update object length now - int length = cb.writerIndex() - objStartIndex; - - //will be helpful during print(). - rpObjHeader.setObjLen((short) length); - - cb.setShort(objLenIndex, (short) length); - return cb.writerIndex(); - } - - /** - * Returns list of optional tlvs. - * - * @param cb of type channel buffer. - * @return llOutOptionalTlv linked list of Optional TLV - * @throws PcepParseException if mandatory fields are missing - */ - protected static LinkedList<PcepValueType> parseOptionalTlv(ChannelBuffer cb) throws PcepParseException { - - LinkedList<PcepValueType> llOutOptionalTlv = new LinkedList<>(); - //Currently no optional TLvs, will be added based on requirements. - return llOutOptionalTlv; - } - - /** - * Returns optional tlvs. - * - * @param cb of type channel buffer - * @return llOptionalTlv linked list of Optional TLV - */ - protected int packOptionalTlv(ChannelBuffer cb) { - - ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator(); - while (listIterator.hasNext()) { - listIterator.next().write(cb); - } - - return cb.writerIndex(); - } - - /** - * Builder class for PCEP rp object. - */ - public static class Builder implements PcepRPObject.Builder { - - private boolean bIsHeaderSet = false; - private boolean bIsRequestIdNumSet = false; - private boolean bIsOFlagSet = false; - private boolean bIsRFlagset = false; - private boolean bIsBFlagSet = false; - private boolean bIsPriFlagSet = false; - - private PcepObjectHeader rpObjHeader; - private int requestIdNum; - private boolean bOFlag; - private boolean bBFlag; - private boolean bRFlag; - private byte yPriFlag; - private LinkedList<PcepValueType> llOptionalTlv = new LinkedList<>(); - - private boolean bIsPFlagSet = false; - private boolean bPFlag; - - private boolean bIsIFlagSet = false; - private boolean bIFlag; - - @Override - public PcepRPObject build() { - PcepObjectHeader lspObjHeader = this.bIsHeaderSet ? this.rpObjHeader : DEFAULT_RP_OBJECT_HEADER; - - int requestIdNum = this.bIsRequestIdNumSet ? this.requestIdNum : DEFAULT_REQUEST_ID_NUM; - boolean bOFlag = this.bIsOFlagSet ? this.bOFlag : DEFAULT_OFLAG; - boolean bBFlag = this.bIsBFlagSet ? this.bBFlag : DEFAULT_BFLAG; - boolean bRFlag = this.bIsRFlagset ? this.bRFlag : DEFAULT_RFLAG; - byte yPriFlag = this.bIsPriFlagSet ? this.yPriFlag : DEFAULT_PRIFLAG; - - if (bIsPFlagSet) { - lspObjHeader.setPFlag(bPFlag); - } - - if (bIsIFlagSet) { - lspObjHeader.setIFlag(bIFlag); - } - - return new PcepRPObjectVer1(lspObjHeader, requestIdNum, bOFlag, bBFlag, bRFlag, yPriFlag, llOptionalTlv); - } - - @Override - public PcepObjectHeader getRPObjHeader() { - return this.rpObjHeader; - } - - @Override - public Builder setRPObjHeader(PcepObjectHeader obj) { - this.rpObjHeader = obj; - this.bIsHeaderSet = true; - return this; - } - - @Override - public int getRequestIdNum() { - return this.requestIdNum; - } - - @Override - public Builder setRequestIdNum(int value) { - this.requestIdNum = value; - this.bIsRequestIdNumSet = true; - return this; - } - - @Override - public Builder setOFlag(boolean value) { - this.bOFlag = value; - this.bIsOFlagSet = true; - return this; - } - - @Override - public boolean getBFlag() { - return this.bBFlag; - } - - @Override - public Builder setBFlag(boolean value) { - this.bBFlag = value; - this.bIsBFlagSet = true; - return this; - } - - @Override - public boolean getRFlag() { - return this.bRFlag; - } - - @Override - public Builder setRFlag(boolean value) { - this.bRFlag = value; - this.bIsRFlagset = true; - return this; - } - - @Override - public byte getPriFlag() { - return this.yPriFlag; - } - - @Override - public Builder setPriFlag(byte value) { - this.yPriFlag = value; - this.bIsPriFlagSet = true; - return this; - } - - @Override - public Builder setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) { - this.llOptionalTlv = llOptionalTlv; - return this; - } - - @Override - public LinkedList<PcepValueType> getOptionalTlv() { - return this.llOptionalTlv; - } - - @Override - public Builder setPFlag(boolean value) { - this.bPFlag = value; - this.bIsPFlagSet = true; - return this; - } - - @Override - public Builder setIFlag(boolean value) { - this.bIFlag = value; - this.bIsIFlagSet = true; - return this; - } - - @Override - public boolean getOFlag() { - return this.bOFlag; - } - - } - - @Override - public LinkedList<PcepValueType> getOptionalTlv() { - return this.llOptionalTlv; - } - - @Override - public void setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) { - this.llOptionalTlv = llOptionalTlv; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("ObjectHeader", rpObjHeader) - .add("OFlag", (bOFlag) ? 1 : 0) - .add("BFlag", (bBFlag) ? 1 : 0) - .add("RFlag", (bRFlag) ? 1 : 0) - .add("PriFlag", yPriFlag) - .add("RequestIdNumber", iRequestIdNum) - .add("OptionalTlv", llOptionalTlv) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepReportMsgVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepReportMsgVer1.java deleted file mode 100644 index 26e48dbd..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepReportMsgVer1.java +++ /dev/null @@ -1,309 +0,0 @@ -/* - * 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.PcepLspObject; -import org.onosproject.pcepio.protocol.PcepMessageReader; -import org.onosproject.pcepio.protocol.PcepMessageWriter; -import org.onosproject.pcepio.protocol.PcepReportMsg; -import org.onosproject.pcepio.protocol.PcepSrpObject; -import org.onosproject.pcepio.protocol.PcepStateReport; -import org.onosproject.pcepio.protocol.PcepType; -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; - -/** - * Provides PCEP report message. - */ -class PcepReportMsgVer1 implements PcepReportMsg { - - // Pcep version: 1 - - /* - * The format of the PCRpt message is as follows: - * <PCRpt Message> ::= <Common Header> - * <state-report-list> - *Where: - * <state-report-list> ::= <state-report>[<state-report-list>] - * <state-report> ::= [<SRP>] - * <LSP> - * <path> - * Where: - * <path> ::= <ERO><attribute-list>[<RRO>] - * Where: - * <attribute-list> is defined in [RFC5440] and extended by PCEP extensions. - * where: - * <attribute-list> ::=[<LSPA>] - * [<BANDWIDTH>] - * [<metric-list>] - * [<IRO>] - * <metric-list> ::=<METRIC>[<metric-list>] - */ - protected static final Logger log = LoggerFactory.getLogger(PcepReportMsgVer1.class); - - public static final byte PACKET_VERSION = 1; - //PACKET_MINIMUM_LENGTH = CommonHeaderLen(4)+LspObjMinLen(8)+EroObjMinLen(12) - public static final int PACKET_MINIMUM_LENGTH = 24; - public static final PcepType MSG_TYPE = PcepType.REPORT; - public static final byte REPORT_OBJ_TYPE = 1; - //Optional TLV - private LinkedList<PcepStateReport> llStateReportList; - - public static final PcepReportMsgVer1.Reader READER = new Reader(); - - /** - * Reader class for reading PCEP report message from channel buffer. - */ - static class Reader implements PcepMessageReader<PcepReportMsg> { - - LinkedList<PcepStateReport> llStateReportList; - - @Override - public PcepReportMsg readFrom(ChannelBuffer cb) throws PcepParseException { - - if (cb.readableBytes() < PACKET_MINIMUM_LENGTH) { - throw new PcepParseException("Received packet size " + cb.readableBytes() - + " is less than the expected size: " + PACKET_MINIMUM_LENGTH); - } - llStateReportList = new LinkedList<>(); - byte version = cb.readByte(); - version = (byte) (version >> PcepMessageVer1.SHIFT_FLAG); - - if (version != PACKET_VERSION) { - throw new PcepParseException(" Invalid version: " + version); - } - - byte type = cb.readByte(); - - if (type != MSG_TYPE.getType()) { - throw new PcepParseException("Unexpected type: " + type); - } - - short length = cb.readShort(); - - if (length < PACKET_MINIMUM_LENGTH) { - throw new PcepParseException("Wrong length. Expected to be >= " + PACKET_MINIMUM_LENGTH + ", was: " - + length); - } - // parse state report list - parseStateReportList(cb); - return new PcepReportMsgVer1(llStateReportList); - } - - // Parse State Report list - public void parseStateReportList(ChannelBuffer cb) throws PcepParseException { - - /* - <state-report-list> - Where: - <state-report-list> ::= <state-report>[<state-report-list>] - <state-report> ::= [<SRP>] - <LSP> - <path> - Where: - <path> ::= <ERO><attribute-list>[<RRO>] - Where: - <attribute-list> is defined in [RFC5440] and extended by PCEP extensions. - - */ - - while (0 < cb.readableBytes()) { - - PcepStateReport pcestateReq = new PcepStateReportVer1(); - - /* - * SRP is optional - * Check whether SRP Object is available, if yes store it. - * First read common object header and check the Object Class whether it is SRP or LSP - * If it is LSP then store only LSP. So, SRP is optional. then read path and store. - * If it is SRP then store SRP and then read LSP, path and store them. - */ - - //mark the reader index to reset - cb.markReaderIndex(); - PcepObjectHeader tempObjHeader = PcepObjectHeader.read(cb); - - byte yObjectClass = tempObjHeader.getObjClass(); - byte yObjectType = tempObjHeader.getObjType(); - - //reset reader index - cb.resetReaderIndex(); - //If SRP present then store it. - if ((PcepSrpObjectVer1.SRP_OBJ_CLASS == yObjectClass) - && (PcepSrpObjectVer1.SRP_OBJ_TYPE == yObjectType)) { - PcepSrpObject srpObj; - srpObj = PcepSrpObjectVer1.read(cb); - pcestateReq.setSrpObject(srpObj); - } - - //store LSP object - PcepLspObject lspObj; - lspObj = PcepLspObjectVer1.read(cb); - pcestateReq.setLspObject(lspObj); - - //store path - PcepStateReport.PcepMsgPath msgPath = new PcepStateReportVer1().new PcepMsgPath().read(cb); - pcestateReq.setMsgPath(msgPath); - - llStateReportList.add(pcestateReq); - } - } - } - - /** - * Constructor to initialize State Report List. - * - * @param llStateReportList list of type Pcep state report - */ - PcepReportMsgVer1(LinkedList<PcepStateReport> llStateReportList) { - this.llStateReportList = llStateReportList; - } - - /** - * Builder class for PCEP Report message. - */ - static class Builder implements PcepReportMsg.Builder { - // Pcep report message fields - LinkedList<PcepStateReport> llStateReportList; - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public PcepType getType() { - return PcepType.REPORT; - } - - @Override - public PcepReportMsg build() { - return new PcepReportMsgVer1(this.llStateReportList); - } - - @Override - public LinkedList<PcepStateReport> getStateReportList() { - return this.llStateReportList; - } - - @Override - public Builder setStateReportList(LinkedList<PcepStateReport> ll) { - this.llStateReportList = ll; - return this; - } - } - - @Override - public void writeTo(ChannelBuffer cb) throws PcepParseException { - WRITER.write(cb, this); - } - - static final Writer WRITER = new Writer(); - - /** - * Writer class for writing PCEP report message to channel buffer. - */ - static class Writer implements PcepMessageWriter<PcepReportMsgVer1> { - - @Override - public void write(ChannelBuffer cb, PcepReportMsgVer1 message) throws PcepParseException { - - int startIndex = cb.writerIndex(); - - // first 3 bits set to version - cb.writeByte((byte) (PACKET_VERSION << PcepMessageVer1.SHIFT_FLAG)); - - // message type - cb.writeByte(MSG_TYPE.getType()); - - // length is length of variable message, will be updated at the end - // Store the position of message - // length in buffer - int msgLenIndex = cb.writerIndex(); - - cb.writeShort((short) 0); - ListIterator<PcepStateReport> listIterator = message.llStateReportList.listIterator(); - - while (listIterator.hasNext()) { - - PcepStateReport stateRpt = listIterator.next(); - PcepSrpObject srpObj = stateRpt.getSrpObject(); - - //SRP object is optional - if (srpObj != null) { - srpObj.write(cb); - } - - //LSP object is mandatory - PcepLspObject lspObj = stateRpt.getLspObject(); - if (lspObj == null) { - throw new PcepParseException("LSP Object is mandatory object for PcRpt message."); - } else { - lspObj.write(cb); - } - - //path is mandatory - PcepStateReport.PcepMsgPath msgPath = stateRpt.getMsgPath(); - if (msgPath == null) { - throw new PcepParseException("Message path is mandatory object for PcRpt message."); - } else { - msgPath.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<PcepStateReport> getStateReportList() { - return this.llStateReportList; - } - - @Override - public void setStateReportList(LinkedList<PcepStateReport> ll) { - this.llStateReportList = ll; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("StateReportList", llStateReportList) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepRroObjectVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepRroObjectVer1.java deleted file mode 100644 index 4df42e05..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepRroObjectVer1.java +++ /dev/null @@ -1,345 +0,0 @@ -/* - * 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.PcepRroObject; -import org.onosproject.pcepio.types.IPv4SubObject; -import org.onosproject.pcepio.types.IPv6SubObject; -import org.onosproject.pcepio.types.LabelSubObject; -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; - -/** - * Provides PCEP RRO object. - */ -public class PcepRroObjectVer1 implements PcepRroObject { - - /* - * rfc3209 - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Object-Class | OT |Res|P|I| Object Length (bytes) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | | - // (Subobjects) // - | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - Each subobject has its own Length - field. The length contains the total length of the subobject in - bytes, including the Type and Length fields. The length MUST always - be a multiple of 4, and at least 4. - - An empty RRO with no subobjects is considered illegal. - Three kinds of subobjects are currently defined. - - Subobject 1: IPv4 address - - 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 | Length | IPv4 address (4 bytes) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | IPv4 address (continued) | Prefix Length | Flags | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - Subobject 2: IPv6 address - - 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 | Length | IPv6 address (16 bytes) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | IPv6 address (continued) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | IPv6 address (continued) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | IPv6 address (continued) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | IPv6 address (continued) | Prefix Length | Flags | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - Subobject 3, Label - - 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 | Length | Flags | C-Type | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Contents of Label Object | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - */ - protected static final Logger log = LoggerFactory.getLogger(PcepRroObjectVer1.class); - - public static final byte RRO_OBJ_TYPE = 1; - public static final byte RRO_OBJ_CLASS = 8; - public static final byte RRO_OBJECT_VERSION = 1; - public static final short RRO_OBJ_MINIMUM_LENGTH = 12; - public static final int OBJECT_HEADER_LENGTH = 4; - public static final int YTYPE_SHIFT_VALUE = 0x7F; - - static final PcepObjectHeader DEFAULT_RRO_OBJECT_HEADER = new PcepObjectHeader(RRO_OBJ_CLASS, RRO_OBJ_TYPE, - PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, RRO_OBJ_MINIMUM_LENGTH); - - private short rroObjType = 0; - private byte length; - private byte prefixLength; - private byte resvd; - PcepObjectHeader rroObjHeader; - private LinkedList<PcepValueType> llSubObjects = new LinkedList<>(); - - /** - * Reset variables. - */ - public PcepRroObjectVer1() { - this.rroObjHeader = null; - this.rroObjType = 0; - this.length = 0; - } - - /** - * constructor to initialize parameters for RRO object. - * - * @param rroObjHeader RRO object header - * @param llSubObjects list of sub objects - */ - public PcepRroObjectVer1(PcepObjectHeader rroObjHeader, LinkedList<PcepValueType> llSubObjects) { - this.rroObjHeader = rroObjHeader; - this.llSubObjects = llSubObjects; - } - - /** - * Returns PCEP RRO Object Header. - * - * @return rroObjHeader RRO Object header - */ - public PcepObjectHeader getRroObjHeader() { - return this.rroObjHeader; - } - - /** - * Sets PCEP RRO Object Header. - * - * @param obj Object header - */ - public void setRroObjHeader(PcepObjectHeader obj) { - this.rroObjHeader = obj; - } - - @Override - public LinkedList<PcepValueType> getSubObjects() { - return this.llSubObjects; - } - - @Override - public void setSubObjects(LinkedList<PcepValueType> llSubObjects) { - this.llSubObjects = llSubObjects; - } - - /** - * Reads the channel buffer and returns object of PcepRroObject. - * - * @param cb of type channel buffer - * @return object of PcepRroObject - * @throws PcepParseException when fails to read from channel buffer - */ - public static PcepRroObject read(ChannelBuffer cb) throws PcepParseException { - - PcepObjectHeader rroObjHeader; - LinkedList<PcepValueType> llSubObjects; - rroObjHeader = PcepObjectHeader.read(cb); - - //take only RroObject buffer. - ChannelBuffer tempCb = cb.readBytes(rroObjHeader.getObjLen() - OBJECT_HEADER_LENGTH); - llSubObjects = parseSubObjects(tempCb); - - return new PcepRroObjectVer1(rroObjHeader, llSubObjects); - } - - /** - * Returns list of sub objects. - * - * @param cb of type channel buffer - * @return list of sub objects - * @throws PcepParseException when fails to parse list of sub objects - */ - protected static LinkedList<PcepValueType> parseSubObjects(ChannelBuffer cb) throws PcepParseException { - - LinkedList<PcepValueType> llSubObjects = new LinkedList<>(); - - while (0 < cb.readableBytes()) { - - //check the Type of the Sub objects - byte yType = cb.readByte(); - yType = (byte) (yType & (YTYPE_SHIFT_VALUE)); - byte hLength = cb.readByte(); - - PcepValueType subObj; - - switch (yType) { - - case IPv4SubObject.TYPE: - subObj = IPv4SubObject.read(cb); - break; - case IPv6SubObject.TYPE: - byte[] ipv6Value = new byte[IPv6SubObject.VALUE_LENGTH]; - cb.readBytes(ipv6Value, 0, IPv6SubObject.VALUE_LENGTH); - subObj = new IPv6SubObject(ipv6Value); - break; - case LabelSubObject.TYPE: - subObj = LabelSubObject.read(cb); - break; - default: - throw new PcepParseException(" Unexpected sub object. Type: " + (int) yType); - } - // Check for the padding - int pad = hLength % 4; - if (0 < pad) { - pad = 4 - pad; - if (pad <= cb.readableBytes()) { - cb.skipBytes(pad); - } - } - llSubObjects.add(subObj); - } - - return llSubObjects; - } - - @Override - public int write(ChannelBuffer cb) throws PcepParseException { - //write Object header - int objStartIndex = cb.writerIndex(); - - int objLenIndex = rroObjHeader.write(cb); - - if (objLenIndex <= 0) { - throw new PcepParseException(" object Length Index" + objLenIndex); - } - - ListIterator<PcepValueType> listIterator = llSubObjects.listIterator(); - - while (listIterator.hasNext()) { - listIterator.next().write(cb); - } - - //Update object length now - int length = cb.writerIndex() - objStartIndex; - cb.setShort(objLenIndex, (short) length); - //will be helpful during print(). - rroObjHeader.setObjLen((short) length); - - //As per RFC the length of object should be multiples of 4 - int pad = length % 4; - - if (0 != pad) { - pad = 4 - pad; - for (int i = 0; i < pad; i++) { - cb.writeByte((byte) 0); - } - length = length + pad; - } - objLenIndex = cb.writerIndex(); - return objLenIndex; - } - - /** - * Builder class for PCEP RRO object. - */ - public static class Builder implements PcepRroObject.Builder { - private boolean bIsHeaderSet = false; - - private PcepObjectHeader rroObjHeader; - LinkedList<PcepValueType> llSubObjects = new LinkedList<>(); - - private boolean bIsPFlagSet = false; - private boolean bPFlag; - - private boolean bIsIFlagSet = false; - private boolean bIFlag; - - @Override - public PcepRroObject build() { - - PcepObjectHeader rroObjHeader = this.bIsHeaderSet ? this.rroObjHeader : DEFAULT_RRO_OBJECT_HEADER; - - if (bIsPFlagSet) { - rroObjHeader.setPFlag(bPFlag); - } - - if (bIsIFlagSet) { - rroObjHeader.setIFlag(bIFlag); - } - return new PcepRroObjectVer1(rroObjHeader, this.llSubObjects); - } - - @Override - public PcepObjectHeader getRroObjHeader() { - return this.rroObjHeader; - } - - @Override - public Builder setRroObjHeader(PcepObjectHeader obj) { - this.rroObjHeader = obj; - this.bIsHeaderSet = true; - return this; - } - - @Override - public LinkedList<PcepValueType> getSubObjects() { - return this.llSubObjects; - } - - @Override - public Builder setSubObjects(LinkedList<PcepValueType> llSubObjects) { - this.llSubObjects = llSubObjects; - 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("SubObjects", llSubObjects) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepSrpObjectVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepSrpObjectVer1.java deleted file mode 100644 index 9c75b3a6..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepSrpObjectVer1.java +++ /dev/null @@ -1,392 +0,0 @@ -/* - * 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.PcepSrpObject; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.onosproject.pcepio.types.PcepValueType; -import org.onosproject.pcepio.types.SymbolicPathNameTlv; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP SRP obejct. - */ -public class PcepSrpObjectVer1 implements PcepSrpObject { - - /* - * ref : draft-ietf-pce-stateful-pce-10, section : 7.2 - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Object-Class | OT |Res|P|I| Object Length (bytes) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Flags |R| - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | SRP-ID-number | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | | - // Optional TLVs // - | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - */ - protected static final Logger log = LoggerFactory.getLogger(PcepSrpObjectVer1.class); - - public static final byte SRP_OBJ_TYPE = 1; - public static final byte SRP_OBJ_CLASS = 33; - public static final byte SRP_OBJECT_VERSION = 1; - public static final short SRP_OBJ_MINIMUM_LENGTH = 12; - public static final int MINIMUM_COMMON_HEADER_LENGTH = 4; - public static final boolean DEFAULT_RFLAG = false; - - static final PcepObjectHeader DEFAULT_SRP_OBJECT_HEADER = new PcepObjectHeader(SRP_OBJ_CLASS, SRP_OBJ_TYPE, - PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, SRP_OBJ_MINIMUM_LENGTH); - - private PcepObjectHeader srpObjHeader; - private static int flags; - private boolean bRFlag; - private int srpId; - - //Optional TLV - private LinkedList<PcepValueType> llOptionalTlv; - public static final byte BBIT_SET = 1; - public static final byte BBIT_RESET = 0; - - /** - * Constructor to initialize member variables. - * - * @param srpObjHeader srp object header - * @param bRFlag R flag - * @param srpID srp Id - * @param llOptionalTlv list of optional tlv - */ - public PcepSrpObjectVer1(PcepObjectHeader srpObjHeader, boolean bRFlag, int srpID, - LinkedList<PcepValueType> llOptionalTlv) { - - this.srpObjHeader = srpObjHeader; - this.bRFlag = bRFlag; - this.srpId = srpID; - this.llOptionalTlv = llOptionalTlv; - } - - /** - * sets the SRP object header. - * - * @param obj srp object header - */ - public void setSrpObjHeader(PcepObjectHeader obj) { - this.srpObjHeader = obj; - } - - @Override - public void setSrpID(int srpID) { - this.srpId = srpID; - } - - @Override - public void setRFlag(boolean bRFlag) { - this.bRFlag = bRFlag; - } - - /** - * Returns SRP object header. - * - * @return srpObjHeader - */ - public PcepObjectHeader getSrpObjHeader() { - return this.srpObjHeader; - } - - @Override - public int getSrpID() { - return this.srpId; - } - - @Override - public boolean getRFlag() { - return this.bRFlag; - } - - @Override - public void setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) { - this.llOptionalTlv = llOptionalTlv; - - } - - @Override - public LinkedList<PcepValueType> getOptionalTlv() { - return this.llOptionalTlv; - } - - /** - * Reads from channel buffer and returns instance of PCEP SRP object. - * - * @param cb of channel buffer. - * @return PCEP SRP object - * @throws PcepParseException when srp object is not received in channel buffer - */ - public static PcepSrpObject read(ChannelBuffer cb) throws PcepParseException { - - log.debug("SrpObject::read"); - PcepObjectHeader srpObjHeader; - boolean bRFlag; - - int srpID; - int flags; - LinkedList<PcepValueType> llOptionalTlv = new LinkedList<>(); - - srpObjHeader = PcepObjectHeader.read(cb); - - if (srpObjHeader.getObjClass() != SRP_OBJ_CLASS) { - throw new PcepParseException("SRP object expected. But received " + srpObjHeader.getObjClass()); - } - - //take only SrpObject buffer. - ChannelBuffer tempCb = cb.readBytes(srpObjHeader.getObjLen() - MINIMUM_COMMON_HEADER_LENGTH); - flags = tempCb.readInt(); - bRFlag = 0 < flags; - srpID = tempCb.readInt(); - - llOptionalTlv = parseOptionalTlv(tempCb); - - return new PcepSrpObjectVer1(srpObjHeader, bRFlag, srpID, llOptionalTlv); - } - - @Override - public int write(ChannelBuffer cb) throws PcepParseException { - - int objStartIndex = cb.writerIndex(); - - //write common header - int objLenIndex = srpObjHeader.write(cb); - - //write Flags - byte bFlag; - - bFlag = (bRFlag) ? BBIT_SET : BBIT_RESET; - - cb.writeInt(bFlag); - - //write SrpId - cb.writeInt(srpId); - - // Add optional TLV - if (!packOptionalTlv(cb)) { - throw new PcepParseException("Failed to write srp tlv to channel buffer."); - } - - //now write SRP Object Length - cb.setShort(objLenIndex, (short) (cb.writerIndex() - objStartIndex)); - - return cb.writerIndex(); - } - - /** - * Parse Optional TLvs from the channel buffer. - * - * @param cb of type channel buffer - * @return list of optional tlvs - * @throws PcepParseException when unsupported tlv is received in srp object - */ - public static LinkedList<PcepValueType> parseOptionalTlv(ChannelBuffer cb) throws PcepParseException { - - LinkedList<PcepValueType> llOutOptionalTlv = new LinkedList<>(); - - while (MINIMUM_COMMON_HEADER_LENGTH <= cb.readableBytes()) { - - PcepValueType tlv; - short hType = cb.readShort(); - short hLength = cb.readShort(); - - switch (hType) { - - case SymbolicPathNameTlv.TYPE: - tlv = SymbolicPathNameTlv.read(cb, hLength); - cb.skipBytes(hLength); - break; - - default: - throw new PcepParseException("Unsupported TLV received in SRP Object."); - } - - // Check for the padding - int pad = hLength % 4; - if (0 < pad) { - pad = 4 - pad; - if (pad <= cb.readableBytes()) { - cb.skipBytes(pad); - } - } - llOutOptionalTlv.add(tlv); - } - - return llOutOptionalTlv; - } - - /** - * Writes optional tlvs to channel buffer. - * - * @param cb of type channel buffer - * @return true if writing optional tlv to channel buffer is success. - */ - protected boolean packOptionalTlv(ChannelBuffer cb) { - - ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator(); - - while (listIterator.hasNext()) { - PcepValueType tlv = listIterator.next(); - - if (tlv == null) { - log.debug("tlv is null from OptionalTlv list"); - continue; - } - tlv.write(cb); - - // need to take care of padding - int pad = tlv.getLength() % 4; - - if (0 != pad) { - pad = 4 - pad; - for (int i = 0; i < pad; ++i) { - cb.writeByte((byte) 0); - } - } - } - - return true; - } - - /** - * Builder class for PCEP srp Object. - */ - public static class Builder implements PcepSrpObject.Builder { - private boolean bIsHeaderSet = false; - private boolean bIsSrpIdset = false; - private boolean bIsRFlagSet = false; - - private PcepObjectHeader srpObjHeader; - private int srpId; - private boolean bRFlag; - LinkedList<PcepValueType> llOptionalTlv = new LinkedList<>(); - - private boolean bIsPFlagSet = false; - private boolean bPFlag; - - private boolean bIsIFlagSet = false; - private boolean bIFlag; - - @Override - public PcepSrpObject build() throws PcepParseException { - PcepObjectHeader srpObjHeader = this.bIsHeaderSet ? this.srpObjHeader : DEFAULT_SRP_OBJECT_HEADER; - - boolean bRFlag = this.bIsRFlagSet ? this.bRFlag : DEFAULT_RFLAG; - - if (!this.bIsSrpIdset) { - throw new PcepParseException("SrpID not set while building SRP Object."); - } - - if (bIsPFlagSet) { - srpObjHeader.setPFlag(bPFlag); - } - - if (bIsIFlagSet) { - srpObjHeader.setIFlag(bIFlag); - } - - return new PcepSrpObjectVer1(srpObjHeader, bRFlag, this.srpId, this.llOptionalTlv); - } - - @Override - public PcepObjectHeader getSrpObjHeader() { - return this.srpObjHeader; - } - - @Override - public Builder setSrpObjHeader(PcepObjectHeader obj) { - this.srpObjHeader = obj; - this.bIsHeaderSet = true; - return this; - } - - @Override - public int getSrpID() { - return this.srpId; - } - - @Override - public Builder setSrpID(int srpID) { - this.srpId = srpID; - this.bIsSrpIdset = true; - return this; - } - - @Override - public boolean getRFlag() { - return this.bRFlag; - } - - @Override - public Builder setRFlag(boolean bRFlag) { - this.bRFlag = bRFlag; - this.bIsRFlagSet = true; - return this; - } - - @Override - public Builder setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) { - this.llOptionalTlv = llOptionalTlv; - return this; - } - - @Override - public LinkedList<PcepValueType> getOptionalTlv() { - return this.llOptionalTlv; - } - - @Override - public Builder setPFlag(boolean value) { - this.bPFlag = value; - this.bIsPFlagSet = true; - return this; - } - - @Override - public Builder setIFlag(boolean value) { - this.bIFlag = value; - this.bIsIFlagSet = true; - return this; - } - - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("RFlag", bRFlag) - .add("SRPID", srpId) - .add("OptionalTlvList", llOptionalTlv) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepStateReportVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepStateReportVer1.java deleted file mode 100644 index ce589bc0..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepStateReportVer1.java +++ /dev/null @@ -1,421 +0,0 @@ -/* - * 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.PcepAttribute; -import org.onosproject.pcepio.protocol.PcepBandwidthObject; -import org.onosproject.pcepio.protocol.PcepEroObject; -import org.onosproject.pcepio.protocol.PcepLspObject; -import org.onosproject.pcepio.protocol.PcepRroObject; -import org.onosproject.pcepio.protocol.PcepSrpObject; -import org.onosproject.pcepio.protocol.PcepStateReport; -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; - -/** - * Provide the State Report for the Pcep Report Message. - * Reference :PCE extensions for stateful draft-ietf-pce-stateful-pce-10. - */ -public class PcepStateReportVer1 implements PcepStateReport { - /* - * <state-report> ::= [<SRP>] - <LSP> - <path> - Where: - <path> ::= <ERO><attribute-list>[<RRO>] - */ - - protected static final Logger log = LoggerFactory.getLogger(PcepStateReport.class); - - public static final int OBJECT_HEADER_LENGTH = 4; - - /** - * Provides PCEP Message path for report message. - */ - public class PcepMsgPath implements PcepStateReport.PcepMsgPath { - - /* - * <path> ::= <ERO><attribute-list>[<RRO>] - */ - - //PcepEroObject - private PcepEroObject eroObj; - private boolean isEroObjectSet; - //PcepAttribute List - private PcepAttribute attrList; - private boolean isAttributeListSet; - //PcepRroObject - private PcepRroObject rroObj; - private boolean isRroObjectSet; - private PcepBandwidthObject bandwidth; - private boolean isBandwidthObjectSet; - - /** - * Constructor to reset the parameters. - */ - public PcepMsgPath() { - eroObj = null; - attrList = null; - rroObj = null; - this.isEroObjectSet = false; - this.isAttributeListSet = false; - this.isRroObjectSet = false; - this.isBandwidthObjectSet = false; - } - - /** - * Constructor to initialize the parameters from PCEP Message path. - * - * @param eroObj PCEP ERO Object - * @param attrList PCEP Attribute - * @param rroObj PCEP Rro Object - * @param bandwidth PCEP bandwidth object - */ - public PcepMsgPath(PcepEroObject eroObj, PcepAttribute attrList, PcepRroObject rroObj, - PcepBandwidthObject bandwidth) { - - this.eroObj = eroObj; - this.attrList = attrList; - this.rroObj = rroObj; - this.bandwidth = bandwidth; - if (rroObj == null) { - this.isRroObjectSet = false; - } else { - this.isRroObjectSet = true; - } - if (eroObj == null) { - this.isEroObjectSet = false; - } else { - this.isEroObjectSet = true; - } - if (attrList == null) { - this.isAttributeListSet = false; - } else { - this.isAttributeListSet = true; - } - if (bandwidth == null) { - this.isBandwidthObjectSet = false; - } else { - this.isBandwidthObjectSet = true; - } - } - - /** - * Returns PcepEroObject. - * - * @return eroObj PCEP ERO Object - */ - @Override - public PcepEroObject getEroObject() { - return this.eroObj; - } - - /** - * Returns PCEP Attribute. - * - * @return attrList Attribute list - */ - @Override - public PcepAttribute getPcepAttribute() { - return this.attrList; - } - - /** - * Returns PcepRroObject. - * - * @return rroObj PCEP RRO Object - */ - @Override - public PcepRroObject getRroObject() { - return this.rroObj; - } - - @Override - public PcepBandwidthObject getBandwidthObject() { - return this.bandwidth; - } - - @Override - public void setEroObject(PcepEroObject eroObj) { - this.eroObj = eroObj; - } - - @Override - public void setPcepAttribute(PcepAttribute attrList) { - this.attrList = attrList; - } - - @Override - public void setRroObject(PcepRroObject rroObj) { - this.rroObj = rroObj; - } - - @Override - public void setBandwidthObject(PcepBandwidthObject bandwidth) { - this.bandwidth = bandwidth; - } - - /** - * Reads all the Objects for PCEP Message Path. - * - * @param bb of type channel buffer - * @return PCEP Message path - * @throws PcepParseException when fails to read pcep message path - */ - @Override - public PcepMsgPath read(ChannelBuffer bb) throws PcepParseException { - - PcepEroObject eroObj; - PcepAttribute attrList; - PcepRroObject rroObj = null; - PcepBandwidthObject bandwidth = null; - - eroObj = PcepEroObjectVer1.read(bb); - attrList = PcepAttributeVer1.read(bb); - - boolean bBreakWhile = false; - while (0 < bb.readableBytes()) { - - if (bb.readableBytes() < OBJECT_HEADER_LENGTH) { - break; - } - bb.markReaderIndex(); - PcepObjectHeader tempObjHeader = PcepObjectHeader.read(bb); - bb.resetReaderIndex(); - byte yObjClass = tempObjHeader.getObjClass(); - - switch (yObjClass) { - case PcepRroObjectVer1.RRO_OBJ_CLASS: - rroObj = PcepRroObjectVer1.read(bb); - break; - case PcepInterLayerObjectVer1.INTER_LAYER_OBJ_CLASS: - bb.skipBytes(tempObjHeader.getObjLen()); - break; - case PcepBandwidthObjectVer1.BANDWIDTH_OBJ_CLASS: - bandwidth = PcepBandwidthObjectVer1.read(bb); - break; - default: - //Otherthan above objects handle those objects in caller. - bBreakWhile = true; - break; - } - if (bBreakWhile) { - break; - } - } - return new PcepMsgPath(eroObj, attrList, rroObj, bandwidth); - } - - /** - * Writes all the objects for PCEP message path. - * - * @param bb of type channel buffer. - * @return object length index - * @throws PcepParseException when fails to write to channel buffer - */ - @Override - public int write(ChannelBuffer bb) throws PcepParseException { - int iLenStartIndex = bb.writerIndex(); - - //write Object header - if (this.isEroObjectSet) { - this.eroObj.write(bb); - } else { - throw new PcepParseException("Ero object is not set in path"); - } - - if (this.isAttributeListSet) { - this.attrList.write(bb); - } - - // RRO is optional check and read - if (this.isRroObjectSet) { - this.rroObj.write(bb); - // bandwidth should come along with RRO. - if (this.isBandwidthObjectSet) { - this.bandwidth.write(bb); - } - } - return bb.writerIndex() - iLenStartIndex; - } - - @Override - public String toString() { - ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass()); - - if (attrList != null) { - toStrHelper.add("AttributeList", attrList); - } - if (rroObj instanceof PcepRroObjectVer1) { - toStrHelper.add("RroObject", rroObj); - } - if (bandwidth instanceof PcepBandwidthObjectVer1) { - toStrHelper.add("bandwidthObject", bandwidth); - } - return toStrHelper.toString(); - } - } - - //SRP Object - private PcepSrpObject srpObject; - //LSP Object - private PcepLspObject lspObject; - //PcepMsgPath - private PcepStateReport.PcepMsgPath msgPath; - - /** - * Constructor to reset objects. - */ - public PcepStateReportVer1() { - this.srpObject = null; - this.lspObject = null; - this.msgPath = null; - } - - public PcepStateReportVer1(PcepSrpObject srpObject, PcepLspObject lspObject, PcepStateReport.PcepMsgPath msgPath) { - this.srpObject = srpObject; - this.lspObject = lspObject; - this.msgPath = msgPath; - } - - @Override - public PcepSrpObject getSrpObject() { - return srpObject; - } - - @Override - public PcepLspObject getLspObject() { - return lspObject; - } - - @Override - public PcepStateReport.PcepMsgPath getMsgPath() { - return msgPath; - } - - @Override - public void setSrpObject(PcepSrpObject srpObj) { - this.srpObject = srpObj; - } - - @Override - public void setLspObject(PcepLspObject lspObject) { - this.lspObject = lspObject; - } - - @Override - public void setMsgPath(PcepStateReport.PcepMsgPath msgPath) { - this.msgPath = msgPath; - } - - /** - * Builder class for PCEP state report. - */ - public static class Builder implements PcepStateReport.Builder { - - private boolean bIsSRPObjectSet = false; - private boolean bIsLSPObjectSet = false; - private boolean bIsPcepMsgPathSet = false; - - //PCEP SRP Object - private PcepSrpObject srpObject; - //PCEP LSP Object - private PcepLspObject lspObject; - //PCEP Attribute list - private PcepStateReport.PcepMsgPath msgPath; - - @Override - public PcepStateReport build() throws PcepParseException { - - //PCEP SRP Object - PcepSrpObject srpObject = null; - //PCEP LSP Object - PcepLspObject lspObject = null; - //PCEP Attribute list - PcepStateReport.PcepMsgPath msgPath = null; - - if (this.bIsSRPObjectSet) { - srpObject = this.srpObject; - } - - if (!this.bIsLSPObjectSet) { - throw new PcepParseException(" LSP Object NOT Set while building PcepStateReport."); - } else { - lspObject = this.lspObject; - } - if (!this.bIsPcepMsgPathSet) { - throw new PcepParseException(" Message Path NOT Set while building PcepStateReport."); - } else { - msgPath = this.msgPath; - } - - return new PcepStateReportVer1(srpObject, lspObject, msgPath); - } - - @Override - public PcepSrpObject getSrpObject() { - return this.srpObject; - } - - @Override - public PcepLspObject getLspObject() { - return this.lspObject; - } - - @Override - public PcepStateReport.PcepMsgPath getMsgPath() { - return this.msgPath; - } - - @Override - public Builder setSrpObject(PcepSrpObject srpobj) { - this.srpObject = srpobj; - this.bIsSRPObjectSet = true; - return this; - } - - @Override - public Builder setLspObject(PcepLspObject lspObject) { - this.lspObject = lspObject; - this.bIsLSPObjectSet = true; - return this; - } - - @Override - public Builder setMsgPath(PcepStateReport.PcepMsgPath msgPath) { - this.msgPath = msgPath; - this.bIsPcepMsgPathSet = true; - return this; - } - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .omitNullValues() - .add("SrpObject", srpObject) - .add("LspObject", lspObject) - .add("MsgPath", msgPath) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepTEObjectVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepTEObjectVer1.java deleted file mode 100644 index b1c69406..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepTEObjectVer1.java +++ /dev/null @@ -1,506 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onosproject.pcepio.protocol.ver1; - -import java.util.LinkedList; -import java.util.ListIterator; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepTEObject; -import org.onosproject.pcepio.types.LocalTENodeDescriptorsTlv; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.onosproject.pcepio.types.PcepValueType; -import org.onosproject.pcepio.types.RemoteTENodeDescriptorsTlv; -import org.onosproject.pcepio.types.RoutingUniverseTlv; -import org.onosproject.pcepio.types.TELinkAttributesTlv; -import org.onosproject.pcepio.types.TELinkDescriptorsTlv; -import org.onosproject.pcepio.types.TENodeAttributesTlv; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP TE Object. - */ -public class PcepTEObjectVer1 implements PcepTEObject { - /* - * - reference: PCEP Extension for Transporting TE Data draft-dhodylee-pce-pcep-te-data-extn-02. - TE Object-Class is [TBD6]. - - Two Object-Type values are defined for the TE object: - - o TE Node: TE Object-Type is 1. - - o TE Link: TE Object-Type is 2. - - The format of the TE object body is as follows: - - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Protocol-ID | Flag |R|S| - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | TE-ID | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // TLVs // - | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - - protected static final Logger log = LoggerFactory.getLogger(PcepTEObjectVer1.class); - - public static final byte TE_OBJ_TYPE_NODE_VALUE = 1; - public static final byte TE_OBJ_TYPE_LINK_VALUE = 2; - - public static final byte TE_OBJ_CLASS = 101; //TBD6 in RFC. - public static final byte TE_OBJECT_VERSION = 1; - - // TE_OBJ_MINIMUM_LENGTH = TEObjectHeaderLen(4)+ TEObjectLen(8) - public static final short TE_OBJ_MINIMUM_LENGTH = 12; - - // Signaled ,all default values to be checked. - public static final byte DEFAULT_PROTOCOL_ID = 1; //IS-IS Level 1 - public static final boolean DEFAULT_R_FLAG = false; - public static final boolean DEFAULT_S_FLAG = false; - public static final int DEFAULT_TE_ID = 0; - - public static final int OBJECT_HEADER_LENGTH = 4; - public static final int RIGHT_SHIFT_ONE = 1; - public static final int RIGHT_FIRST_FLAG = 0x1; - public static final int FLAG_SET_R_FLAG = 0x2; - public static final int FLAG_SET_S_FLAG = 0x1; - public static final int MINIMUM_COMMON_HEADER_LENGTH = 4; - public static final int MINIMUM_TLV_HEADER_LENGTH = 4; - - public static final PcepObjectHeader DEFAULT_TE_OBJECT_HEADER = new PcepObjectHeader(TE_OBJ_CLASS, - TE_OBJ_TYPE_NODE_VALUE, PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, - TE_OBJ_MINIMUM_LENGTH); - - private PcepObjectHeader teObjHeader; - private byte yProtocolId; - // 2-flags - private boolean bRFlag; - private boolean bSFlag; - private int iTEId; - // Optional TLV - private LinkedList<PcepValueType> llOptionalTlv; - - /** - * Constructor to initialize variables. - * - * @param teObjHeader TE Object header - * @param yProtocolId Protocol-ID - * @param bRFlag R-flag - * @param bSFlag S-flag - * @param iTEId TE-ID - * @param llOptionalTlv linked list of Optional TLV - */ - public PcepTEObjectVer1(PcepObjectHeader teObjHeader, byte yProtocolId, boolean bRFlag, boolean bSFlag, int iTEId, - LinkedList<PcepValueType> llOptionalTlv) { - - this.teObjHeader = teObjHeader; - this.yProtocolId = yProtocolId; - this.bRFlag = bRFlag; - this.bSFlag = bSFlag; - this.iTEId = iTEId; - this.llOptionalTlv = llOptionalTlv; - } - - @Override - public PcepObjectHeader getTEObjHeader() { - return this.teObjHeader; - } - - @Override - public void setTEObjHeader(PcepObjectHeader obj) { - this.teObjHeader = obj; - } - - @Override - public byte getProtocolId() { - return this.yProtocolId; - } - - @Override - public void setProtocolId(byte yProtId) { - this.yProtocolId = yProtId; - } - - @Override - public boolean getRFlag() { - return this.bRFlag; - } - - @Override - public void setRFlag(boolean bRFlag) { - this.bRFlag = bRFlag; - } - - @Override - public boolean getSFlag() { - return this.bSFlag; - } - - @Override - public void setSFlag(boolean bSFlag) { - this.bSFlag = bSFlag; - } - - @Override - public int getTEId() { - return this.iTEId; - } - - @Override - public void setTEId(int iTEId) { - this.iTEId = iTEId; - } - - @Override - public LinkedList<PcepValueType> getOptionalTlv() { - return this.llOptionalTlv; - } - - @Override - public void setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) { - this.llOptionalTlv = llOptionalTlv; - } - - /** - * Reads from the channel buffer and returns Object of PcepTEObject. - * - * @param cb of type channel buffer - * @return Object of PcepTEObject - * @throws PcepParseException if mandatory fields are missing - */ - public static PcepTEObject read(ChannelBuffer cb) throws PcepParseException { - log.debug("read"); - - PcepObjectHeader teObjHeader; - byte yProtocolId; - // 2-flags - boolean bRFlag; - boolean bSFlag; - int iTEId; - LinkedList<PcepValueType> llOptionalTlv; - - teObjHeader = PcepObjectHeader.read(cb); - - //take only TEObject buffer. - ChannelBuffer tempCb = cb.readBytes(teObjHeader.getObjLen() - OBJECT_HEADER_LENGTH); - - yProtocolId = tempCb.readByte(); - //ignore first two bytes of Flags - tempCb.readShort(); - - Integer iTemp = (int) tempCb.readByte(); //read 3rd byte Flag - bSFlag = (iTemp & FLAG_SET_S_FLAG) == FLAG_SET_S_FLAG; - bRFlag = (iTemp & FLAG_SET_R_FLAG) == FLAG_SET_R_FLAG; - - iTEId = tempCb.readInt(); - - // parse optional TLV - llOptionalTlv = parseOptionalTlv(tempCb); - - return new PcepTEObjectVer1(teObjHeader, yProtocolId, bRFlag, bSFlag, iTEId, llOptionalTlv); - } - - @Override - public int write(ChannelBuffer cb) throws PcepParseException { - - //write Object header - int objStartIndex = cb.writerIndex(); - int objLenIndex = teObjHeader.write(cb); - - if (objLenIndex <= 0) { - throw new PcepParseException("ObjectLength Index is " + objLenIndex); - } - - //write Protocol ID - cb.writeByte(this.yProtocolId); - - //write Flag - cb.writeShort(0); - - byte bTemp = 0; - if (bSFlag) { - bTemp = FLAG_SET_S_FLAG; - } - - if (bRFlag) { - bTemp = (byte) (bTemp | FLAG_SET_R_FLAG); - } - cb.writeByte(bTemp); - - //write TEId - cb.writeInt(iTEId); - - // Add optional TLV - packOptionalTlv(cb); - - //Update object length now - int length = cb.writerIndex() - objStartIndex; - - //will be helpful during print(). - teObjHeader.setObjLen((short) length); - - cb.setShort(objLenIndex, (short) length); - - return cb.writerIndex(); - } - - /** - * Returns Linked list of PCEP Value Type. - * - * @param cb of channel buffer - * @return Linked list of PCEP Value Type - * @throws PcepParseException if mandatory fields are missing - */ - protected static LinkedList<PcepValueType> parseOptionalTlv(ChannelBuffer cb) throws PcepParseException { - - LinkedList<PcepValueType> llOutOptionalTlv; - - llOutOptionalTlv = new LinkedList<>(); - - while (MINIMUM_TLV_HEADER_LENGTH <= cb.readableBytes()) { - - PcepValueType tlv; - short hType = cb.readShort(); - short hLength = cb.readShort(); - long lValue = 0; - - switch (hType) { - - case RoutingUniverseTlv.TYPE: - lValue = cb.readLong(); - tlv = new RoutingUniverseTlv(lValue); - break; - case LocalTENodeDescriptorsTlv.TYPE: - tlv = LocalTENodeDescriptorsTlv.read(cb, hLength); - break; - case RemoteTENodeDescriptorsTlv.TYPE: - tlv = RemoteTENodeDescriptorsTlv.read(cb, hLength); - break; - case TELinkDescriptorsTlv.TYPE: - tlv = TELinkDescriptorsTlv.read(cb, hLength); - break; - case TENodeAttributesTlv.TYPE: - tlv = TENodeAttributesTlv.read(cb, hLength); - break; - case TELinkAttributesTlv.TYPE: - tlv = TELinkAttributesTlv.read(cb, hLength); - break; - default: - throw new PcepParseException("Unsupported TLV type :" + hType); - } - - // Check for the padding - int pad = hLength % 4; - if (0 < pad) { - pad = 4 - pad; - if (pad <= cb.readableBytes()) { - cb.skipBytes(pad); - } - } - - llOutOptionalTlv.add(tlv); - } - - if (0 < cb.readableBytes()) { - - throw new PcepParseException("Optional Tlv parsing error. Extra bytes received."); - } - return llOutOptionalTlv; - } - - /** - * Returns the writer index. - * - * @param cb of type channel buffer - * @return the writer index. - */ - protected int packOptionalTlv(ChannelBuffer cb) { - - ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator(); - - while (listIterator.hasNext()) { - PcepValueType tlv = listIterator.next(); - - if (tlv == null) { - log.debug("TLV is null from OptionalTlv list"); - continue; - } - tlv.write(cb); - - // need to take care of padding - int pad = tlv.getLength() % 4; - - if (0 != pad) { - pad = 4 - pad; - for (int i = 0; i < pad; ++i) { - cb.writeByte((byte) 0); - } - } - } - return cb.writerIndex(); - } - - /** - * Builder class for PCEP te object. - */ - public static class Builder implements PcepTEObject.Builder { - private boolean bIsHeaderSet = false; - private boolean bIsProtocolIdSet = false; - private boolean bIsRFlagSet = false; - private boolean bIsSFlagSet = false; - private boolean bIsTEIdSet = false; - - private PcepObjectHeader teObjHeader; - private byte yProtocolId; - private boolean bRFlag; - private boolean bSFlag; - private int iTEId; - private LinkedList<PcepValueType> llOptionalTlv = new LinkedList<>(); - - private boolean bIsPFlagSet = false; - private boolean bPFlag; - - private boolean bIsIFlagSet = false; - private boolean bIFlag; - - @Override - public PcepTEObject build() { - PcepObjectHeader teObjHeader = this.bIsHeaderSet ? this.teObjHeader : DEFAULT_TE_OBJECT_HEADER; - - byte yProtocolId = this.bIsProtocolIdSet ? this.yProtocolId : DEFAULT_PROTOCOL_ID; - boolean bRFlag = this.bIsRFlagSet ? this.bRFlag : DEFAULT_R_FLAG; - boolean bSFlag = this.bIsSFlagSet ? this.bSFlag : DEFAULT_S_FLAG; - int iTEId = this.bIsTEIdSet ? this.iTEId : DEFAULT_TE_ID; - - if (bIsPFlagSet) { - teObjHeader.setPFlag(bPFlag); - } - - if (bIsIFlagSet) { - teObjHeader.setIFlag(bIFlag); - } - - return new PcepTEObjectVer1(teObjHeader, yProtocolId, bRFlag, bSFlag, iTEId, llOptionalTlv); - - } - - @Override - public PcepObjectHeader getTEObjHeader() { - return this.teObjHeader; - } - - @Override - public Builder setTEObjHeader(PcepObjectHeader obj) { - this.teObjHeader = obj; - this.bIsHeaderSet = true; - return this; - } - - @Override - public byte getProtocolId() { - return this.yProtocolId; - } - - @Override - public Builder setProtocolId(byte yProtId) { - this.yProtocolId = yProtId; - this.bIsProtocolIdSet = true; - return this; - } - - @Override - public boolean getRFlag() { - return this.bRFlag; - } - - @Override - public Builder setRFlag(boolean bRFlag) { - this.bRFlag = bRFlag; - this.bIsRFlagSet = true; - return this; - } - - @Override - public boolean getSFlag() { - return this.bSFlag; - } - - @Override - public Builder setSFlag(boolean bSFlag) { - this.bSFlag = bSFlag; - this.bIsSFlagSet = true; - return this; - } - - @Override - public int getTEId() { - return this.iTEId; - } - - @Override - public Builder setTEId(int iTEId) { - this.iTEId = iTEId; - this.bIsTEIdSet = true; - return this; - } - - @Override - public LinkedList<PcepValueType> getOptionalTlv() { - return this.llOptionalTlv; - } - - @Override - public Builder setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) { - this.llOptionalTlv = llOptionalTlv; - return this; - } - - @Override - public Builder setPFlag(boolean value) { - this.bPFlag = value; - this.bIsPFlagSet = true; - return this; - } - - @Override - public Builder setIFlag(boolean value) { - this.bIFlag = value; - this.bIsIFlagSet = true; - return this; - } - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("ObjectHeader", teObjHeader) - .add("ProtocolId", yProtocolId) - .add("RFlag", (bRFlag) ? 1 : 0) - .add("SFlag", (bSFlag) ? 1 : 0) - .add("TeId", iTEId) - .add("OptionalTlv", llOptionalTlv) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepTEReportMsgVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepTEReportMsgVer1.java deleted file mode 100644 index 92833080..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepTEReportMsgVer1.java +++ /dev/null @@ -1,225 +0,0 @@ -/* - * 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.PcepMessageReader; -import org.onosproject.pcepio.protocol.PcepMessageWriter; -import org.onosproject.pcepio.protocol.PcepTEObject; -import org.onosproject.pcepio.protocol.PcepTEReportMsg; -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; - -/** - * Provides PCEP TE Report Message. - */ -class PcepTEReportMsgVer1 implements PcepTEReportMsg { - - /* - * Ref : draft-dhodylee-pce-pcep-te-data-extn-02, section 8.1 - - <TERpt Message> ::= <Common Header> - <te-report-list> - Where: - <te-report-list> ::= <TE>[<te-report-list>] - */ - - private static final Logger log = LoggerFactory.getLogger(PcepTEReportMsgVer1.class); - //PACKET_MINIMUM_LENGTH = CommonHeaderLen(4)+TEObjMinLen(12) - public static final int PACKET_MINIMUM_LENGTH = 16; - public static final PcepType MSG_TYPE = PcepType.TE_REPORT; - // <te-report-list> - private LinkedList<PcepTEObject> teReportList; - - public static final PcepTEReportMsgVer1.Reader READER = new Reader(); - - /** - * Reader class for reading PCPE te report message form channel buffer. - */ - static class Reader implements PcepMessageReader<PcepTEReportMsg> { - - LinkedList<PcepTEObject> teReportList; - - @Override - public PcepTEReportMsg readFrom(ChannelBuffer cb) throws PcepParseException { - - if (cb.readableBytes() < PACKET_MINIMUM_LENGTH) { - return null; - } - - teReportList = new LinkedList<>(); - - byte version = cb.readByte(); - version = (byte) (version >> PcepMessageVer1.SHIFT_FLAG); - if (version != PcepMessageVer1.PACKET_VERSION) { - throw new PcepParseException("Wrong version. Expected=PcepVersion.PCEP_1(1), got=" + version); - } - - byte type = cb.readByte(); - if (type != MSG_TYPE.getType()) { - throw new PcepParseException("Wrong type. Expected=PcepType.TE_REPORT(14), 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 state report list - parseTEReportList(cb); - - return new PcepTEReportMsgVer1(teReportList); - } - - /** - * Parse te-report-list. - * - * @param cb input Channel Buffer - * @throws PcepParseException when fails to parse TE Report list. - */ - public void parseTEReportList(ChannelBuffer cb) throws PcepParseException { - // <te-report-list> ::= <TE>[<te-report-list>] - - while (0 < cb.readableBytes()) { - //store TE objectS - if (!teReportList.add(PcepTEObjectVer1.read(cb))) { - throw new PcepParseException("Failed to add TE object to TE report list"); - } - } - } - } - - /** - * Constructor to initialize TE Report List. - * - * @param teReportList list of PCEP TE Object - */ - PcepTEReportMsgVer1(LinkedList<PcepTEObject> teReportList) { - this.teReportList = teReportList; - } - - /** - * Builder class for PCEP te report message. - */ - static class Builder implements PcepTEReportMsg.Builder { - // PCEP TE Report message fields - LinkedList<PcepTEObject> teReportList; - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public PcepType getType() { - return PcepType.TE_REPORT; - } - - @Override - public PcepTEReportMsg build() { - return new PcepTEReportMsgVer1(this.teReportList); - } - - @Override - public LinkedList<PcepTEObject> getTEReportList() { - return this.teReportList; - } - - @Override - public Builder setTEReportList(LinkedList<PcepTEObject> ll) { - this.teReportList = ll; - return this; - } - } - - @Override - public void writeTo(ChannelBuffer bb) throws PcepParseException { - WRITER.write(bb, this); - } - - static final Writer WRITER = new Writer(); - - /** - * Writer class for writing PCEP te report message to channel buffer. - */ - static class Writer implements PcepMessageWriter<PcepTEReportMsgVer1> { - - @Override - public void write(ChannelBuffer bb, PcepTEReportMsgVer1 message) throws PcepParseException { - - int startIndex = bb.writerIndex(); - - // first 3 bits set to version - bb.writeByte((byte) (PcepMessageVer1.PACKET_VERSION << PcepMessageVer1.SHIFT_FLAG)); - - // message type - bb.writeByte(MSG_TYPE.getType()); - - // Length of the message will be updated at the end - // First write with 0s - int msgLenIndex = bb.writerIndex(); - bb.writeShort((short) 0); - - ListIterator<PcepTEObject> listIterator = message.teReportList.listIterator(); - - while (listIterator.hasNext()) { - PcepTEObject teObj = listIterator.next(); - teObj.write(bb); - } - - // update message length field - int length = bb.writerIndex() - startIndex; - bb.setShort(msgLenIndex, (short) length); - } - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public PcepType getType() { - return MSG_TYPE; - } - - @Override - public LinkedList<PcepTEObject> getTEReportList() { - return this.teReportList; - } - - @Override - public void setTEReportList(LinkedList<PcepTEObject> ll) { - this.teReportList = ll; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("TeReportList", teReportList) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepUpdateMsgVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepUpdateMsgVer1.java deleted file mode 100644 index 53c66872..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepUpdateMsgVer1.java +++ /dev/null @@ -1,300 +0,0 @@ -/* - * 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.PcepLspObject; -import org.onosproject.pcepio.protocol.PcepMessageReader; -import org.onosproject.pcepio.protocol.PcepMessageWriter; -import org.onosproject.pcepio.protocol.PcepMsgPath; -import org.onosproject.pcepio.protocol.PcepSrpObject; -import org.onosproject.pcepio.protocol.PcepType; -import org.onosproject.pcepio.protocol.PcepUpdateMsg; -import org.onosproject.pcepio.protocol.PcepUpdateRequest; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP update message. - */ - -class PcepUpdateMsgVer1 implements PcepUpdateMsg { - - // Pcep version: 1 - - /* The format of the PCUpd message is as follows: - * <PCUpd Message> ::= <Common Header> - * <update-request-list> - * Where: - * <update-request-list> ::= <update-request>[<update-request-list>] - * <update-request> ::= <SRP> - * <LSP> - * <path> - * Where: - * <path> ::= <ERO><attribute-list> - * Where: - * <attribute-list> is defined in [RFC5440] and extended by PCEP extensions. - * where: - * <attribute-list> ::=[<LSPA>] - * [<BANDWIDTH>] - * [<metric-list>] - * [<IRO>] - * <metric-list> ::=<METRIC>[<metric-list>] - * - * 0 1 2 3 - * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Ver | Flags | Message-Type | Message-Length | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | | - * // UPDATE REQUEST LIST // - * | | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * - * Reference:Internet-Draft-PCEP Extensions-for-Stateful-PCE-10 - */ - - protected static final Logger log = LoggerFactory.getLogger(PcepUpdateMsgVer1.class); - - public static final byte PACKET_VERSION = 1; - // UpdateMsgMinLength = SrpObjMinLentgh(12)+LspObjMinLength(8)+EroObjMinLength(12)+ CommonHeaderLength(4) - public static final short PACKET_MINIMUM_LENGTH = 36; - public static final PcepType MSG_TYPE = PcepType.UPDATE; - //Update Request List - private LinkedList<PcepUpdateRequest> llUpdateRequestList; - - public static final PcepUpdateMsgVer1.Reader READER = new Reader(); - - /** - * Reader reads UpdateMessage from the channel. - */ - static class Reader implements PcepMessageReader<PcepUpdateMsg> { - - LinkedList<PcepUpdateRequest> llUpdateRequestList; - - @Override - public PcepUpdateMsg readFrom(ChannelBuffer cb) throws PcepParseException { - - if (cb.readableBytes() < PACKET_MINIMUM_LENGTH) { - throw new PcepParseException("Readable bytes is less than update message minimum length"); - } - - llUpdateRequestList = new LinkedList<>(); - - // 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 == 11 - byte type = cb.readByte(); - if (type != MSG_TYPE.getType()) { - throw new PcepParseException("Wrong type. Expected=PcepType.UPDATE(11), got=" + type); - } - short length = cb.readShort(); - if (length < PACKET_MINIMUM_LENGTH) { - throw new PcepParseException("Wrong length. Expected to be >= " + PACKET_MINIMUM_LENGTH + ", was: " - + length); - } - - log.debug("reading update message of length " + length); - - // parse Update Request list - if (!parseUpdateRequestList(cb)) { - throw new PcepParseException("parsing Update Request List Failed."); - } - - return new PcepUpdateMsgVer1(llUpdateRequestList); - } - - /** - * Parse update request list. - * - * @param cb of type channel buffer - * @return true after parsing Update Request List - * @throws PcepParseException while parsing update request list from channel buffer - */ - public boolean parseUpdateRequestList(ChannelBuffer cb) throws PcepParseException { - - /* <update-request-list> - * Where: - * <update-request-list> ::= <update-request>[<update-request-list>] - * <update-request> ::= <SRP> - * <LSP> - * <path> - * Where: - * <path> ::= <ERO><attribute-list> - * Where: - * <attribute-list> is defined in [RFC5440] and extended by PCEP extensions. - */ - - while (0 < cb.readableBytes()) { - - PcepUpdateRequest pceUpdateReq = new PcepUpdateRequestVer1(); - - //Read SRP Object and Store it. - PcepSrpObject srpObj; - srpObj = PcepSrpObjectVer1.read(cb); - pceUpdateReq.setSrpObject(srpObj); - - //Read LSP object and Store it. - PcepLspObject lspObj; - lspObj = PcepLspObjectVer1.read(cb); - pceUpdateReq.setLspObject(lspObj); - - // Read Msg Path and store it. - PcepMsgPath msgPath = new PcepMsgPathVer1().read(cb); - pceUpdateReq.setMsgPath(msgPath); - - llUpdateRequestList.add(pceUpdateReq); - } - return true; - } - } - - /** - * Constructor to initialize llUpdateRequestList. - * - * @param llUpdateRequestList list of PcepUpdateRequest. - */ - PcepUpdateMsgVer1(LinkedList<PcepUpdateRequest> llUpdateRequestList) { - this.llUpdateRequestList = llUpdateRequestList; - } - - /** - * Builder class for PCPE update message. - */ - static class Builder implements PcepUpdateMsg.Builder { - - // PCEP report message fields - LinkedList<PcepUpdateRequest> llUpdateRequestList; - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public PcepType getType() { - return PcepType.UPDATE; - } - - @Override - public PcepUpdateMsg build() { - return new PcepUpdateMsgVer1(this.llUpdateRequestList); - } - - @Override - public LinkedList<PcepUpdateRequest> getUpdateRequestList() { - return this.llUpdateRequestList; - } - - @Override - public Builder setUpdateRequestList(LinkedList<PcepUpdateRequest> llUpdateRequestList) { - this.llUpdateRequestList = llUpdateRequestList; - return this; - } - - } - - @Override - public void writeTo(ChannelBuffer cb) throws PcepParseException { - WRITER.write(cb, this); - } - - static final Writer WRITER = new Writer(); - - /** - * Writer writes UpdateMessage to the channel buffer. - */ - static class Writer implements PcepMessageWriter<PcepUpdateMsgVer1> { - - @Override - public void write(ChannelBuffer cb, PcepUpdateMsgVer1 message) throws PcepParseException { - - int startIndex = cb.writerIndex(); - // first 3 bits set to version - cb.writeByte((byte) (PACKET_VERSION << PcepMessageVer1.SHIFT_FLAG)); - // message type - cb.writeByte(MSG_TYPE.getType()); - /* length is length of variable message, will be updated at the end - * Store the position of message - * length in buffer - */ - int msgLenIndex = cb.writerIndex(); - - cb.writeShort((short) 0); - ListIterator<PcepUpdateRequest> listIterator = message.llUpdateRequestList.listIterator(); - - while (listIterator.hasNext()) { - - PcepUpdateRequest updateReq = listIterator.next(); - - //SRP object is mandatory - PcepSrpObject srpObj = updateReq.getSrpObject(); - srpObj.write(cb); - - //LSP object is mandatory - PcepLspObject lspObj = updateReq.getLspObject(); - lspObj.write(cb); - - //PATH object is mandatory - PcepMsgPath msgPath = updateReq.getMsgPath(); - msgPath.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<PcepUpdateRequest> getUpdateRequestList() { - return this.llUpdateRequestList; - } - - @Override - public void setUpdateRequestList(LinkedList<PcepUpdateRequest> llUpdateRequestList) { - this.llUpdateRequestList = llUpdateRequestList; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("UpdateRequestList", llUpdateRequestList) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepUpdateRequestVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepUpdateRequestVer1.java deleted file mode 100644 index 0bcc2907..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepUpdateRequestVer1.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * 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.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepLspObject; -import org.onosproject.pcepio.protocol.PcepMsgPath; -import org.onosproject.pcepio.protocol.PcepSrpObject; -import org.onosproject.pcepio.protocol.PcepUpdateRequest; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP Update Request List. - */ -public class PcepUpdateRequestVer1 implements PcepUpdateRequest { - - /* <update-request-list> - * Where: - * <update-request-list> ::= <update-request>[<update-request-list>] - * <update-request> ::= <SRP> - * <LSP> - * <path> - * Where: - * <path> ::= <ERO><attribute-list> - * Where: - * <attribute-list> is defined in [RFC5440] and extended by PCEP extensions. - */ - - protected static final Logger log = LoggerFactory.getLogger(PcepUpdateRequestVer1.class); - - //PCEP SRP Object - private PcepSrpObject srpObject; - //PCEP LSP Object - private PcepLspObject lspObject; - //PCEP Message path - private PcepMsgPath msgPath; - - /** - * Default constructor. - */ - public PcepUpdateRequestVer1() { - srpObject = null; - lspObject = null; - msgPath = null; - } - - /** - * Constructor to initialize all member variables. - * - * @param srpObject srp object - * @param lspObject lsp object - * @param msgPath message path object - */ - public PcepUpdateRequestVer1(PcepSrpObject srpObject, PcepLspObject lspObject, PcepMsgPath msgPath) { - this.srpObject = srpObject; - this.lspObject = lspObject; - this.msgPath = msgPath; - } - - @Override - public PcepSrpObject getSrpObject() { - return srpObject; - } - - @Override - public PcepLspObject getLspObject() { - return lspObject; - } - - @Override - public PcepMsgPath getMsgPath() { - return msgPath; - } - - @Override - public void setSrpObject(PcepSrpObject srpObject) { - this.srpObject = srpObject; - - } - - @Override - public void setLspObject(PcepLspObject lspObject) { - this.lspObject = lspObject; - } - - @Override - public void setMsgPath(PcepMsgPath msgPath) { - this.msgPath = msgPath; - } - - /** - * Builder class for PCEP update request. - */ - public static class Builder implements PcepUpdateRequest.Builder { - - private boolean bIsSRPObjectSet = false; - private boolean bIsLSPObjectSet = false; - private boolean bIsPcepMsgPathSet = false; - - //PCEP SRP Object - private PcepSrpObject srpObject; - //PCEP LSP Object - private PcepLspObject lspObject; - //PCEP Attribute list - private PcepMsgPath msgPath; - - @Override - public PcepUpdateRequest build() throws PcepParseException { - - //PCEP SRP Object - PcepSrpObject srpObject = null; - //PCEP LSP Object - PcepLspObject lspObject = null; - //PCEP Attribute list - PcepMsgPath msgPath = null; - - if (!this.bIsSRPObjectSet) { - throw new PcepParseException(" SRP Object NOT Set while building PcepUpdateRequest."); - } else { - srpObject = this.srpObject; - } - if (!this.bIsLSPObjectSet) { - throw new PcepParseException(" LSP Object NOT Set while building PcepUpdateRequest."); - } else { - lspObject = this.lspObject; - } - if (!this.bIsPcepMsgPathSet) { - throw new PcepParseException(" Msg Path NOT Set while building PcepUpdateRequest."); - } else { - msgPath = this.msgPath; - } - - return new PcepUpdateRequestVer1(srpObject, lspObject, msgPath); - } - - @Override - public PcepSrpObject getSrpObject() { - return this.srpObject; - } - - @Override - public PcepLspObject getLspObject() { - return this.lspObject; - } - - @Override - public PcepMsgPath getMsgPath() { - return this.msgPath; - } - - @Override - public Builder setSrpObject(PcepSrpObject srpobj) { - this.srpObject = srpobj; - this.bIsSRPObjectSet = true; - return this; - - } - - @Override - public Builder setLspObject(PcepLspObject lspObject) { - this.lspObject = lspObject; - this.bIsLSPObjectSet = true; - return this; - } - - @Override - public Builder setMsgPath(PcepMsgPath msgPath) { - this.msgPath = msgPath; - this.bIsPcepMsgPathSet = true; - return this; - } - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("SrpObject", srpObject) - .add("LspObject", lspObject) - .add("MsgPath", msgPath) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/package-info.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/package-info.java deleted file mode 100644 index 32d49ec9..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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. - */ - -/** - * Implementation of PCEP messages. - */ -package org.onosproject.pcepio.protocol.ver1; |