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.PcepFecObjectIPv6;
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 object.
32 public class PcepFecObjectIPv6Ver1 implements PcepFecObjectIPv6 {
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 // IPv6 Node ID (16 bytes) //
43 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
45 FEC Object-Type is 2 IPv6 Node ID
47 protected static final Logger log = LoggerFactory.getLogger(PcepFecObjectIPv6Ver1.class);
49 public static final byte FEC_OBJ_TYPE = 2;
50 public static final byte FEC_OBJ_CLASS = 63; //to be defined
51 public static final byte FEC_OBJECT_VERSION = 1;
52 public static final short FEC_OBJ_MINIMUM_LENGTH = 20;
53 public static final int MINIMUM_COMMON_HEADER_LENGTH = 4;
54 public static final int IPV6_ADDRESS_LENGTH = 16;
56 static final PcepObjectHeader DEFAULT_FEC_OBJECT_HEADER = new PcepObjectHeader(FEC_OBJ_CLASS, FEC_OBJ_TYPE,
57 PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, FEC_OBJ_MINIMUM_LENGTH);
59 private PcepObjectHeader fecObjHeader;
60 private byte[] nodeID = new byte[IPV6_ADDRESS_LENGTH];
63 * Constructor to initialize parameters for PCEP fec object.
65 * @param fecObjHeader Fec object header
66 * @param nodeID node ID
68 public PcepFecObjectIPv6Ver1(PcepObjectHeader fecObjHeader, byte[] nodeID) {
69 this.fecObjHeader = fecObjHeader;
74 * Sets the Object header.
76 * @param obj object header
78 public void setFecIpv6ObjHeader(PcepObjectHeader obj) {
79 this.fecObjHeader = obj;
83 public void setNodeID(byte[] nodeID) {
88 * Returns object header.
90 * @return fec Object Header
92 public PcepObjectHeader getFecIpv6ObjHeader() {
93 return this.fecObjHeader;
97 public byte[] getNodeID() {
102 * reads the channel buffer and returns object of PcepFecObjectIPv6.
104 * @param cb of channel buffer.
105 * @return object of PcepFecObjectIPv6
106 * @throws PcepParseException when fails to read from channel buffer
108 public static PcepFecObjectIPv6 read(ChannelBuffer cb) throws PcepParseException {
110 PcepObjectHeader fecObjHeader;
111 byte[] nodeID = new byte[IPV6_ADDRESS_LENGTH];
112 fecObjHeader = PcepObjectHeader.read(cb);
113 cb.readBytes(nodeID, 0, IPV6_ADDRESS_LENGTH);
114 return new PcepFecObjectIPv6Ver1(fecObjHeader, nodeID);
118 public int write(ChannelBuffer cb) throws PcepParseException {
120 int objStartIndex = cb.writerIndex();
122 //write common header
123 int objLenIndex = fecObjHeader.write(cb);
124 cb.writeBytes(nodeID);
126 //now write FEC IPv4 Object Length
127 cb.setShort(objLenIndex, (short) (cb.writerIndex() - objStartIndex));
128 return cb.writerIndex();
132 * Builder class for PCEP fec object IPv6.
134 public static class Builder implements PcepFecObjectIPv6.Builder {
135 private boolean bIsHeaderSet = false;
136 private boolean bIsNodeIdset = false;
138 private PcepObjectHeader fecObjHeader;
139 private byte[] nodeID = new byte[IPV6_ADDRESS_LENGTH];
141 private boolean bIsPFlagSet = false;
142 private boolean bPFlag;
144 private boolean bIsIFlagSet = false;
145 private boolean bIFlag;
148 public PcepFecObjectIPv6 build() throws PcepParseException {
149 PcepObjectHeader fecObjHeader = this.bIsHeaderSet ? this.fecObjHeader : DEFAULT_FEC_OBJECT_HEADER;
151 if (!this.bIsNodeIdset) {
152 throw new PcepParseException(" NodeID not set while building PcepFecObjectIPv6 object.");
155 fecObjHeader.setPFlag(bPFlag);
158 fecObjHeader.setIFlag(bIFlag);
160 return new PcepFecObjectIPv6Ver1(fecObjHeader, this.nodeID);
164 public Builder setPFlag(boolean value) {
166 this.bIsPFlagSet = true;
171 public Builder setIFlag(boolean value) {
173 this.bIsIFlagSet = true;
178 public PcepObjectHeader getFecIpv6ObjHeader() {
179 return this.fecObjHeader;
183 public Builder setFecIpv6ObjHeader(PcepObjectHeader obj) {
184 this.fecObjHeader = obj;
185 this.bIsHeaderSet = true;
190 public byte[] getNodeID() {
195 public Builder setNodeID(byte[] value) {
197 this.bIsNodeIdset = true;
204 public PcepVersion getVersion() {
205 return PcepVersion.PCEP_1;
209 public int getType() {
214 public String toString() {
215 return MoreObjects.toStringHelper(getClass())
216 .add("fecObjHeader", fecObjHeader)
217 .add("NodeID: ", nodeID)