blob: 2d76cf94ed7f76dccf27eb2725665f71a10c74b0 [file] [log] [blame]
Chidambar babu86b3b1a2016-02-16 17:39:52 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Chidambar babu86b3b1a2016-02-16 17:39:52 +05303 *
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.ospf.protocol.ospfpacket;
17
18import com.google.common.base.MoreObjects;
19import org.jboss.netty.buffer.ChannelBuffer;
20import org.onlab.packet.Ip4Address;
sunishvkf7c56552016-07-18 16:02:39 +053021import org.onosproject.ospf.controller.OspfMessage;
22import org.onosproject.ospf.controller.OspfPacketType;
Chidambar babu86b3b1a2016-02-16 17:39:52 +053023import org.onosproject.ospf.exceptions.OspfParseException;
Chidambar babu86b3b1a2016-02-16 17:39:52 +053024
25/**
26 * Defines the OSPF Packet Header, fields and access methods.
27 * Every OSPF packet starts with a standard 24 byte header.
28 * This header contains all the information necessary to determine whether
29 * the packet should be accepted for further processing
30 */
31public class OspfPacketHeader implements OspfMessage {
32
33 /*
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 | Version # | Type | Packet length |
38 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39 | Router ID |
40 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
41 | Area ID |
42 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
43 | Checksum | AuType |
44 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
45 | Authentication |
46 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
47 | Authentication |
48 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
49 */
50
51 private int ospfVer;
52 private int ospfType;
53 private int ospfPackLength;
54 private Ip4Address routerId;
55 private Ip4Address areaId;
56 private int checkSum;
57 private int auType;
58 private int authentication;
59 private Ip4Address destinationIp;
60 private Ip4Address sourceIp;
sunishvkf7c56552016-07-18 16:02:39 +053061 private int interfaceIndex;
Chidambar babu86b3b1a2016-02-16 17:39:52 +053062
63 /**
64 * Gets the source IP.
65 *
66 * @return source IP address
67 */
68 public Ip4Address sourceIp() {
69 return sourceIp;
70 }
71
72 /**
73 * Sets the source IP address.
74 *
75 * @param sourceIp source IP address
76 */
77 public void setSourceIp(Ip4Address sourceIp) {
78 this.sourceIp = sourceIp;
79 }
80
81 @Override
82 public OspfPacketType ospfMessageType() {
83 //default impl
84 return null;
85 }
86
87 @Override
88 public void readFrom(ChannelBuffer channelBuffer) throws OspfParseException {
89 //default impl
90 }
91
92 @Override
93 public byte[] asBytes() {
94 //default impl
95 return new byte[0];
96 }
97
98 /**
99 * Gets OSPF version.
100 *
101 * @return OSPF version
102 */
103 public int ospfVersion() {
104 return ospfVer;
105 }
106
107 /**
108 * Sets OSPF version.
109 *
110 * @param ospfVer OSPF version
111 */
112 public void setOspfVer(int ospfVer) {
113 this.ospfVer = ospfVer;
114 }
115
116 /**
117 * Gets OSPF packet type.
118 *
119 * @return OSPF packet type
120 */
121 public int ospfType() {
122 return ospfType;
123 }
124
125 /**
126 * Sets OSPF packet type.
127 *
128 * @param ospfType packet type
129 */
130 public void setOspftype(int ospfType) {
131 this.ospfType = ospfType;
132 }
133
134 /**
135 * Gets ospf packet length.
136 *
137 * @return OSPF packet length
138 */
139 public int ospfPacLength() {
140 return ospfPackLength;
141 }
142
143 /**
144 * Sets OSPF packet length.
145 *
146 * @param ospfPacLength packet length
147 */
148 public void setOspfPacLength(int ospfPacLength) {
149 this.ospfPackLength = ospfPacLength;
150 }
151
152 /**
153 * Gets router id.
154 *
155 * @return routerId
156 */
157 public Ip4Address routerId() {
158 return routerId;
159 }
160
161 /**
162 * Sets router id.
163 *
164 * @param routerId router id
165 */
166 public void setRouterId(Ip4Address routerId) {
167 this.routerId = routerId;
168 }
169
170 /**
171 * Gets area id.
172 *
173 * @return areaId area id
174 */
175 public Ip4Address areaId() {
176 return areaId;
177 }
178
179 /**
180 * Sets area id.
181 *
182 * @param areaId area id
183 */
184 public void setAreaId(Ip4Address areaId) {
185 this.areaId = areaId;
186 }
187
188 /**
189 * Gets checksum value.
190 *
191 * @return checkSum check sum value
192 */
193 public int checksum() {
194 return checkSum;
195 }
196
197 /**
198 * Sets checksum.
199 *
200 * @param checkSum check sum value
201 */
202 public void setChecksum(int checkSum) {
203 this.checkSum = checkSum;
204 }
205
206 /**
207 * Gets auth type.
208 *
209 * @return authType authentication type
210 */
211 public int authType() {
212 return auType;
213 }
214
215 /**
216 * Sets auth Type.
217 *
218 * @param auType authentication type
219 */
220 public void setAuthType(int auType) {
221 this.auType = auType;
222 }
223
224 /**
225 * Gets authentication.
226 *
227 * @return authentication
228 */
229 public int authentication() {
230 return authentication;
231 }
232
233 /**
234 * Sets authentication.
235 *
236 * @param authentication authentication
237 */
238 public void setAuthentication(int authentication) {
239 this.authentication = authentication;
240 }
241
242 /**
243 * Gets destination IP.
244 *
245 * @return destination IP
246 */
247 public Ip4Address destinationIp() {
248 return destinationIp;
249 }
250
251 /**
252 * Sets destination IP.
253 *
254 * @param destinationIp destination IP
255 */
256 public void setDestinationIp(Ip4Address destinationIp) {
257 this.destinationIp = destinationIp;
258 }
259
260 /**
sunishvkf7c56552016-07-18 16:02:39 +0530261 * Returns the interface index on which the message received.
262 *
263 * @return interface index on which the message received
264 */
265 public int interfaceIndex() {
266 return interfaceIndex;
267 }
268
269 /**
270 * Sets the interface index on which the message received.
271 *
272 * @param interfaceIndex interface index on which the message received
273 */
274 public void setInterfaceIndex(int interfaceIndex) {
275 this.interfaceIndex = interfaceIndex;
276 }
277
278 /**
Chidambar babu86b3b1a2016-02-16 17:39:52 +0530279 * Populates the header from the packetHeader instance.
280 *
281 * @param ospfPacketHeader packet header instance.
282 */
283 public void populateHeader(OspfPacketHeader ospfPacketHeader) {
sunishvkf7c56552016-07-18 16:02:39 +0530284 this.setInterfaceIndex(ospfPacketHeader.interfaceIndex());
Chidambar babu86b3b1a2016-02-16 17:39:52 +0530285 this.setSourceIp(ospfPacketHeader.sourceIp());
286 this.setOspfVer(ospfPacketHeader.ospfVersion());
287 this.setOspftype(ospfPacketHeader.ospfType());
288 this.setOspfPacLength(ospfPacketHeader.ospfPacLength());
289 this.setRouterId(ospfPacketHeader.routerId());
290 this.setAreaId(ospfPacketHeader.areaId());
291 this.setChecksum(ospfPacketHeader.checksum());
292 this.setAuthType(ospfPacketHeader.authType());
293 this.setAuthentication(ospfPacketHeader.authentication());
294 }
295
296 @Override
297 public String toString() {
298 return MoreObjects.toStringHelper(getClass())
299 .omitNullValues()
300 .add("ospfVersion", ospfVer)
301 .add("ospfType", ospfType)
302 .add("ospfPackLength", ospfPackLength)
303 .add("routerId", routerId)
304 .add("areaId", areaId)
305 .add("checkSum", checkSum)
306 .add("auType", auType)
307 .add("authentication", authentication)
308 .add("destinationIP", destinationIp)
309 .toString();
310 }
311}