blob: bf553a4bc12e61eb82ca7368d73c8f2f29afd26d [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 */
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 */
30public class RoutingUniverseTLV implements PcepValueType {
31
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
53 protected static final Logger log = LoggerFactory.getLogger(RoutingUniverseTLV.class);
54
55 public static final short TYPE = 14; // TODO:need to change TBD7
56 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 */
65 public RoutingUniverseTLV(long rawValue) {
66 this.rawValue = rawValue;
67 }
68
69 /**
70 * Returns object of RoutingUniverseTLV.
71 *
72 * @param raw value
73 * @return object of RoutingUniverseTLV
74 */
75 public static RoutingUniverseTLV of(final long raw) {
76 return new RoutingUniverseTLV(raw);
77 }
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 }
113 if (obj instanceof RoutingUniverseTLV) {
114 RoutingUniverseTLV other = (RoutingUniverseTLV) obj;
115 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 */
135 public static RoutingUniverseTLV read(ChannelBuffer c) {
136 return RoutingUniverseTLV.of(c.readLong());
137 }
138
139 @Override
140 public String toString() {
141 return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH).add("Value", rawValue)
142 .toString();
143 }
144}