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.
17 package org.onosproject.pcepio.protocol.ver1;
19 import org.jboss.netty.buffer.ChannelBuffer;
20 import org.onosproject.pcepio.exceptions.PcepParseException;
21 import org.onosproject.pcepio.protocol.PcepFecObjectIPv6Adjacency;
22 import org.onosproject.pcepio.protocol.PcepVersion;
23 import org.onosproject.pcepio.types.PcepObjectHeader;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
27 import com.google.common.base.MoreObjects;
30 * Provides Pcep Fec Object IPv6 Adjacency object.
32 public class PcepFecObjectIPv6AdjacencyVer1 implements PcepFecObjectIPv6Adjacency {
35 * ref : draft-zhao-pce-pcep-extension-for-pce-controller-01 , section : 7.5
38 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
39 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
41 // Local IPv6 address (16 bytes) //
43 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
45 // Remote IPv6 address (16 bytes) //
47 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
49 FEC Object-Type is 4 IPv6 Adjacency
51 protected static final Logger log = LoggerFactory.getLogger(PcepFecObjectIPv6AdjacencyVer1.class);
53 public static final byte FEC_OBJ_TYPE = 4;
54 public static final byte FEC_OBJ_CLASS = 63; //to be defined
55 public static final byte FEC_OBJECT_VERSION = 1;
56 public static final short FEC_OBJ_MINIMUM_LENGTH = 36;
57 public static final int MINIMUM_COMMON_HEADER_LENGTH = 4;
58 public static final int IPV6_ADDRESS_LENGTH = 16;
60 static final PcepObjectHeader DEFAULT_FEC_OBJECT_HEADER = new PcepObjectHeader(FEC_OBJ_CLASS, FEC_OBJ_TYPE,
61 PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, FEC_OBJ_MINIMUM_LENGTH);
63 private PcepObjectHeader fecObjHeader;
64 private byte[] localIPv6Address = new byte[IPV6_ADDRESS_LENGTH];
65 private byte[] remoteIPv6Address = new byte[IPV6_ADDRESS_LENGTH];
68 * Constructor to initialize parameters for PCEP fec object.
70 * @param fecObjHeader fec object header
71 * @param localIPv6Address local IPv6 address
72 * @param remoteIPv6Address remote IPv6 address
74 public PcepFecObjectIPv6AdjacencyVer1(PcepObjectHeader fecObjHeader, byte[] localIPv6Address,
75 byte[] remoteIPv6Address) {
76 this.fecObjHeader = fecObjHeader;
77 this.localIPv6Address = localIPv6Address;
78 this.remoteIPv6Address = remoteIPv6Address;
84 * @param obj object header
86 public void setFecIpv4ObjHeader(PcepObjectHeader obj) {
87 this.fecObjHeader = obj;
91 public byte[] getLocalIPv6Address() {
92 return this.localIPv6Address;
96 public void seLocalIPv6Address(byte[] value) {
97 this.localIPv6Address = value;
101 public byte[] getRemoteIPv6Address() {
102 return this.remoteIPv6Address;
106 public void seRemoteIPv6Address(byte[] value) {
107 this.remoteIPv6Address = value;
111 * Reads channel buffer and Returns object of PcepFecObjectIPv6Adjacency.
113 * @param cb of channel buffer
114 * @return object of PcepFecObjectIPv6Adjacency
115 * @throws PcepParseException when fails tp read from channel buffer
117 public static PcepFecObjectIPv6Adjacency read(ChannelBuffer cb) throws PcepParseException {
119 PcepObjectHeader fecObjHeader;
120 byte[] localIPv6Address = new byte[IPV6_ADDRESS_LENGTH];
121 byte[] remoteIPv6Address = new byte[IPV6_ADDRESS_LENGTH];
122 fecObjHeader = PcepObjectHeader.read(cb);
123 cb.readBytes(localIPv6Address, 0, IPV6_ADDRESS_LENGTH);
124 cb.readBytes(remoteIPv6Address, 0, IPV6_ADDRESS_LENGTH);
125 return new PcepFecObjectIPv6AdjacencyVer1(fecObjHeader, localIPv6Address, remoteIPv6Address);
129 public int write(ChannelBuffer cb) throws PcepParseException {
131 int objStartIndex = cb.writerIndex();
133 //write common header
134 int objLenIndex = fecObjHeader.write(cb);
135 cb.writeBytes(localIPv6Address);
136 cb.writeBytes(remoteIPv6Address);
137 //now write FEC IPv6 Adjacency Object Length
138 cb.setShort(objLenIndex, (short) (cb.writerIndex() - objStartIndex));
139 return cb.writerIndex();
143 * Builder class for PCEP fec object IPv6 Adjacency.
145 public static class Builder implements PcepFecObjectIPv6Adjacency.Builder {
146 private boolean bIsHeaderSet = false;
147 private boolean bIsLocalIPv6Addressset = false;
148 private boolean bIsRemoteIPv6Addressset = false;
150 private PcepObjectHeader fecObjHeader;
151 byte[] localIPv6Address = new byte[IPV6_ADDRESS_LENGTH];
152 byte[] remoteIPv6Address = new byte[IPV6_ADDRESS_LENGTH];
154 private boolean bIsPFlagSet = false;
155 private boolean bPFlag;
157 private boolean bIsIFlagSet = false;
158 private boolean bIFlag;
161 public PcepFecObjectIPv6Adjacency build() throws PcepParseException {
162 PcepObjectHeader fecObjHeader = this.bIsHeaderSet ? this.fecObjHeader : DEFAULT_FEC_OBJECT_HEADER;
164 if (!this.bIsLocalIPv6Addressset) {
165 throw new PcepParseException(
166 "Local IPv6 Address not set while building PcepFecObjectIPv6Adjacency object.");
168 if (!this.bIsRemoteIPv6Addressset) {
169 throw new PcepParseException(
170 "Remote IPv6 Address not set while building PcepFecObjectIPv6Adjacency object.");
173 fecObjHeader.setPFlag(bPFlag);
176 fecObjHeader.setIFlag(bIFlag);
178 return new PcepFecObjectIPv6AdjacencyVer1(fecObjHeader, this.localIPv6Address, this.remoteIPv6Address);
182 public Builder setPFlag(boolean value) {
184 this.bIsPFlagSet = true;
189 public Builder setIFlag(boolean value) {
191 this.bIsIFlagSet = true;
196 public PcepObjectHeader getFecIpv6AdjacencyObjHeader() {
197 return this.fecObjHeader;
201 public Builder setFecIpv6AdjacencyObjHeader(PcepObjectHeader obj) {
202 this.fecObjHeader = obj;
203 this.bIsHeaderSet = true;
208 public byte[] getLocalIPv6Address() {
209 return this.localIPv6Address;
213 public Builder setLocalIPv6Address(byte[] value) {
214 this.localIPv6Address = value;
215 this.bIsLocalIPv6Addressset = true;
220 public byte[] getRemoteIPv6Address() {
221 return this.remoteIPv6Address;
225 public Builder setRemoteIPv6Address(byte[] value) {
226 this.remoteIPv6Address = value;
227 this.bIsRemoteIPv6Addressset = true;
233 public PcepVersion getVersion() {
234 return PcepVersion.PCEP_1;
238 public int getType() {
243 public String toString() {
244 return MoreObjects.toStringHelper(getClass())
245 .add("localIPv6Address", localIPv6Address)
246 .add("remoteIPv6Address: ", remoteIPv6Address)