blob: c555da19faac11b61a5499ae89398e37857fb40d [file] [log] [blame]
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -07003 *
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 */
16package org.onosproject.pcepio.types;
17
18import java.util.Objects;
19
20import org.jboss.netty.buffer.ChannelBuffer;
21import org.onosproject.pcepio.protocol.PcepVersion;
22import org.slf4j.Logger;
23import org.slf4j.LoggerFactory;
24
25import com.google.common.base.MoreObjects;
26
27/**
28 * Provides RoutingUniverseTLV identifiers.
29 */
Sho SHIMIZUa5356ec2015-09-03 13:27:38 -070030public class RoutingUniverseTlv implements PcepValueType {
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -070031
32 /*
33 * Reference : draft-dhodylee-pce-pcep-te-data-extn-02, section 9.2.1.
34 * 0 1 2 3
35 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
36 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
37 | Type=[TBD7] | Length=8 |
38 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39 | Identifier |
40 | |
41 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42
43 *
44 *
45 * +------------+---------------------+
46 | Identifier | Routing Universe |
47 +------------+---------------------+
48 | 0 | L3 packet topology |
49 | 1 | L1 optical topology |
50 +------------+---------------------+
51 */
52
Ray Milkey9c9cde42018-01-12 14:22:06 -080053 private static final Logger log = LoggerFactory.getLogger(RoutingUniverseTlv.class);
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -070054
Mahesh Poojary Sf1bbd362016-02-25 18:19:59 +053055 public static final short TYPE = (short) 65281;
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -070056 public static final short LENGTH = 8;
57
58 private final long rawValue;
59
60 /**
61 * Constructor to initialize raw value.
62 *
63 * @param rawValue raw value
64 */
Sho SHIMIZUa5356ec2015-09-03 13:27:38 -070065 public RoutingUniverseTlv(long rawValue) {
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -070066 this.rawValue = rawValue;
67 }
68
69 /**
70 * Returns object of RoutingUniverseTLV.
71 *
72 * @param raw value
73 * @return object of RoutingUniverseTLV
74 */
Sho SHIMIZUa5356ec2015-09-03 13:27:38 -070075 public static RoutingUniverseTlv of(final long raw) {
76 return new RoutingUniverseTlv(raw);
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -070077 }
78
79 /**
80 * Returns raw value as Identifier.
81 *
82 * @return rawValue Identifier
83 */
84 public long getLong() {
85 return rawValue;
86 }
87
88 @Override
89 public PcepVersion getVersion() {
90 return PcepVersion.PCEP_1;
91 }
92
93 @Override
94 public short getType() {
95 return TYPE;
96 }
97
98 @Override
99 public short getLength() {
100 return LENGTH;
101 }
102
103 @Override
104 public int hashCode() {
105 return Objects.hash(rawValue);
106 }
107
108 @Override
109 public boolean equals(Object obj) {
110 if (this == obj) {
111 return true;
112 }
Sho SHIMIZUa5356ec2015-09-03 13:27:38 -0700113 if (obj instanceof RoutingUniverseTlv) {
114 RoutingUniverseTlv other = (RoutingUniverseTlv) obj;
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -0700115 return Objects.equals(this.rawValue, other.rawValue);
116 }
117 return false;
118 }
119
120 @Override
121 public int write(ChannelBuffer c) {
122 int iLenStartIndex = c.writerIndex();
123 c.writeShort(TYPE);
124 c.writeShort(LENGTH);
125 c.writeLong(rawValue);
126 return c.writerIndex() - iLenStartIndex;
127 }
128
129 /**
130 * Reads from channel buffer and returns object of RoutingUniverseTLV.
131 *
132 * @param c input channel buffer
133 * @return object of RoutingUniverseTLV
134 */
Sho SHIMIZUa5356ec2015-09-03 13:27:38 -0700135 public static RoutingUniverseTlv read(ChannelBuffer c) {
136 return RoutingUniverseTlv.of(c.readLong());
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -0700137 }
138
139 @Override
140 public String toString() {
Sho SHIMIZU7cdbcf72015-09-03 14:43:05 -0700141 return MoreObjects.toStringHelper(getClass())
142 .add("Type", TYPE)
143 .add("Length", LENGTH)
144 .add("Value", rawValue)
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -0700145 .toString();
146 }
147}