1 package org.onosproject.pcepio.protocol.ver1;
3 import org.jboss.netty.buffer.ChannelBuffer;
4 import org.onosproject.pcepio.exceptions.PcepParseException;
5 import org.onosproject.pcepio.protocol.PcepAttribute;
6 import org.onosproject.pcepio.protocol.PcepEroObject;
7 import org.onosproject.pcepio.protocol.PcepMsgPath;
8 import org.slf4j.Logger;
9 import org.slf4j.LoggerFactory;
11 import com.google.common.base.MoreObjects;
14 * Provides PCEP Message PAth for update message.
15 * Reference :PCE extensions for stateful draft-ietf-pce-stateful-pce-10.
17 public class PcepMsgPathVer1 implements PcepMsgPath {
20 * <path> ::= <ERO><attribute-list>
23 protected static final Logger log = LoggerFactory.getLogger(PcepMsgPathVer1.class);
25 private PcepEroObject eroObj;
26 private boolean isEroObjectSet;
28 private PcepAttribute attrList;
29 private boolean isAttributeListSet;
32 * constructor to initialize objects.
34 public PcepMsgPathVer1() {
37 isEroObjectSet = false;
38 isAttributeListSet = false;
42 public PcepEroObject getEroObject() {
47 public PcepAttribute getPcepAttribute() {
52 public void setEroObject(PcepEroObject eroObj) {
57 public void setPcepAttribute(PcepAttribute attrList) {
58 this.attrList = attrList;
62 * constructor to initialize member variables.
64 * @param eroObj pcep ero object
65 * @param attrList pcep attribute
67 public PcepMsgPathVer1(PcepEroObject eroObj, PcepAttribute attrList) {
69 isEroObjectSet = true;
70 this.attrList = attrList;
71 if (attrList == null) {
72 isAttributeListSet = false;
74 isAttributeListSet = true;
79 public PcepMsgPath read(ChannelBuffer cb) throws PcepParseException {
81 PcepAttribute attrList;
83 eroObj = PcepEroObjectVer1.read(cb);
84 attrList = PcepAttributeVer1.read(cb);
86 return new PcepMsgPathVer1(eroObj, attrList);
90 public int write(ChannelBuffer cb) throws PcepParseException {
91 int iLenStartIndex = cb.writerIndex();
94 if (this.isEroObjectSet) {
95 this.eroObj.write(cb);
97 if (this.isAttributeListSet) {
101 return cb.writerIndex() - iLenStartIndex;
105 * Builder class for PCEP Message path.
107 public static class Builder implements PcepMsgPath.Builder {
109 private boolean bIsEROObjectSet = false;
110 private boolean bIsPcepAttributeSet = false;
113 private PcepEroObject eroObject;
114 //PCEP Attribute list
115 private PcepAttribute pcepAttribute;
118 public PcepMsgPath build() throws PcepParseException {
121 PcepEroObject eroObject = null;
122 //PCEP Attribute list
123 PcepAttribute pcepAttribute = null;
125 if (!this.bIsEROObjectSet) {
126 throw new PcepParseException("ERO Object NOT Set while building PcepMsgPath.");
128 eroObject = this.eroObject;
130 if (!this.bIsPcepAttributeSet) {
131 throw new PcepParseException("Pcep Attributes NOT Set while building PcepMsgPath.");
133 pcepAttribute = this.pcepAttribute;
136 return new PcepMsgPathVer1(eroObject, pcepAttribute);
140 public PcepEroObject getEroObject() {
141 return this.eroObject;
145 public PcepAttribute getPcepAttribute() {
146 return this.pcepAttribute;
150 public Builder setEroObject(PcepEroObject eroObject) {
151 this.eroObject = eroObject;
152 this.bIsEROObjectSet = true;
157 public Builder setPcepAttribute(PcepAttribute pcepAttribute) {
158 this.pcepAttribute = pcepAttribute;
159 this.bIsPcepAttributeSet = true;
166 public String toString() {
167 return MoreObjects.toStringHelper(getClass())
168 .add("EroObject", eroObj)
169 .add("AttributeList", attrList)