blob: 9b2f5aadf02908b858267444d2a96f88bacbb18d [file] [log] [blame]
Thomas Vachuska58de4162015-09-10 16:15:33 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Thomas Vachuska58de4162015-09-10 16:15:33 -07003 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -070016package org.onosproject.pcepio.protocol.ver1;
17
18import org.jboss.netty.buffer.ChannelBuffer;
19import org.onosproject.pcepio.exceptions.PcepParseException;
20import org.onosproject.pcepio.protocol.PcepAttribute;
21import org.onosproject.pcepio.protocol.PcepEroObject;
22import org.onosproject.pcepio.protocol.PcepMsgPath;
23import org.slf4j.Logger;
24import org.slf4j.LoggerFactory;
25
26import com.google.common.base.MoreObjects;
27
28/**
29 * Provides PCEP Message PAth for update message.
30 * Reference :PCE extensions for stateful draft-ietf-pce-stateful-pce-10.
31 */
32public class PcepMsgPathVer1 implements PcepMsgPath {
33
34 /*
35 * <path> ::= <ERO><attribute-list>
36 */
37
Ray Milkey9c9cde42018-01-12 14:22:06 -080038 private static final Logger log = LoggerFactory.getLogger(PcepMsgPathVer1.class);
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -070039 //PcepEroObject
40 private PcepEroObject eroObj;
41 private boolean isEroObjectSet;
42 // PcepAttribute
43 private PcepAttribute attrList;
44 private boolean isAttributeListSet;
45
46 /**
47 * constructor to initialize objects.
48 */
49 public PcepMsgPathVer1() {
50 eroObj = null;
51 attrList = null;
52 isEroObjectSet = false;
53 isAttributeListSet = false;
54 }
55
56 @Override
57 public PcepEroObject getEroObject() {
58 return eroObj;
59 }
60
61 @Override
62 public PcepAttribute getPcepAttribute() {
63 return attrList;
64 }
65
66 @Override
67 public void setEroObject(PcepEroObject eroObj) {
68 this.eroObj = eroObj;
69 }
70
71 @Override
72 public void setPcepAttribute(PcepAttribute attrList) {
73 this.attrList = attrList;
74 }
75
76 /**
77 * constructor to initialize member variables.
78 *
79 * @param eroObj pcep ero object
80 * @param attrList pcep attribute
81 */
82 public PcepMsgPathVer1(PcepEroObject eroObj, PcepAttribute attrList) {
83 this.eroObj = eroObj;
84 isEroObjectSet = true;
85 this.attrList = attrList;
86 if (attrList == null) {
87 isAttributeListSet = false;
88 } else {
89 isAttributeListSet = true;
90 }
91 }
92
93 @Override
94 public PcepMsgPath read(ChannelBuffer cb) throws PcepParseException {
95 PcepEroObject eroObj;
96 PcepAttribute attrList;
97
98 eroObj = PcepEroObjectVer1.read(cb);
99 attrList = PcepAttributeVer1.read(cb);
100
101 return new PcepMsgPathVer1(eroObj, attrList);
102 }
103
104 @Override
105 public int write(ChannelBuffer cb) throws PcepParseException {
106 int iLenStartIndex = cb.writerIndex();
107
108 //write Object header
109 if (this.isEroObjectSet) {
110 this.eroObj.write(cb);
111 }
112 if (this.isAttributeListSet) {
113 attrList.write(cb);
114 }
115
116 return cb.writerIndex() - iLenStartIndex;
117 }
118
119 /**
120 * Builder class for PCEP Message path.
121 */
122 public static class Builder implements PcepMsgPath.Builder {
123
Jonathan Hart51539b82015-10-29 09:53:04 -0700124 private boolean bIsEroObjectSet = false;
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -0700125 private boolean bIsPcepAttributeSet = false;
126
127 //PCEP ERO Object
128 private PcepEroObject eroObject;
129 //PCEP Attribute list
130 private PcepAttribute pcepAttribute;
131
132 @Override
133 public PcepMsgPath build() throws PcepParseException {
134
135 //PCEP ERO Object
136 PcepEroObject eroObject = null;
137 //PCEP Attribute list
138 PcepAttribute pcepAttribute = null;
139
Jonathan Hart51539b82015-10-29 09:53:04 -0700140 if (!this.bIsEroObjectSet) {
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -0700141 throw new PcepParseException("ERO Object NOT Set while building PcepMsgPath.");
142 } else {
143 eroObject = this.eroObject;
144 }
145 if (!this.bIsPcepAttributeSet) {
146 throw new PcepParseException("Pcep Attributes NOT Set while building PcepMsgPath.");
147 } else {
148 pcepAttribute = this.pcepAttribute;
149 }
150
151 return new PcepMsgPathVer1(eroObject, pcepAttribute);
152 }
153
154 @Override
155 public PcepEroObject getEroObject() {
156 return this.eroObject;
157 }
158
159 @Override
160 public PcepAttribute getPcepAttribute() {
161 return this.pcepAttribute;
162 }
163
164 @Override
165 public Builder setEroObject(PcepEroObject eroObject) {
166 this.eroObject = eroObject;
Jonathan Hart51539b82015-10-29 09:53:04 -0700167 this.bIsEroObjectSet = true;
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -0700168 return this;
169 }
170
171 @Override
172 public Builder setPcepAttribute(PcepAttribute pcepAttribute) {
173 this.pcepAttribute = pcepAttribute;
174 this.bIsPcepAttributeSet = true;
175 return this;
176 }
177
178 }
179
180 @Override
181 public String toString() {
Sho SHIMIZU7cdbcf72015-09-03 14:43:05 -0700182 return MoreObjects.toStringHelper(getClass())
183 .add("EroObject", eroObj)
184 .add("AttributeList", attrList)
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -0700185 .toString();
186 }
Sho SHIMIZU7cdbcf72015-09-03 14:43:05 -0700187}