Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 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.types; |
| 18 | |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 19 | import org.jboss.netty.buffer.ChannelBuffer; |
Jian Li | 597d7b2 | 2016-02-29 14:06:55 -0800 | [diff] [blame] | 20 | import org.onlab.util.Identifier; |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 21 | import org.onosproject.pcepio.protocol.PcepNai; |
| 22 | |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 23 | /** |
| 24 | * Provides Pcep Nai Ipv4 Node Id. |
| 25 | */ |
Jian Li | 597d7b2 | 2016-02-29 14:06:55 -0800 | [diff] [blame] | 26 | public class PcepNaiIpv4NodeId extends Identifier<Integer> implements PcepNai { |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 27 | |
| 28 | public static final byte ST_TYPE = 0x01; |
| 29 | |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 30 | /** |
| 31 | * Constructor to initialize ipv4NodeId. |
| 32 | * |
| 33 | * @param value ipv4 node id |
| 34 | */ |
| 35 | public PcepNaiIpv4NodeId(int value) { |
Jian Li | 597d7b2 | 2016-02-29 14:06:55 -0800 | [diff] [blame] | 36 | super(value); |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 37 | } |
| 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 Li | 597d7b2 | 2016-02-29 14:06:55 -0800 | [diff] [blame] | 57 | bb.writeInt(identifier); |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 58 | 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 SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 70 | } |