2 * Copyright 2015 Open Networking Laboratory
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.onosproject.pcepio.protocol.ver1;
18 import org.jboss.netty.buffer.ChannelBuffer;
19 import org.onosproject.pcepio.exceptions.PcepParseException;
20 import org.onosproject.pcepio.protocol.PcepAttribute;
21 import org.onosproject.pcepio.protocol.PcepEroObject;
22 import org.onosproject.pcepio.protocol.PcepMsgPath;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 import com.google.common.base.MoreObjects;
29 * Provides PCEP Message PAth for update message.
30 * Reference :PCE extensions for stateful draft-ietf-pce-stateful-pce-10.
32 public class PcepMsgPathVer1 implements PcepMsgPath {
35 * <path> ::= <ERO><attribute-list>
38 protected static final Logger log = LoggerFactory.getLogger(PcepMsgPathVer1.class);
40 private PcepEroObject eroObj;
41 private boolean isEroObjectSet;
43 private PcepAttribute attrList;
44 private boolean isAttributeListSet;
47 * constructor to initialize objects.
49 public PcepMsgPathVer1() {
52 isEroObjectSet = false;
53 isAttributeListSet = false;
57 public PcepEroObject getEroObject() {
62 public PcepAttribute getPcepAttribute() {
67 public void setEroObject(PcepEroObject eroObj) {
72 public void setPcepAttribute(PcepAttribute attrList) {
73 this.attrList = attrList;
77 * constructor to initialize member variables.
79 * @param eroObj pcep ero object
80 * @param attrList pcep attribute
82 public PcepMsgPathVer1(PcepEroObject eroObj, PcepAttribute attrList) {
84 isEroObjectSet = true;
85 this.attrList = attrList;
86 if (attrList == null) {
87 isAttributeListSet = false;
89 isAttributeListSet = true;
94 public PcepMsgPath read(ChannelBuffer cb) throws PcepParseException {
96 PcepAttribute attrList;
98 eroObj = PcepEroObjectVer1.read(cb);
99 attrList = PcepAttributeVer1.read(cb);
101 return new PcepMsgPathVer1(eroObj, attrList);
105 public int write(ChannelBuffer cb) throws PcepParseException {
106 int iLenStartIndex = cb.writerIndex();
108 //write Object header
109 if (this.isEroObjectSet) {
110 this.eroObj.write(cb);
112 if (this.isAttributeListSet) {
116 return cb.writerIndex() - iLenStartIndex;
120 * Builder class for PCEP Message path.
122 public static class Builder implements PcepMsgPath.Builder {
124 private boolean bIsEROObjectSet = false;
125 private boolean bIsPcepAttributeSet = false;
128 private PcepEroObject eroObject;
129 //PCEP Attribute list
130 private PcepAttribute pcepAttribute;
133 public PcepMsgPath build() throws PcepParseException {
136 PcepEroObject eroObject = null;
137 //PCEP Attribute list
138 PcepAttribute pcepAttribute = null;
140 if (!this.bIsEROObjectSet) {
141 throw new PcepParseException("ERO Object NOT Set while building PcepMsgPath.");
143 eroObject = this.eroObject;
145 if (!this.bIsPcepAttributeSet) {
146 throw new PcepParseException("Pcep Attributes NOT Set while building PcepMsgPath.");
148 pcepAttribute = this.pcepAttribute;
151 return new PcepMsgPathVer1(eroObject, pcepAttribute);
155 public PcepEroObject getEroObject() {
156 return this.eroObject;
160 public PcepAttribute getPcepAttribute() {
161 return this.pcepAttribute;
165 public Builder setEroObject(PcepEroObject eroObject) {
166 this.eroObject = eroObject;
167 this.bIsEROObjectSet = true;
172 public Builder setPcepAttribute(PcepAttribute pcepAttribute) {
173 this.pcepAttribute = pcepAttribute;
174 this.bIsPcepAttributeSet = true;
181 public String toString() {
182 return MoreObjects.toStringHelper(getClass())
183 .add("EroObject", eroObj)
184 .add("AttributeList", attrList)