blob: ff6956150616a2fddf0a63e5bf353d4b0f8da4d0 [file] [log] [blame]
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -07001/*
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
17package org.onosproject.pcepio.types;
18
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -070019import org.jboss.netty.buffer.ChannelBuffer;
Jian Li597d7b22016-02-29 14:06:55 -080020import org.onlab.util.Identifier;
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -070021import org.onosproject.pcepio.protocol.PcepNai;
22
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -070023/**
24 * Provides Pcep Nai Ipv4 Node Id.
25 */
Jian Li597d7b22016-02-29 14:06:55 -080026public class PcepNaiIpv4NodeId extends Identifier<Integer> implements PcepNai {
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -070027
28 public static final byte ST_TYPE = 0x01;
29
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -070030 /**
31 * Constructor to initialize ipv4NodeId.
32 *
33 * @param value ipv4 node id
34 */
35 public PcepNaiIpv4NodeId(int value) {
Jian Li597d7b22016-02-29 14:06:55 -080036 super(value);
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -070037 }
38
39 /**
40 * Returns an object of PcepNaiIpv4NodeId.
41 *
42 * @param value ipv4 node id
43 * @return object of PcepNaiIpv4NodeId
44 */
45 public static PcepNaiIpv4NodeId of(int value) {
46 return new PcepNaiIpv4NodeId(value);
47 }
48
49 @Override
50 public byte getType() {
51 return ST_TYPE;
52 }
53
54 @Override
55 public int write(ChannelBuffer bb) {
56 int iLenStartIndex = bb.writerIndex();
Jian Li597d7b22016-02-29 14:06:55 -080057 bb.writeInt(identifier);
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -070058 return bb.writerIndex() - iLenStartIndex;
59 }
60
61 /**
62 * Reads from the channel buffer and returns object of PcepNAIIpv4NodeIdVer1.
63 *
64 * @param bb of channel buffer.
65 * @return object of PcepNAIIpv4NodeIdVer1
66 */
67 public static PcepNaiIpv4NodeId read(ChannelBuffer bb) {
68 return new PcepNaiIpv4NodeId(bb.readInt());
69 }
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -070070}