Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 3 | * |
| 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 | */ |
| 16 | |
| 17 | package org.onosproject.pcepio.protocol.ver1; |
| 18 | |
| 19 | import org.onosproject.pcepio.exceptions.PcepParseException; |
| 20 | import org.onosproject.pcepio.protocol.PcInitiatedLspRequest; |
| 21 | import org.onosproject.pcepio.protocol.PcepAttribute; |
| 22 | import org.onosproject.pcepio.protocol.PcepEndPointsObject; |
| 23 | import org.onosproject.pcepio.protocol.PcepEroObject; |
| 24 | import org.onosproject.pcepio.protocol.PcepLspObject; |
| 25 | import org.onosproject.pcepio.protocol.PcepSrpObject; |
| 26 | import org.slf4j.Logger; |
| 27 | import org.slf4j.LoggerFactory; |
| 28 | |
| 29 | import com.google.common.base.MoreObjects; |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * Provides PcInitiatedLspRequest for PCEP Initiate message. |
| 33 | * Reference : PCE initiated tunnel setup draft-ietf-pce-pce-initiated-lsp-03. |
| 34 | */ |
| 35 | public class PcInitiatedLspRequestVer1 implements PcInitiatedLspRequest { |
| 36 | |
| 37 | /* |
| 38 | * <PCE-initiated-lsp-request> ::= (<PCE-initiated-lsp-instantiation>|<PCE-initiated-lsp-deletion>) |
| 39 | <PCE-initiated-lsp-instantiation> ::= <SRP> |
| 40 | <LSP> |
| 41 | <END-POINTS> |
| 42 | <ERO> |
| 43 | [<attribute-list>] |
| 44 | <PCE-initiated-lsp-deletion> ::= <SRP> |
| 45 | <LSP> |
| 46 | */ |
| 47 | |
| 48 | protected static final Logger log = LoggerFactory.getLogger(PcInitiatedLspRequestVer1.class); |
| 49 | |
| 50 | //PCEP SRP Object |
| 51 | private PcepSrpObject srpObject; |
| 52 | //PCEP LSP Object |
| 53 | private PcepLspObject lspObject; |
| 54 | //PCEP End Point Object |
| 55 | private PcepEndPointsObject endPointsObject; |
| 56 | //PCEP ERO Object |
| 57 | private PcepEroObject eroObject; |
| 58 | //PCEP Attribute list |
| 59 | private PcepAttribute pcepAttribute; |
| 60 | |
| 61 | /** |
| 62 | * Default constructor. |
| 63 | */ |
| 64 | public PcInitiatedLspRequestVer1() { |
| 65 | srpObject = null; |
| 66 | lspObject = null; |
| 67 | endPointsObject = null; |
| 68 | eroObject = null; |
| 69 | pcepAttribute = null; |
| 70 | |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Constructor to initialize all parameters of PC initiated lsp request. |
| 75 | * |
| 76 | * @param srpObject PCEP srp Object |
| 77 | * @param lspObject PCEP lsp object |
| 78 | * @param endPointsObject PCPE endpoints object |
| 79 | * @param eroObject PCEP ero object |
| 80 | * @param pcepAttribute PCEP attribute |
| 81 | */ |
| 82 | public PcInitiatedLspRequestVer1(PcepSrpObject srpObject, PcepLspObject lspObject, |
| 83 | PcepEndPointsObject endPointsObject, PcepEroObject eroObject, PcepAttribute pcepAttribute) { |
| 84 | this.srpObject = srpObject; |
| 85 | this.lspObject = lspObject; |
| 86 | this.endPointsObject = endPointsObject; |
| 87 | this.eroObject = eroObject; |
| 88 | this.pcepAttribute = pcepAttribute; |
| 89 | |
| 90 | } |
| 91 | |
| 92 | @Override |
| 93 | public PcepSrpObject getSrpObject() { |
| 94 | return srpObject; |
| 95 | } |
| 96 | |
| 97 | @Override |
| 98 | public PcepLspObject getLspObject() { |
| 99 | return lspObject; |
| 100 | } |
| 101 | |
| 102 | @Override |
| 103 | public PcepEndPointsObject getEndPointsObject() { |
| 104 | return endPointsObject; |
| 105 | } |
| 106 | |
| 107 | @Override |
| 108 | public PcepEroObject getEroObject() { |
| 109 | return eroObject; |
| 110 | } |
| 111 | |
| 112 | @Override |
| 113 | public PcepAttribute getPcepAttribute() { |
| 114 | return pcepAttribute; |
| 115 | } |
| 116 | |
| 117 | @Override |
| 118 | public void setSrpObject(PcepSrpObject srpobj) { |
| 119 | this.srpObject = srpobj; |
| 120 | |
| 121 | } |
| 122 | |
| 123 | @Override |
| 124 | public void setLspObject(PcepLspObject lspObject) { |
| 125 | this.lspObject = lspObject; |
| 126 | } |
| 127 | |
| 128 | @Override |
| 129 | public void setEndPointsObject(PcepEndPointsObject endPointsObject) { |
| 130 | this.endPointsObject = endPointsObject; |
| 131 | } |
| 132 | |
| 133 | @Override |
| 134 | public void setEroObject(PcepEroObject eroObject) { |
| 135 | this.eroObject = eroObject; |
| 136 | } |
| 137 | |
| 138 | @Override |
| 139 | public void setPcepAttribute(PcepAttribute pcepAttribute) { |
| 140 | this.pcepAttribute = pcepAttribute; |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * Builder class for PC initiated lsp reuqest. |
| 145 | */ |
| 146 | public static class Builder implements PcInitiatedLspRequest.Builder { |
| 147 | |
| 148 | private boolean bIsSRPObjectSet = false; |
| 149 | private boolean bIsLSPObjectSet = false; |
| 150 | private boolean bIsEndPointsObjectSet = false; |
| 151 | private boolean bIsEROObjectSet = false; |
| 152 | private boolean bIsPcepAttributeSet = false; |
| 153 | private boolean bIsbRFlagSet = false; |
| 154 | |
| 155 | //PCEP SRP Object |
| 156 | private PcepSrpObject srpObject; |
| 157 | //PCEP LSP Object |
| 158 | private PcepLspObject lspObject; |
| 159 | //PCEP End Point Object |
| 160 | private PcepEndPointsObject endPointsObject; |
| 161 | //PCEP ERO Object |
| 162 | private PcepEroObject eroObject; |
| 163 | //PCEP Attribute list |
| 164 | private PcepAttribute pcepAttribute; |
| 165 | |
| 166 | @Override |
| 167 | public PcInitiatedLspRequest build() throws PcepParseException { |
| 168 | |
| 169 | //PCEP SRP Object |
| 170 | PcepSrpObject srpObject = null; |
| 171 | //PCEP LSP Object |
| 172 | PcepLspObject lspObject = null; |
| 173 | //PCEP End Point Object |
| 174 | PcepEndPointsObject endPointsObject = null; |
| 175 | //PCEP ERO Object |
| 176 | PcepEroObject eroObject = null; |
| 177 | //PCEP Attribute list |
| 178 | PcepAttribute pcepAttribute = null; |
| 179 | boolean bRFlag = false; |
| 180 | |
| 181 | if (!this.bIsSRPObjectSet) { |
| 182 | throw new PcepParseException("Srp object NOT Set while building PcInitiatedLspRequest"); |
| 183 | } else { |
| 184 | srpObject = this.srpObject; |
| 185 | bRFlag = srpObject.getRFlag(); |
| 186 | } |
| 187 | |
| 188 | if (bRFlag) { |
| 189 | this.bIsbRFlagSet = true; |
| 190 | } else { |
| 191 | this.bIsbRFlagSet = false; |
| 192 | } |
| 193 | |
| 194 | if (!this.bIsLSPObjectSet) { |
| 195 | throw new PcepParseException("LSP Object NOT Set while building PcInitiatedLspRequest"); |
| 196 | } else { |
| 197 | lspObject = this.lspObject; |
| 198 | } |
| 199 | if (!this.bIsbRFlagSet) { |
| 200 | |
| 201 | if (!this.bIsEndPointsObjectSet) { |
| 202 | throw new PcepParseException("EndPoints Object NOT Set while building PcInitiatedLspRequest"); |
| 203 | } else { |
| 204 | endPointsObject = this.endPointsObject; |
| 205 | } |
| 206 | if (!this.bIsEROObjectSet) { |
| 207 | throw new PcepParseException("ERO Object NOT Set while building PcInitiatedLspRequest"); |
| 208 | } else { |
| 209 | eroObject = this.eroObject; |
| 210 | } |
| 211 | if (bIsPcepAttributeSet) { |
| 212 | pcepAttribute = this.pcepAttribute; |
| 213 | } |
| 214 | } |
| 215 | return new PcInitiatedLspRequestVer1(srpObject, lspObject, endPointsObject, eroObject, pcepAttribute); |
| 216 | } |
| 217 | |
| 218 | @Override |
| 219 | public PcepSrpObject getSrpObject() { |
| 220 | return this.srpObject; |
| 221 | } |
| 222 | |
| 223 | @Override |
| 224 | public PcepLspObject getLspObject() { |
| 225 | return this.lspObject; |
| 226 | } |
| 227 | |
| 228 | @Override |
| 229 | public PcepEndPointsObject getEndPointsObject() { |
| 230 | return this.endPointsObject; |
| 231 | } |
| 232 | |
| 233 | @Override |
| 234 | public PcepEroObject getEroObject() { |
| 235 | return this.eroObject; |
| 236 | } |
| 237 | |
| 238 | @Override |
| 239 | public PcepAttribute getPcepAttribute() { |
| 240 | return this.pcepAttribute; |
| 241 | } |
| 242 | |
| 243 | @Override |
| 244 | public Builder setSrpObject(PcepSrpObject srpobj) { |
| 245 | this.srpObject = srpobj; |
| 246 | this.bIsSRPObjectSet = true; |
| 247 | return this; |
| 248 | |
| 249 | } |
| 250 | |
| 251 | @Override |
| 252 | public Builder setLspObject(PcepLspObject lspObject) { |
| 253 | this.lspObject = lspObject; |
| 254 | this.bIsLSPObjectSet = true; |
| 255 | return this; |
| 256 | } |
| 257 | |
| 258 | @Override |
| 259 | public Builder setEndPointsObject(PcepEndPointsObject endPointsObject) { |
| 260 | this.endPointsObject = endPointsObject; |
| 261 | this.bIsEndPointsObjectSet = true; |
| 262 | return this; |
| 263 | } |
| 264 | |
| 265 | @Override |
| 266 | public Builder setEroObject(PcepEroObject eroObject) { |
| 267 | this.eroObject = eroObject; |
| 268 | this.bIsEROObjectSet = true; |
| 269 | return this; |
| 270 | } |
| 271 | |
| 272 | @Override |
| 273 | public Builder setPcepAttribute(PcepAttribute pcepAttribute) { |
| 274 | this.pcepAttribute = pcepAttribute; |
| 275 | this.bIsPcepAttributeSet = true; |
| 276 | return this; |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | @Override |
| 281 | public String toString() { |
Sho SHIMIZU | 7cdbcf7 | 2015-09-03 14:43:05 -0700 | [diff] [blame^] | 282 | return MoreObjects.toStringHelper(getClass()) |
| 283 | .omitNullValues() |
| 284 | .add("SrpObject", srpObject) |
| 285 | .add("LspObject", lspObject) |
| 286 | .add("EndPointObject", endPointsObject) |
| 287 | .add("EroObject", eroObject) |
| 288 | .add("PcepAttribute", pcepAttribute) |
| 289 | .toString(); |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 290 | } |
| 291 | } |