Kalyankumar Asangi
Committed by Gerrit Code Review

ONOS-2740,ONOS-2741,from ONOS-3032 - to ONOS 3071 , OSPF Protocol Implementation

Change-Id: Ie8cccca4aaf2641ab1e332ed367ddfc9b725a35c
1 +/*
2 + * Copyright 2016 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 +package org.onosproject.ospf.controller.area;
17 +
18 +import com.google.common.base.MoreObjects;
19 +import org.onosproject.ospf.controller.OspfProcess;
20 +
21 +import java.util.List;
22 +
23 +/**
24 + * Representation of an OSPF configuration data.
25 + */
26 +public class Configuration {
27 + private List<OspfProcess> processes;
28 + private String method;
29 +
30 + /**
31 + * Gets the configured processes.
32 + *
33 + * @return list of configured processes.
34 + */
35 + public List<OspfProcess> getProcesses() {
36 + return processes;
37 + }
38 +
39 + /**
40 + * Sets the configured processes.
41 + *
42 + * @param processes configured processes
43 + */
44 + public void setProcesses(List<OspfProcess> processes) {
45 + this.processes = processes;
46 + }
47 +
48 + /**
49 + * Gets whether to update, add or delete configuration.
50 + *
51 + * @return update, add or delete configuration
52 + */
53 + public String getMethod() {
54 + return method;
55 + }
56 +
57 + /**
58 + * Sets whether to update, add or delete configuration.
59 + *
60 + * @param method configuration method.
61 + */
62 + public void setMethod(String method) {
63 + this.method = method;
64 + }
65 +
66 +
67 + @Override
68 + public String toString() {
69 + return MoreObjects.toStringHelper(getClass())
70 + .omitNullValues()
71 + .add("method", method)
72 + .add("processes", processes)
73 + .toString();
74 + }
75 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 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 +package org.onosproject.ospf.controller.area;
17 +
18 +import com.google.common.base.MoreObjects;
19 +import com.google.common.base.Objects;
20 +import org.onlab.packet.Ip4Address;
21 +import org.onosproject.ospf.controller.OspfAreaAddressRange;
22 +
23 +/**
24 + * Representation of an area address ranges.
25 + * Address ranges are used in order to aggregate routing information at area boundaries.
26 + * Each address range is specified by an [address,mask] pair and a status indication of
27 + * either advertise or do not advertise
28 + */
29 +public class OspfAreaAddressRangeImpl implements OspfAreaAddressRange {
30 +
31 + public Ip4Address ipAddress;
32 + public String mask;
33 + public boolean advertise;
34 +
35 + /**
36 + * Gets the IP address.
37 + *
38 + * @return IP address
39 + */
40 + public Ip4Address ipAddress() {
41 + return ipAddress;
42 + }
43 +
44 + /**
45 + * Sets the IP address.
46 + *
47 + * @param ipAddress IP address
48 + */
49 + public void setIpAddress(Ip4Address ipAddress) {
50 + this.ipAddress = ipAddress;
51 + }
52 +
53 + /**
54 + * Gets the network mask.
55 + *
56 + * @return network mask
57 + */
58 + public String mask() {
59 + return mask;
60 + }
61 +
62 + /**
63 + * Sets the network mask.
64 + *
65 + * @param mask network mask value
66 + */
67 + public void setMask(String mask) {
68 + this.mask = mask;
69 + }
70 +
71 + /**
72 + * Gets the advertise value.
73 + *
74 + * @return advertise value
75 + */
76 + public boolean isAdvertise() {
77 + return advertise;
78 + }
79 +
80 + /**
81 + * Sets the advertise value.
82 + *
83 + * @param advertise advertise value
84 + */
85 + public void setAdvertise(boolean advertise) {
86 + this.advertise = advertise;
87 + }
88 +
89 + @Override
90 + public boolean equals(Object other) {
91 + if (!(other instanceof OspfAreaAddressRangeImpl)) {
92 + return false;
93 + }
94 + OspfAreaAddressRangeImpl otherAreaAddressRange = (OspfAreaAddressRangeImpl) other;
95 + return Objects.equal(ipAddress, otherAreaAddressRange.ipAddress) &&
96 + Objects.equal(mask, otherAreaAddressRange.mask) &&
97 + Objects.equal(advertise, otherAreaAddressRange.advertise);
98 + }
99 +
100 + @Override
101 + public int hashCode() {
102 + return Objects.hashCode(ipAddress, mask, advertise);
103 + }
104 +
105 + @Override
106 + public String toString() {
107 + return MoreObjects.toStringHelper(getClass())
108 + .omitNullValues()
109 + .add("ipAddress", ipAddress)
110 + .add("mask", mask)
111 + .add("advertise", advertise)
112 + .toString();
113 + }
114 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 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 +
17 +package org.onosproject.ospf.controller.area;
18 +
19 +import com.google.common.base.MoreObjects;
20 +import com.google.common.base.Objects;
21 +import org.onlab.packet.Ip4Address;
22 +import org.onosproject.ospf.controller.OspfInterface;
23 +import org.onosproject.ospf.controller.OspfNbr;
24 +import org.onosproject.ospf.protocol.lsa.LsaHeader;
25 +import org.onosproject.ospf.protocol.lsa.OpaqueLsaHeader;
26 +import org.onosproject.ospf.protocol.util.OspfInterfaceState;
27 +import org.onosproject.ospf.protocol.util.OspfParameters;
28 +import org.slf4j.Logger;
29 +import org.slf4j.LoggerFactory;
30 +
31 +import java.util.ArrayList;
32 +import java.util.HashMap;
33 +import java.util.List;
34 +import java.util.Set;
35 +
36 +/**
37 + * Representation of an OSPF interface.
38 + */
39 +public class OspfInterfaceImpl implements OspfInterface {
40 + private static final Logger log = LoggerFactory.getLogger(OspfInterfaceImpl.class);
41 + private Ip4Address ipAddress;
42 + private Ip4Address ipNetworkMask;
43 + private int areaId;
44 + private int helloIntervalTime;
45 + private int routerDeadIntervalTime;
46 + private int transmitDelay;
47 + private int routerPriority;
48 + private int systemInterfaceType;
49 + private int interfaceType;
50 + private int interfaceCost;
51 + private String authType;
52 + private String authKey;
53 + private int pollInterval;
54 + private int mtu;
55 + private int reTransmitInterval;
56 + private Ip4Address dr;
57 + private Ip4Address bdr;
58 + private OspfInterfaceState state;
59 + private List<LsaHeader> linkStateHeaders = new ArrayList<>();
60 + private HashMap<String, OspfNbr> listOfNeighbors = new HashMap<>();
61 + private HashMap<String, LsaHeader> listOfNeighborMap = new HashMap<>();
62 +
63 + /**
64 + * Gets the interface state.
65 + *
66 + * @return interfaceState state of the interface
67 + */
68 + public OspfInterfaceState state() {
69 + return state;
70 + }
71 +
72 + /**
73 + * Sets the interface state.
74 + *
75 + * @param ospfInterfaceState interface state enum instance
76 + */
77 + public void setState(OspfInterfaceState ospfInterfaceState) {
78 + this.state = ospfInterfaceState;
79 + }
80 +
81 + /**
82 + * Gets link state headers.
83 + *
84 + * @return get the list of lsa headers
85 + */
86 + public List<LsaHeader> linkStateHeaders() {
87 + Set<String> key = listOfNeighborMap.keySet();
88 + for (String keys : key) {
89 + LsaHeader lsaHeader = listOfNeighborMap.get(keys);
90 + linkStateHeaders.add(lsaHeader);
91 + }
92 + return linkStateHeaders;
93 + }
94 +
95 + /**
96 + * Gets IP network mask.
97 + *
98 + * @return network mask
99 + */
100 + public Ip4Address ipNetworkMask() {
101 + return ipNetworkMask;
102 + }
103 +
104 + /**
105 + * Sets IP network mask.
106 + *
107 + * @param ipNetworkMask network mask
108 + */
109 + @Override
110 + public void setIpNetworkMask(Ip4Address ipNetworkMask) {
111 + this.ipNetworkMask = ipNetworkMask;
112 + }
113 +
114 + /**
115 + * Adds neighboring router to list.
116 + *
117 + * @param ospfNbr ospfNbr instance
118 + */
119 + public void addNeighbouringRouter(OspfNbr ospfNbr) {
120 + listOfNeighbors.put(ospfNbr.neighborId().toString(), ospfNbr);
121 + }
122 +
123 + /**
124 + * Gets the neighbour details from listOfNeighbors map.
125 + *
126 + * @param neighborId neighbors id
127 + * @return ospfNbr neighbor instance
128 + */
129 + public OspfNbr neighbouringRouter(String neighborId) {
130 + return listOfNeighbors.get(neighborId);
131 + }
132 +
133 +
134 + /**
135 + * Adds LSAHeader to map.
136 + *
137 + * @param lsaHeader LSA header instance
138 + */
139 + public void addLsaHeaderForDelayAck(LsaHeader lsaHeader) {
140 + String key = lsaHeader.lsType() + "-" + lsaHeader.linkStateId() + "-" +
141 + lsaHeader.advertisingRouter();
142 + if (lsaHeader.lsType() == OspfParameters.LINK_LOCAL_OPAQUE_LSA ||
143 + lsaHeader.lsType() == OspfParameters.AREA_LOCAL_OPAQUE_LSA ||
144 + lsaHeader.lsType() == OspfParameters.AS_OPAQUE_LSA) {
145 + OpaqueLsaHeader header = (OpaqueLsaHeader) lsaHeader;
146 + key = lsaHeader.lsType() + "-" + header.opaqueType() + header.opaqueId()
147 + + "-" + lsaHeader.advertisingRouter();
148 + }
149 +
150 + log.debug("Adding LSA key {} for delayed Ack", key);
151 + listOfNeighborMap.put(key, lsaHeader);
152 + }
153 +
154 + /**
155 + * Removes LSA header from map.
156 + *
157 + * @param lsaKey key used to store LSA in map
158 + */
159 + public void removeLsaFromNeighborMap(String lsaKey) {
160 + listOfNeighborMap.remove(lsaKey);
161 + }
162 +
163 + /**
164 + * Checks neighbor is in the list or not.
165 + *
166 + * @param neighborId neighbors id
167 + * @return true if neighbor in list else false
168 + */
169 + public boolean isNeighborInList(String neighborId) {
170 + return listOfNeighbors.containsKey(neighborId);
171 + }
172 +
173 + /**
174 + * Gets the list of neighbors.
175 + *
176 + * @return listOfNeighbors as key value pair
177 + */
178 + public HashMap<String, OspfNbr> listOfNeighbors() {
179 + return listOfNeighbors;
180 + }
181 +
182 + /**
183 + * Sets the list of neighbors.
184 + *
185 + * @param listOfNeighbors as key value pair
186 + */
187 + public void setListOfNeighbors(HashMap<String, OspfNbr> listOfNeighbors) {
188 + this.listOfNeighbors = listOfNeighbors;
189 + }
190 +
191 + /**
192 + * Gets the IP address.
193 + *
194 + * @return IP address
195 + */
196 + public Ip4Address ipAddress() {
197 + return ipAddress;
198 + }
199 +
200 + /**
201 + * Sets the interface IP address.
202 + *
203 + * @param ipAddress interface IP address
204 + */
205 + public void setIpAddress(Ip4Address ipAddress) {
206 + this.ipAddress = ipAddress;
207 + }
208 +
209 + /**
210 + * Gets router priority.
211 + *
212 + * @return routerPriority value
213 + */
214 + public int routerPriority() {
215 + return routerPriority;
216 + }
217 +
218 + /**
219 + * Sets router priority.
220 + *
221 + * @param routerPriority value
222 + */
223 + public void setRouterPriority(int routerPriority) {
224 + this.routerPriority = routerPriority;
225 + }
226 +
227 + /**
228 + * Gets the area id this interface belongs.
229 + *
230 + * @return area id this interface belongs
231 + */
232 + public int areaId() {
233 + return areaId;
234 + }
235 +
236 +
237 + /**
238 + * Sets the area id this interface belongs.
239 + *
240 + * @param areaId the area id this interface belongs
241 + */
242 + public void setAreaId(int areaId) {
243 + this.areaId = areaId;
244 + }
245 +
246 + /**
247 + * Gets hello interval time.
248 + *
249 + * @return hello interval time
250 + */
251 + public int helloIntervalTime() {
252 + return helloIntervalTime;
253 + }
254 +
255 + /**
256 + * Sets hello interval time.
257 + *
258 + * @param helloIntervalTime an integer interval time
259 + */
260 + public void setHelloIntervalTime(int helloIntervalTime) {
261 + this.helloIntervalTime = helloIntervalTime;
262 + }
263 +
264 + /**
265 + * Gets router dead interval time.
266 + *
267 + * @return router dead interval time
268 + */
269 + public int routerDeadIntervalTime() {
270 + return routerDeadIntervalTime;
271 + }
272 +
273 + /**
274 + * Sets router dead interval time.
275 + *
276 + * @param routerDeadIntervalTime router dead interval time
277 + */
278 + public void setRouterDeadIntervalTime(int routerDeadIntervalTime) {
279 + this.routerDeadIntervalTime = routerDeadIntervalTime;
280 + }
281 +
282 + /**
283 + * Gets interface type.
284 + *
285 + * @return interfaceType an integer represents interface type
286 + */
287 + public int interfaceType() {
288 + return interfaceType;
289 + }
290 +
291 + /**
292 + * Sets interface type.
293 + *
294 + * @param interfaceType interface type
295 + */
296 + public void setInterfaceType(int interfaceType) {
297 + this.interfaceType = interfaceType;
298 + }
299 +
300 + /**
301 + * Gets interface cost.
302 + *
303 + * @return interface cost
304 + */
305 + public int interfaceCost() {
306 + return interfaceCost;
307 + }
308 +
309 + /**
310 + * Sets interface cost.
311 + *
312 + * @param interfaceCost interface cost
313 + */
314 + public void setInterfaceCost(int interfaceCost) {
315 + this.interfaceCost = interfaceCost;
316 + }
317 +
318 + /**
319 + * Gets authentication type.
320 + *
321 + * @return authType represents authentication type
322 + */
323 + public String authType() {
324 + return authType;
325 + }
326 +
327 + /**
328 + * Sets authentication type.
329 + *
330 + * @param authType authType represents authentication type
331 + */
332 + public void setAuthType(String authType) {
333 + this.authType = authType;
334 + }
335 +
336 + /**
337 + * Gets authentication key.
338 + *
339 + * @return authKey represents authentication key
340 + */
341 + public String authKey() {
342 + return authKey;
343 + }
344 +
345 + /**
346 + * Sets authentication key.
347 + *
348 + * @param authKey represents authentication key
349 + */
350 + public void setAuthKey(String authKey) {
351 + this.authKey = authKey;
352 + }
353 +
354 + /**
355 + * Gets poll interval.
356 + *
357 + * @return pollInterval an integer represents poll interval
358 + */
359 + public int pollInterval() {
360 + return pollInterval;
361 + }
362 +
363 + /**
364 + * Sets poll interval.
365 + *
366 + * @param pollInterval an integer represents poll interval
367 + */
368 + public void setPollInterval(int pollInterval) {
369 + this.pollInterval = pollInterval;
370 + }
371 +
372 + /**
373 + * Gets max transfer unit.
374 + *
375 + * @return mtu an integer represents max transfer unit
376 + */
377 + public int mtu() {
378 + return mtu;
379 + }
380 +
381 + /**
382 + * Sets max transfer unit.
383 + *
384 + * @param mtu max transfer unit
385 + */
386 + public void setMtu(int mtu) {
387 + this.mtu = mtu;
388 + }
389 +
390 + /**
391 + * Gets retransmit interval.
392 + *
393 + * @return retransmit interval
394 + */
395 + public int reTransmitInterval() {
396 + return reTransmitInterval;
397 + }
398 +
399 + /**
400 + * Sets retransmit interval.
401 + *
402 + * @param reTransmitInterval retransmit interval
403 + */
404 + public void setReTransmitInterval(int reTransmitInterval) {
405 + this.reTransmitInterval = reTransmitInterval;
406 + }
407 +
408 + /**
409 + * Gets designated routers IP address.
410 + *
411 + * @return dr designated routers IP address
412 + */
413 + public Ip4Address dr() {
414 + return dr;
415 + }
416 +
417 + /**
418 + * Sets designated routers IP address.
419 + *
420 + * @param dr designated routers IP address
421 + */
422 + public void setDr(Ip4Address dr) {
423 + this.dr = dr;
424 + }
425 +
426 + /**
427 + * Gets backup designated routers IP address.
428 + *
429 + * @return bdr backup designated routers IP address
430 + */
431 + public Ip4Address bdr() {
432 + return bdr;
433 + }
434 +
435 + /**
436 + * Sets backup designated routers IP address.
437 + *
438 + * @param bdr backup designated routers IP address
439 + */
440 + public void setBdr(Ip4Address bdr) {
441 + this.bdr = bdr;
442 + }
443 +
444 + /**
445 + * Get transmission delay.
446 + *
447 + * @return transmission delay
448 + */
449 + public int transmitDelay() {
450 + return transmitDelay;
451 + }
452 +
453 + /**
454 + * Sets transmission delay.
455 + *
456 + * @param transmitDelay transmission delay
457 + */
458 + public void setTransmitDelay(int transmitDelay) {
459 + this.transmitDelay = transmitDelay;
460 + }
461 +
462 + @Override
463 + public boolean equals(Object o) {
464 + if (this == o) {
465 + return true;
466 + }
467 + if (o == null || getClass() != o.getClass()) {
468 + return false;
469 + }
470 + OspfInterfaceImpl that = (OspfInterfaceImpl) o;
471 + return Objects.equal(areaId, that.areaId) &&
472 + Objects.equal(helloIntervalTime, that.helloIntervalTime) &&
473 + Objects.equal(routerDeadIntervalTime, that.routerDeadIntervalTime) &&
474 + Objects.equal(transmitDelay, that.transmitDelay) &&
475 + Objects.equal(routerPriority, that.routerPriority) &&
476 + Objects.equal(systemInterfaceType, that.systemInterfaceType) &&
477 + Objects.equal(interfaceType, that.interfaceType) &&
478 + Objects.equal(interfaceCost, that.interfaceCost) &&
479 + Objects.equal(pollInterval, that.pollInterval) &&
480 + Objects.equal(mtu, that.mtu) &&
481 + Objects.equal(reTransmitInterval, that.reTransmitInterval) &&
482 + Objects.equal(ipAddress, that.ipAddress) &&
483 + Objects.equal(ipNetworkMask, that.ipNetworkMask) &&
484 + Objects.equal(listOfNeighbors, that.listOfNeighbors) &&
485 + Objects.equal(authType, that.authType) &&
486 + Objects.equal(authKey, that.authKey) &&
487 + Objects.equal(dr, that.dr) &&
488 + Objects.equal(bdr, that.bdr);
489 + }
490 +
491 + @Override
492 + public int hashCode() {
493 + return Objects.hashCode(ipAddress, ipNetworkMask, areaId, helloIntervalTime,
494 + routerDeadIntervalTime, transmitDelay, routerPriority, listOfNeighbors,
495 + systemInterfaceType, interfaceType, interfaceCost, authType, authKey,
496 + pollInterval, mtu, reTransmitInterval, dr, bdr);
497 + }
498 +
499 + @Override
500 + public String toString() {
501 + return MoreObjects.toStringHelper(getClass())
502 + .omitNullValues()
503 + .add("ipAddress", ipAddress)
504 + .add("routerPriority", routerPriority)
505 + .add("areaID", areaId)
506 + .add("helloIntervalTime", helloIntervalTime)
507 + .add("routerDeadIntervalTime", routerDeadIntervalTime)
508 + .add("interfaceType", interfaceType)
509 + .add("interfaceCost", interfaceCost)
510 + .add("authType", authType)
511 + .add("authKey", authKey)
512 + .add("pollInterval", pollInterval)
513 + .add("mtu", mtu)
514 + .add("reTransmitInterval", reTransmitInterval)
515 + .add("dr", dr)
516 + .add("bdr", bdr)
517 + .add("transmitDelay", transmitDelay)
518 + .toString();
519 + }
520 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 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 +package org.onosproject.ospf.controller.area;
17 +
18 +import com.fasterxml.jackson.annotation.JsonProperty;
19 +import com.google.common.base.MoreObjects;
20 +import org.onosproject.ospf.controller.OspfArea;
21 +import org.onosproject.ospf.controller.OspfProcess;
22 +
23 +import java.util.List;
24 +
25 +/**
26 + * Representation of the configuration data for OSPF Process, which will be configured using rest URI.
27 + */
28 +public class OspfProcessImpl implements OspfProcess {
29 +
30 + private String processId;
31 + private List<OspfArea> areas;
32 +
33 + /**
34 + * Gets the list of areas belonging to this process.
35 + *
36 + * @return list of areas belonging to this process
37 + */
38 + public List<OspfArea> areas() {
39 + return areas;
40 + }
41 +
42 + /**
43 + * Sets the list of areas belonging to this process.
44 + *
45 + * @param areas list of areas belonging to this process
46 + */
47 + @JsonProperty("areas")
48 + public void setAreas(List<OspfArea> areas) {
49 + this.areas = areas;
50 + }
51 +
52 + /**
53 + * Gets the process id.
54 + *
55 + * @return process id
56 + */
57 + public String processId() {
58 + return processId;
59 + }
60 +
61 + /**
62 + * Sets the process id.
63 + *
64 + * @param processId the process id
65 + */
66 + @JsonProperty("processId")
67 + public void setProcessId(String processId) {
68 + this.processId = processId;
69 + }
70 +
71 + @Override
72 + public String toString() {
73 + return MoreObjects.toStringHelper(getClass())
74 + .omitNullValues()
75 + .add("areas", areas)
76 + .toString();
77 + }
78 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 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 +
17 +/**
18 + * Implementation of the OSPF controller.
19 + */
20 +package org.onosproject.ospf.controller.area;
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 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 +package org.onosproject.ospf.controller.impl;
17 +
18 +import org.jboss.netty.bootstrap.ServerBootstrap;
19 +import org.jboss.netty.channel.AdaptiveReceiveBufferSizePredictor;
20 +import org.jboss.netty.channel.ChannelPipelineFactory;
21 +import org.jboss.netty.channel.FixedReceiveBufferSizePredictorFactory;
22 +import org.jboss.netty.channel.group.ChannelGroup;
23 +import org.jboss.netty.channel.group.DefaultChannelGroup;
24 +import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
25 +import org.onosproject.net.driver.DriverService;
26 +import org.onosproject.ospf.controller.OspfAgent;
27 +import org.onosproject.ospf.controller.OspfArea;
28 +import org.onosproject.ospf.controller.OspfInterface;
29 +import org.onosproject.ospf.controller.OspfLinkTed;
30 +import org.onosproject.ospf.controller.OspfProcess;
31 +import org.onosproject.ospf.controller.OspfRouter;
32 +import org.slf4j.Logger;
33 +import org.slf4j.LoggerFactory;
34 +
35 +import java.net.InetAddress;
36 +import java.net.InetSocketAddress;
37 +import java.net.NetworkInterface;
38 +import java.net.SocketException;
39 +import java.util.ArrayList;
40 +import java.util.Collections;
41 +import java.util.Enumeration;
42 +import java.util.HashSet;
43 +import java.util.Iterator;
44 +import java.util.List;
45 +import java.util.Set;
46 +import java.util.concurrent.Executor;
47 +import java.util.concurrent.Executors;
48 +
49 +/**
50 + * Representation of the main controller class. Handles all setup and network listeners.
51 + */
52 +public class Controller {
53 +
54 + protected static final Logger log = LoggerFactory.getLogger(Controller.class);
55 + protected static final int BUFFER_SIZE = 4 * 1024 * 1024;
56 + private static final String PROCESS = "process";
57 + private static final String AREA = "area";
58 + private static final String INTERFACE = "interface";
59 +
60 + protected int ospfPort = 7000;
61 + protected int workerThreads = 16;
62 + protected long systemStartTime;
63 + private DriverService driverService;
64 + private OspfAgent agent;
65 + private List<ChannelGroup> cgList = new ArrayList();
66 + private List<NioServerSocketChannelFactory> execFactoryLst = new ArrayList<>();
67 + private List<OspfProcess> processes;
68 +
69 + /**
70 + * Gets all configured processes.
71 + *
72 + * @return all configured processes
73 + */
74 + public List<OspfProcess> getAllConfiguredProcesses() {
75 + return processes;
76 + }
77 +
78 + /**
79 + * Adds device details.
80 + *
81 + * @param ospfRouter OSPF router instance
82 + */
83 + public void addDeviceDetails(OspfRouter ospfRouter) {
84 + agent.addConnectedRouter(ospfRouter);
85 + }
86 +
87 + /**
88 + * Removes device details.
89 + *
90 + * @param ospfRouter OSPF router instance
91 + */
92 + public void removeDeviceDetails(OspfRouter ospfRouter) {
93 + agent.removeConnectedRouter(ospfRouter);
94 + }
95 +
96 + /**
97 + * Adds link details.
98 + *
99 + * @param ospfRouter OSPF router instance
100 + * @param ospfLinkTed OSPF link ted instance
101 + */
102 + public void addLinkDetails(OspfRouter ospfRouter, OspfLinkTed ospfLinkTed) {
103 + agent.addLink(ospfRouter, ospfLinkTed);
104 + }
105 +
106 + /**
107 + * Removes link details.
108 + *
109 + * @param ospfRouter OSPF router instance
110 + */
111 + public void removeLinkDetails(OspfRouter ospfRouter) {
112 + agent.deleteLink(ospfRouter);
113 + }
114 +
115 + /**
116 + * Creates a server bootstrap.
117 + *
118 + * @return ServerBootstrap bootstrap instance
119 + */
120 + private ServerBootstrap createServerBootStrap() {
121 +
122 + Executor bossPool = Executors.newCachedThreadPool();
123 + Executor workerPool = Executors.newCachedThreadPool();
124 + NioServerSocketChannelFactory executerFactory;
125 +
126 + if (workerThreads == 0) {
127 + executerFactory = new NioServerSocketChannelFactory(bossPool, workerPool);
128 + execFactoryLst.add(executerFactory);
129 + } else {
130 + executerFactory = new NioServerSocketChannelFactory(bossPool, workerPool, workerThreads);
131 + execFactoryLst.add(executerFactory);
132 + }
133 +
134 + return new ServerBootstrap(executerFactory);
135 + }
136 +
137 +
138 + /**
139 + * Initializes internal data structures.
140 + */
141 + public void init() {
142 + this.systemStartTime = System.currentTimeMillis();
143 + }
144 +
145 + /**
146 + * Starts the controller.
147 + *
148 + * @param ag OSPF agent instance
149 + * @param driverService driver service instance
150 + */
151 + public void start(OspfAgent ag, DriverService driverService) {
152 + log.info("Starting OSPF Controller...!!!");
153 + this.agent = ag;
154 + this.driverService = driverService;
155 + this.init();
156 + }
157 +
158 + /**
159 + * Stops the Controller.
160 + */
161 + public void stop() {
162 + log.info("Stopping OSPF Controller...!!!");
163 +
164 + for (ChannelGroup cg : cgList) {
165 + cg.close();
166 + }
167 +
168 + for (NioServerSocketChannelFactory execFactory : execFactoryLst) {
169 + execFactory.shutdown();
170 + }
171 +
172 + processes.clear();
173 + }
174 +
175 + /**
176 + * Deletes configured interface from the area.
177 + *
178 + * @param processId process id
179 + * @param areaId area id
180 + * @param interfaceToDelete interface to delete
181 + * @return true if operation success else false
182 + */
183 + public boolean deleteInterfaceFromArea(String processId, String areaId, String interfaceToDelete) {
184 + Iterator<OspfProcess> processItr = processes.iterator();
185 +
186 + while (processItr.hasNext()) {
187 + OspfProcess process = processItr.next();
188 + if (processId.equalsIgnoreCase(process.processId())) {
189 + Iterator<OspfArea> areaItr = process.areas().iterator();
190 + while (areaItr.hasNext()) {
191 + OspfArea area = areaItr.next();
192 + Iterator<OspfInterface> ospfIntrItr = area.getInterfacesLst().iterator();
193 + if (area.areaId().toString().equalsIgnoreCase(areaId)) {
194 + while (ospfIntrItr.hasNext()) {
195 + OspfInterface ospfIntr = ospfIntrItr.next();
196 + if (interfaceToDelete.equalsIgnoreCase(ospfIntr.ipAddress().toString())) {
197 + ospfIntrItr.remove();
198 + log.debug("Interface With Id {} is removed from Area {}",
199 + ospfIntr.ipAddress(), ospfIntr.areaId());
200 + return true;
201 + }
202 + }
203 + }
204 + }
205 + }
206 + }
207 +
208 + return false;
209 + }
210 +
211 + /*
212 + * Checks area with area id exists in process.
213 + *
214 + * @param processId process id
215 + * @param areaId area id
216 + * @return true if exist else false
217 + */
218 + public boolean checkArea(String processId, String areaId) {
219 + for (OspfProcess process : processes) {
220 + if (processId.equalsIgnoreCase(process.processId())) {
221 + for (OspfArea area : process.areas()) {
222 + if (area.areaId().toString().equalsIgnoreCase(areaId)) {
223 + return true;
224 + }
225 + }
226 + }
227 + }
228 + return false;
229 + }
230 +
231 + /*
232 + * Checks process with process id exists or not.
233 + *
234 + * @param processId process id
235 + * @return true if exist else false
236 + */
237 + public boolean checkProcess(String processId) {
238 + log.debug("CheckProcess,Process Id ={} processes={}", processId, processes);
239 + for (OspfProcess process : processes) {
240 + if (processId.equalsIgnoreCase(process.processId())) {
241 + return true;
242 + }
243 + }
244 + return false;
245 + }
246 +
247 + /*
248 + * Checks interface exists in given area.
249 + *
250 + * @param processId process id
251 + * @param areaId area id
252 + * @param ipAddress interface
253 + * @return true if exist else false
254 + */
255 + public boolean checkInterface(String processId, String areaId, String interfaceIp) {
256 + for (OspfProcess process : processes) {
257 + if (processId.equalsIgnoreCase(process.processId())) {
258 + for (OspfArea area : process.areas()) {
259 + if (area.areaId().toString().equalsIgnoreCase(areaId)) {
260 + for (OspfInterface ospfInterface : area.getInterfacesLst()) {
261 + if (ospfInterface.ipAddress().toString().equalsIgnoreCase(interfaceIp)) {
262 + return true;
263 + }
264 + }
265 + }
266 + }
267 + }
268 + }
269 + return false;
270 + }
271 +
272 + /**
273 + * Create processes first time when no process exist.
274 + * Create server bootstraps for all the interfaces in the processes.
275 + *
276 + * @param ospfProcesses list of OSPF processes to create
277 + */
278 + private void createProcessWhenNoProcessesExists(List<OspfProcess> ospfProcesses) {
279 + Set<String> interfaceIpList = new HashSet<>();
280 + Set<String> areaIdList = new HashSet<>();
281 + if (processes != null) {
282 + if (processes.size() == 0) {
283 +
284 + processes.addAll(ospfProcesses);
285 + for (OspfProcess process : ospfProcesses) {
286 + for (OspfArea area : process.areas()) {
287 + areaIdList.add(area.areaId().toString());
288 + for (OspfInterface intrfc : area.getInterfacesLst()) {
289 + interfaceIpList.add(intrfc.ipAddress().toString());
290 + }
291 + }
292 + }
293 + createBootStrapForCreatedInterface(interfaceIpList, areaIdList);
294 + }
295 + } else {
296 + processes = new ArrayList<>();
297 + processes.addAll(ospfProcesses);
298 +
299 + for (OspfProcess process : ospfProcesses) {
300 + for (OspfArea area : process.areas()) {
301 + areaIdList.add(area.areaId().toString());
302 + for (OspfInterface intrfc : area.getInterfacesLst()) {
303 + interfaceIpList.add(intrfc.ipAddress().toString());
304 + }
305 + }
306 + }
307 + createBootStrapForCreatedInterface(interfaceIpList, areaIdList);
308 + }
309 + }
310 +
311 + /**
312 + * Creates processes when already process exist.
313 + * It can be modifying existing process or adding a new process.
314 + *
315 + * @param ospfProcesses list of processes
316 + */
317 + private void createProcessWhenProcessesExists(List<OspfProcess> ospfProcesses) {
318 + if (ospfProcesses != null) {
319 + for (OspfProcess process : ospfProcesses) {
320 + if (!checkProcess(process.processId())) {
321 + createNewProcess(process.processId(), process);
322 + } else {
323 + List<OspfArea> areas = process.areas();
324 + for (OspfArea area : areas) {
325 + if (!checkArea(process.processId(), area.areaId().toString())) {
326 + createAreaInProcess(process.processId(),
327 + area.areaId().toString(), area);
328 + } else {
329 + updateAreaInProcess(process.processId(), area.areaId().toString(), area);
330 + for (OspfInterface interfc : area.getInterfacesLst()) {
331 + if (!checkInterface(process.processId(),
332 + area.areaId().toString(), interfc.ipAddress().toString())) {
333 + createInterfaceInAreaInProcess(process.processId(),
334 + area.areaId().toString(), interfc);
335 + } else {
336 + updateInterfaceParameters(process.processId(),
337 + area.areaId().toString(),
338 + interfc.ipAddress().toString(), interfc);
339 + }
340 + }
341 + }
342 + }
343 + }
344 + }
345 + }
346 + }
347 +
348 + /**
349 + * Updates the area information in already started OSPF processes.
350 + *
351 + * @param processId process id
352 + * @param areaId area id
353 + * @param areaFrmConfig area to update
354 + */
355 + public void updateAreaInProcess(String processId, String areaId, OspfArea areaFrmConfig) {
356 + if (processes != null) {
357 + Iterator<OspfProcess> processItr = processes.iterator();
358 + while (processItr.hasNext()) {
359 + OspfProcess process = processItr.next();
360 + if (processId.equalsIgnoreCase(process.processId())) {
361 + Iterator<OspfArea> area = process.areas().iterator();
362 + while (area.hasNext()) {
363 + OspfArea ospfArea = area.next();
364 + if (areaId.equalsIgnoreCase(ospfArea.areaId().toString())) {
365 + ospfArea.setAddressRanges(areaFrmConfig.addressRanges());
366 + ospfArea.setRouterId(areaFrmConfig.routerId());
367 + ospfArea.setTransitCapability(areaFrmConfig.isTransitCapability());
368 + ospfArea.setExternalRoutingCapability(areaFrmConfig.isExternalRoutingCapability());
369 + ospfArea.setStubCost(areaFrmConfig.stubCost());
370 + ospfArea.setOptions(areaFrmConfig.options());
371 + ospfArea.setIsOpaqueEnabled(areaFrmConfig.isOpaqueEnabled());
372 + log.debug("updateAreaInProcess::Process Id::{}::Ospf Area with Id::{}::is " +
373 + "updated", processId, areaId);
374 + }
375 + }
376 + }
377 + }
378 + }
379 + }
380 +
381 + /**
382 + * Updates the processes configuration.
383 + *
384 + * @param ospfProcesses list of OSPF processes
385 + */
386 + public void updateConfig(List<OspfProcess> ospfProcesses) {
387 + log.info("Controller::UpdateConfig called");
388 + if (processes != null) {
389 + if (processes.size() == 0) {
390 + createProcessWhenNoProcessesExists(ospfProcesses);
391 + } else {
392 + createProcessWhenProcessesExists(ospfProcesses);
393 + }
394 + } else {
395 + createProcessWhenNoProcessesExists(ospfProcesses);
396 + }
397 + }
398 +
399 + /**
400 + * Deletes configuration.
401 + *
402 + * @param ospfProcesses OSPF processes
403 + * @param attribute attribute to delete
404 + */
405 + public void deleteConfig(List<OspfProcess> ospfProcesses, String attribute) {
406 + log.info("Controller::UpdateConfig called");
407 + if (processes != null) {
408 + if (processes.size() == 0) {
409 + log.debug("DeleteConfig:: No process exists");
410 + } else {
411 + deleteProcessWhenExists(ospfProcesses, attribute);
412 + }
413 + } else {
414 + log.debug("DeleteConfig:: No process exists");
415 + }
416 + }
417 +
418 + /**
419 + * Creates a new process.
420 + *
421 + * @param processId process id
422 + * @param process OSPF process instance
423 + */
424 + private void createNewProcess(String processId, OspfProcess process) {
425 + Set<String> interfaceIpList = new HashSet<>();
426 + Set<String> areaIdList = new HashSet<>();
427 +
428 + processes.add(process);
429 + for (OspfArea area : process.areas()) {
430 + areaIdList.add(area.areaId().toString());
431 + for (OspfInterface interfc : area.getInterfacesLst()) {
432 + interfaceIpList.add(interfc.ipAddress().toString());
433 + }
434 + }
435 + log.debug("createNewProcess::List of areas in process::{} areas::{}", processId, areaIdList);
436 +
437 + createBootStrapForCreatedInterface(interfaceIpList, areaIdList);
438 +
439 + log.debug("createNewProcess:: all processes::{}", processes);
440 + }
441 +
442 + /**
443 + * Creates a new area information in the process.
444 + *
445 + * @param processId process id
446 + * @param areaId area id
447 + * @param area OSPF area instance
448 + */
449 + private void createAreaInProcess(String processId, String areaId, OspfArea area) {
450 + Set<String> interfaceIpList = new HashSet<>();
451 + Set<String> areaIdList = new HashSet<>();
452 +
453 + Iterator<OspfProcess> processItr = processes.iterator();
454 + while (processItr.hasNext()) {
455 + OspfProcess process = processItr.next();
456 + List<OspfArea> areasInProcess = process.areas();
457 + if (processId.equalsIgnoreCase(process.processId())) {
458 + areasInProcess.add(area);
459 +
460 + for (OspfInterface intrfc : area.getInterfacesLst()) {
461 + interfaceIpList.add(intrfc.ipAddress().toString());
462 + }
463 + areaIdList.add(area.areaId().toString());
464 + log.debug("createAreaInProcess::List of areas in process Id::{} " +
465 + "AreaId ::{} update process::{}",
466 + processId, areaId, process);
467 + }
468 + }
469 + createBootStrapForCreatedInterface(interfaceIpList, areaIdList);
470 + log.debug("createAreaInProcess:: all processes::{}", processes);
471 + }
472 +
473 + /**
474 + * Creates an interface in the given area and process.
475 + *
476 + * @param processId process id
477 + * @param areaId area id
478 + * @param ospfInterface OSPF interface instance
479 + */
480 + private void createInterfaceInAreaInProcess(String processId,
481 + String areaId, OspfInterface ospfInterface) {
482 + Set<String> interfaceIpList = new HashSet<>();
483 + Set<String> areaIdList = new HashSet<>();
484 +
485 + Iterator<OspfProcess> processItr = processes.iterator();
486 + while (processItr.hasNext()) {
487 + OspfProcess process = processItr.next();
488 + List<OspfArea> areasInProcess = process.areas();
489 + if (processId.equalsIgnoreCase(process.processId())) {
490 + Iterator<OspfArea> areaItr = areasInProcess.iterator();
491 + while (areaItr.hasNext()) {
492 + OspfArea area = areaItr.next();
493 + if (areaId.equalsIgnoreCase(area.areaId().toString())) {
494 + area.getInterfacesLst().add(ospfInterface);
495 + interfaceIpList.add(ospfInterface.ipAddress().toString());
496 +
497 + log.debug("createInterfaceInAreaInProcess::Interface " +
498 + "updated in process Id::{} AreaId ::{} Interface List{}",
499 + processId, areaId, area.getInterfacesLst());
500 +
501 + }
502 + }
503 + }
504 + }
505 + createBootStrapForCreatedInterface(interfaceIpList, areaIdList);
506 + log.debug("createInterfaceInAreaInProcess:: all processes::{}", processes);
507 + }
508 +
509 + /**
510 + * Updates interface parameters.
511 + *
512 + * @param processId process id
513 + * @param areaId area id
514 + * @param interfaceId interface id
515 + * @param ospfInterface OSPF interface instance
516 + */
517 + private void updateInterfaceParameters(String processId, String areaId, String interfaceId,
518 + OspfInterface ospfInterface) {
519 + Iterator<OspfProcess> processItr = processes.iterator();
520 + while (processItr.hasNext()) {
521 + OspfProcess process = processItr.next();
522 + if (processId.equalsIgnoreCase(process.processId())) {
523 + Iterator<OspfArea> areItr = process.areas().iterator();
524 + while (areItr.hasNext()) {
525 + OspfArea area = (OspfArea) areItr.next();
526 + if (area.areaId().toString().equalsIgnoreCase(areaId)) {
527 + Iterator<OspfInterface> intfcList = area.getInterfacesLst().iterator();
528 + while (intfcList.hasNext()) {
529 + OspfInterface intrfcObj = intfcList.next();
530 + if (interfaceId.equalsIgnoreCase(intrfcObj.ipAddress().toString())) {
531 + intrfcObj.setPollInterval(ospfInterface.pollInterval());
532 + intrfcObj.setTransmitDelay(ospfInterface.transmitDelay());
533 + intrfcObj.setBdr(ospfInterface.bdr());
534 + intrfcObj.setDr(ospfInterface.dr());
535 + intrfcObj.setAuthKey(ospfInterface.authKey());
536 + intrfcObj.setAuthType(ospfInterface.authType());
537 + intrfcObj.setHelloIntervalTime(ospfInterface.helloIntervalTime());
538 + intrfcObj.setReTransmitInterval(ospfInterface.reTransmitInterval());
539 + intrfcObj.setMtu(ospfInterface.mtu());
540 + intrfcObj.setInterfaceCost(ospfInterface.interfaceCost());
541 + intrfcObj.setInterfaceType(ospfInterface.interfaceType());
542 + intrfcObj.setRouterDeadIntervalTime(ospfInterface.routerDeadIntervalTime());
543 + intrfcObj.setRouterPriority(ospfInterface.routerPriority());
544 + intrfcObj.setIpNetworkMask(ospfInterface.ipNetworkMask());
545 + log.debug("updateInterfaceParameters::Interface updated in " +
546 + "process Id::{} AreaId ::{} Interface Id:{} " +
547 + "Updated Interface List: {}", processId, areaId,
548 + interfaceId, intfcList);
549 + }
550 + }
551 + }
552 + }
553 + }
554 + }
555 + log.debug("updateInterfaceParameters:: all processes::{}", processes);
556 + }
557 +
558 + /**
559 + * Creates server bootstrap for interface.
560 + *
561 + * @param interfaceIPs set of interfaces
562 + * @param areaIds set of area id's
563 + */
564 + private void createBootStrapForCreatedInterface(Set<String> interfaceIPs, Set<String> areaIds) {
565 +
566 + log.debug("createBootStrapForCreatedInterface:: List of new Interfaces::{}, " +
567 + "List of new areas::{}", interfaceIPs, areaIds);
568 + List<String> networkInterfaces = new ArrayList();
569 + //get the connected interfaces
570 + Enumeration<NetworkInterface> nets = null;
571 + try {
572 + nets = NetworkInterface.getNetworkInterfaces();
573 + // Check NetworkInterfaces and add the IP's
574 + for (NetworkInterface netInt : Collections.list(nets)) {
575 + // if the interface is up & not loopback
576 + if (!netInt.isUp() && !netInt.isLoopback()) {
577 + continue;
578 + }
579 + //get all the InetAddresses
580 + Enumeration<InetAddress> inetAddresses = netInt.getInetAddresses();
581 + for (InetAddress inetAddress : Collections.list(inetAddresses)) {
582 + String ipAddress = inetAddress.getHostAddress();
583 + networkInterfaces.add(ipAddress);
584 + }
585 + }
586 + //Search for the address in all configured areas interfaces
587 + for (OspfProcess process : processes) {
588 + for (OspfArea area : process.areas()) {
589 + for (OspfInterface ospfIf : area.getInterfacesLst()) {
590 + String ipFromConfig = ospfIf.ipAddress().toString();
591 + if (interfaceIPs.contains(ipFromConfig)) {
592 + log.debug("Ip address::{} for area {} is newly created" + ipFromConfig);
593 + if (networkInterfaces.contains(ipFromConfig)) {
594 + log.debug("Both Config and Interface have ipAddress {} for area {}",
595 + ipFromConfig, area.areaId());
596 + // if same IP address create
597 + try {
598 + log.debug("Creating ServerBootstrap for {} @ {}", ipFromConfig, ospfPort);
599 +
600 + final ServerBootstrap bootstrap = createServerBootStrap();
601 +
602 + bootstrap.setOption("receiveBufferSize", Controller.BUFFER_SIZE);
603 + bootstrap.setOption("receiveBufferSizePredictorFactory",
604 + new FixedReceiveBufferSizePredictorFactory(
605 + Controller.BUFFER_SIZE));
606 + bootstrap.setOption("reuseAddress", true);
607 + bootstrap.setOption("tcpNoDelay", true);
608 + bootstrap.setOption("keepAlive", true);
609 +
610 + bootstrap.setOption("child.receiveBufferSize", Controller.BUFFER_SIZE);
611 + bootstrap.setOption("child.receiveBufferSizePredictorFactory",
612 + new FixedReceiveBufferSizePredictorFactory(
613 + Controller.BUFFER_SIZE));
614 + bootstrap.setOption("child.reuseAddress", true);
615 + bootstrap.setOption("child.tcpNoDelay", true);
616 + bootstrap.setOption("child.keepAlive", true);
617 + bootstrap.setOption("receiveBufferSizePredictorFactory",
618 + new FixedReceiveBufferSizePredictorFactory(
619 + Controller.BUFFER_SIZE));
620 + bootstrap.setOption("receiveBufferSizePredictor",
621 + new AdaptiveReceiveBufferSizePredictor(64, 1024, 65536));
622 +
623 + ChannelPipelineFactory pfact = new OspfPipelineFactory(this, area, ospfIf);
624 + bootstrap.setPipelineFactory(pfact);
625 + InetSocketAddress sa = new InetSocketAddress(InetAddress.getByName(ipFromConfig),
626 + ospfPort);
627 +
628 + ChannelGroup cg = new DefaultChannelGroup();
629 + cg.add(bootstrap.bind(sa));
630 + cgList.add(cg);
631 +
632 + log.debug("Listening for connections on {}", sa);
633 +
634 + } catch (Exception e) {
635 + throw new RuntimeException(e);
636 + }
637 + }
638 + } else {
639 + log.debug("Ip address::{} for area {} is not newly created" + ipFromConfig);
640 + }
641 + }
642 + if (areaIds.contains(area.areaId().toString())) {
643 + area.initializeDb();
644 + }
645 + }
646 + }
647 +
648 + } catch (SocketException e) {
649 + log.error("Error occured due to SocketException::Class::{},Line::{},Method::{}",
650 + e.getStackTrace()[0].getFileName(), e.getStackTrace()[0].getLineNumber(),
651 + e.getStackTrace()[0].getMethodName());
652 + }
653 + }
654 +
655 + /**
656 + * Deletes given process.
657 + *
658 + * @param ospfProcesses list of OSPF process instance.
659 + * @param attribute attribute to delete
660 + */
661 + public void deleteProcessWhenExists(List<OspfProcess> ospfProcesses, String attribute) {
662 + if (ospfProcesses != null) {
663 + for (OspfProcess process : ospfProcesses) {
664 + if (checkProcess(process.processId())) {
665 + if (PROCESS.equalsIgnoreCase(attribute)) {
666 + deleteProcess(process.processId(), process);
667 + } else {
668 + List<OspfArea> areas = process.areas();
669 + for (OspfArea area : areas) {
670 + if (checkArea(process.processId(), area.areaId().toString())) {
671 + if (AREA.equalsIgnoreCase(attribute)) {
672 + deleteAreaFromProcess(process.processId(),
673 + area.areaId().toString(), area);
674 + } else {
675 + for (OspfInterface interfc : area.getInterfacesLst()) {
676 + if (checkInterface(process.processId(),
677 + area.areaId().toString(),
678 + interfc.ipAddress().toString())) {
679 + if (INTERFACE.equalsIgnoreCase(attribute)) {
680 + deleteInterfaceFromAreaProcess(process.processId(),
681 + area.areaId().toString(),
682 + interfc);
683 + }
684 + }
685 + }
686 + }
687 + }
688 + }
689 + }
690 + }
691 + }
692 + }
693 + }
694 +
695 + /**
696 + * Deletes given process.
697 + *
698 + * @param processId process id
699 + * @param process OSPF process instance
700 + */
701 + private void deleteProcess(String processId, OspfProcess process) {
702 + if (processes != null) {
703 + Iterator<OspfProcess> itrProcess = processes.iterator();
704 + while (itrProcess.hasNext()) {
705 + OspfProcess ospfPrs = itrProcess.next();
706 + if (processId.equalsIgnoreCase(ospfPrs.processId())) {
707 + itrProcess.remove();
708 + }
709 + }
710 + }
711 + }
712 +
713 + /**
714 + * Deletes area from process.
715 + *
716 + * @param processId process id
717 + * @param areaId area id
718 + * @param area OSPF area instance
719 + */
720 + private void deleteAreaFromProcess(String processId, String areaId, OspfArea area) {
721 + if (processes != null) {
722 + Iterator<OspfProcess> itrProcess = processes.iterator();
723 + while (itrProcess.hasNext()) {
724 + OspfProcess ospfPrs = itrProcess.next();
725 + if (processId.equalsIgnoreCase(ospfPrs.processId())) {
726 + if (ospfPrs.areas() != null) {
727 + Iterator<OspfArea> itrArea = ospfPrs.areas().iterator();
728 + while (itrArea.hasNext()) {
729 + OspfArea ospfArea = itrArea.next();
730 + if (areaId.equalsIgnoreCase(ospfArea.areaId().toString())) {
731 + itrArea.remove();
732 + }
733 + }
734 + }
735 + }
736 + }
737 + }
738 + }
739 +
740 + /**
741 + * Deletes interface from area.
742 + *
743 + * @param processId process id
744 + * @param areaId area id
745 + * @param interfaceToDelete interface to delete
746 + */
747 + private void deleteInterfaceFromAreaProcess(String processId, String areaId, OspfInterface interfaceToDelete) {
748 + if (processes != null) {
749 + Iterator<OspfProcess> itrProcess = processes.iterator();
750 + while (itrProcess.hasNext()) {
751 + OspfProcess ospfPrs = itrProcess.next();
752 + if (processId.equalsIgnoreCase(ospfPrs.processId())) {
753 + if (ospfPrs.areas() != null) {
754 + Iterator<OspfArea> itrArea = ospfPrs.areas().iterator();
755 + while (itrArea.hasNext()) {
756 + OspfArea ospfArea = itrArea.next();
757 + if (areaId.equalsIgnoreCase(ospfArea.areaId().toString())) {
758 + if (ospfArea.getInterfacesLst() != null) {
759 + Iterator<OspfInterface> intrfcList = ospfArea.getInterfacesLst().iterator();
760 + while (intrfcList.hasNext()) {
761 + OspfInterface ospfItrfc = intrfcList.next();
762 + if (interfaceToDelete.ipAddress().equals(ospfItrfc.ipAddress())) {
763 + intrfcList.remove();
764 + }
765 + }
766 + }
767 + }
768 + }
769 + }
770 + }
771 + }
772 + }
773 + }
774 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 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 +
17 +/**
18 + * Implementation of the OSPF controller.
19 + */
20 +package org.onosproject.ospf.controller.impl;
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 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 +package org.onosproject.ospf.controller.lsdb;
17 +
18 +import com.google.common.base.MoreObjects;
19 +import org.onosproject.ospf.controller.LsaBin;
20 +import org.onosproject.ospf.controller.LsaWrapper;
21 +
22 +import java.util.Map;
23 +import java.util.concurrent.ConcurrentHashMap;
24 +
25 +/**
26 + * Represents a bin, where an LSA is stored for Aging.
27 + * A bin is identified by a bin number and can have one or more LSAs
28 + * store in a particular bin location.
29 + */
30 +public class LsaBinImpl implements LsaBin {
31 +
32 + private int binNumber;
33 + private Map<String, LsaWrapper> listOfLsa = new ConcurrentHashMap<>();
34 +
35 + /**
36 + * Creates an instance of LSA bin.
37 + *
38 + * @param binNumber unique number of this bin
39 + */
40 + public LsaBinImpl(int binNumber) {
41 + this.binNumber = binNumber;
42 + }
43 +
44 + /**
45 + * Adds the LSA to this bin with the given key.
46 + *
47 + * @param lsaKey key of the LSA
48 + * @param lsaWrapper wrapper instance to store
49 + */
50 + public void addOspfLsa(String lsaKey, LsaWrapper lsaWrapper) {
51 + if (!listOfLsa.containsKey(lsaKey)) {
52 + listOfLsa.put(lsaKey, lsaWrapper);
53 + lsaWrapper.setBinNumber(this.binNumber);
54 + }
55 + }
56 +
57 + /**
58 + * Gets the LSA from the bin.
59 + *
60 + * @param lsaKey key to search the LSA
61 + * @return LSA Wrapper instance
62 + */
63 + public LsaWrapper ospfLsa(String lsaKey) {
64 +
65 + return listOfLsa.get(lsaKey);
66 + }
67 +
68 + /**
69 + * Removes LSA from the bin.
70 + *
71 + * @param lsaKey key to search LSA
72 + * @param lsaWrapper wrapper object to remove
73 + */
74 + public void removeOspfLsa(String lsaKey, LsaWrapper lsaWrapper) {
75 + if (listOfLsa.containsKey(lsaKey)) {
76 + listOfLsa.remove(lsaKey);
77 + }
78 + }
79 +
80 + /**
81 + * Gets the list of LSAs in this bin as key value pair.
82 + *
83 + * @return list of LSAs in this bin as key value pair
84 + */
85 + public Map<String, LsaWrapper> listOfLsa() {
86 + return listOfLsa;
87 + }
88 +
89 + /**
90 + * Gets the bin number.
91 + *
92 + * @return the bin number
93 + */
94 + public int binNumber() {
95 + return binNumber;
96 + }
97 +
98 + @Override
99 + public String toString() {
100 + return MoreObjects.toStringHelper(getClass())
101 + .omitNullValues()
102 + .add("binNumber", binNumber)
103 + .add("listOfLsa", listOfLsa)
104 + .toString();
105 + }
106 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 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 +package org.onosproject.ospf.controller.lsdb;
17 +
18 +import com.google.common.base.MoreObjects;
19 +import com.google.common.base.Objects;
20 +import org.onosproject.ospf.controller.LsaWrapper;
21 +import org.onosproject.ospf.controller.LsdbAge;
22 +import org.onosproject.ospf.controller.OspfInterface;
23 +import org.onosproject.ospf.controller.OspfLsa;
24 +import org.onosproject.ospf.controller.OspfLsaType;
25 +import org.onosproject.ospf.protocol.lsa.LsaHeader;
26 +import org.onosproject.ospf.protocol.util.OspfParameters;
27 +import org.slf4j.Logger;
28 +import org.slf4j.LoggerFactory;
29 +
30 +/**
31 + * Wrapper object to store LSA and associated metadata information.
32 + */
33 +public class LsaWrapperImpl implements LsaWrapper {
34 + private static final Logger log = LoggerFactory.getLogger(LsaWrapperImpl.class);
35 + private LsaHeader lsaHeader;
36 + private int lsaAgeReceived;
37 + private int ageCounterWhenReceived;
38 + private boolean isSelfOriginated;
39 + private OspfLsaType lsaType;
40 + private OspfLsa ospfLsa;
41 + private int noReTransmissionLists;
42 + private boolean inAnAgeBin;
43 + private boolean changedSinceLastFlood;
44 + private boolean isSequenceRollOver;
45 + private boolean sentReplyForOlderLsa;
46 + private boolean checkAge; // Queued for check sum verification
47 + private boolean isAging;
48 + private String lsaProcessing; //for LSAQueueConsumer processing
49 + private int binNumber = -1;
50 + private OspfInterface ospfInterface;
51 + private LsdbAge lsdbAge;
52 +
53 + /**
54 + * Gets the LSA type.
55 + *
56 + * @return LSA type
57 + */
58 + public OspfLsaType lsaType() {
59 + return lsaType;
60 + }
61 +
62 + /**
63 + * Sets the LSA type.
64 + *
65 + * @param lsaType LSA type
66 + */
67 + public void setLsaType(OspfLsaType lsaType) {
68 + this.lsaType = lsaType;
69 + }
70 +
71 + /**
72 + * Gets if self originated or not.
73 + *
74 + * @return true if self originated else false
75 + */
76 + public boolean isSelfOriginated() {
77 + return isSelfOriginated;
78 + }
79 +
80 + /**
81 + * Sets if self originated or not.
82 + *
83 + * @param isSelfOriginated true if self originated else false
84 + */
85 + public void setIsSelfOriginated(boolean isSelfOriginated) {
86 + this.isSelfOriginated = isSelfOriginated;
87 + }
88 +
89 + /**
90 + * Adds the LSA in the wrapper.
91 + *
92 + * @param lsaType LSA type
93 + * @param ospfLsa LSA instance
94 + */
95 + public void addLsa(OspfLsaType lsaType, OspfLsa ospfLsa) {
96 + this.lsaType = lsaType;
97 + this.lsaHeader = (LsaHeader) ospfLsa.lsaHeader();
98 + this.ospfLsa = ospfLsa;
99 + }
100 +
101 + /**
102 + * Age of LSA when received.
103 + *
104 + * @return Age of LSA when received
105 + */
106 + public int lsaAgeReceived() {
107 + return lsaAgeReceived;
108 + }
109 +
110 + /**
111 + * Sets the Age of LSA when received.
112 + *
113 + * @param lsaAgeReceived Age of LSA when received
114 + */
115 + public void setLsaAgeReceived(int lsaAgeReceived) {
116 + this.lsaAgeReceived = lsaAgeReceived;
117 + }
118 +
119 + /**
120 + * Gets the LSA header.
121 + *
122 + * @return LSA header instance
123 + */
124 + public LsaHeader lsaHeader() {
125 + lsaHeader.setAge(currentAge());
126 + return lsaHeader;
127 + }
128 +
129 + /**
130 + * Sets LSA header.
131 + *
132 + * @param lsaHeader LSA header
133 + */
134 + public void setLsaHeader(LsaHeader lsaHeader) {
135 + this.lsaHeader = lsaHeader;
136 + }
137 +
138 + /**
139 + * Gets the LSA.
140 + *
141 + * @return LSA instance
142 + */
143 + public OspfLsa ospfLsa() {
144 + LsaHeader lsaHeader = (LsaHeader) ospfLsa;
145 + lsaHeader.setAge(currentAge());
146 +
147 + return lsaHeader;
148 + }
149 +
150 + /**
151 + * Sets the LSA.
152 + *
153 + * @param ospfLsa LSA instance
154 + */
155 + public void setOspfLsa(OspfLsa ospfLsa) {
156 + this.ospfLsa = ospfLsa;
157 + }
158 +
159 + /**
160 + * Gets number of LSAs in retransmission list.
161 + *
162 + * @return number of LSAs in retransmission list
163 + */
164 + public int noReTransmissionLists() {
165 + return noReTransmissionLists;
166 + }
167 +
168 + /**
169 + * Sets number of LSAs in retransmission list.
170 + *
171 + * @param noReTransmissionLists number of LSAs in retransmission list
172 + */
173 + public void setNoReTransmissionLists(int noReTransmissionLists) {
174 + this.noReTransmissionLists = noReTransmissionLists;
175 + }
176 +
177 + /**
178 + * whether LSA in age bin or not.
179 + *
180 + * @return true if LSA in age bin else false
181 + */
182 + public boolean isInAnAgeBin() {
183 + return inAnAgeBin;
184 + }
185 +
186 + /**
187 + * Sets whether LSA in age bin or not.
188 + *
189 + * @param inAnAgeBin whether LSA in age bin or not
190 + */
191 + public void setInAnAgeBin(boolean inAnAgeBin) {
192 + this.inAnAgeBin = inAnAgeBin;
193 + }
194 +
195 + /**
196 + * Gets if LSA is changed since last flood.
197 + *
198 + * @return true if LSA is changed since last flood else false
199 + */
200 + public boolean isChangedSinceLastFlood() {
201 + return changedSinceLastFlood;
202 + }
203 +
204 + /**
205 + * Sets if LSA is changed since last flood.
206 + *
207 + * @param changedSinceLastFlood true if LSA is changed since last flood else false
208 + */
209 + public void setChangedSinceLastFlood(boolean changedSinceLastFlood) {
210 + this.changedSinceLastFlood = changedSinceLastFlood;
211 + }
212 +
213 + /**
214 + * Gets if sequence number rolled over.
215 + *
216 + * @return true if sequence rolled over else false.
217 + */
218 + public boolean isSequenceRollOver() {
219 + return isSequenceRollOver;
220 + }
221 +
222 + /**
223 + * Sets if sequence number rolled over.
224 + *
225 + * @param isSequenceRollOver true if sequence rolled over else false
226 + */
227 + public void setIsSequenceRollOver(boolean isSequenceRollOver) {
228 + this.isSequenceRollOver = isSequenceRollOver;
229 + }
230 +
231 + /**
232 + * Gets is sent reply for older LSA.
233 + *
234 + * @return true if sent reply for old LSA else false
235 + */
236 + public boolean isSentReplyForOlderLsa() {
237 + return sentReplyForOlderLsa;
238 + }
239 +
240 + /**
241 + * Sets is sent reply for older lsa.
242 + *
243 + * @param sentReplyForOlderLsa true if sent reply for older lsa else false
244 + */
245 + public void setSentReplyForOlderLsa(boolean sentReplyForOlderLsa) {
246 + this.sentReplyForOlderLsa = sentReplyForOlderLsa;
247 + }
248 +
249 + /**
250 + * Gets check age flag.
251 + *
252 + * @return true check age flag is set else false
253 + */
254 + public boolean isCheckAge() {
255 + return checkAge;
256 + }
257 +
258 + /**
259 + * Sets check age flag.
260 + *
261 + * @param checkAge check age flag.
262 + */
263 + public void setCheckAge(boolean checkAge) {
264 + this.checkAge = checkAge;
265 + }
266 +
267 + /**
268 + * Gets value of aging flag.
269 + *
270 + * @return is aging flag
271 + */
272 + public boolean isAging() {
273 + return isAging;
274 + }
275 +
276 + /**
277 + * Sets aging flag.
278 + *
279 + * @param isAging is aging flag
280 + */
281 + public void setIsAging(boolean isAging) {
282 + this.isAging = isAging;
283 + }
284 +
285 + /**
286 + * Gets the LSDB age.
287 + *
288 + * @return LSDB age
289 + */
290 + public LsdbAge getLsdbAge() {
291 + return lsdbAge;
292 + }
293 +
294 + /**
295 + * Sets the LSDB age.
296 + *
297 + * @param lsdbAge LSDB age
298 + */
299 + public void setLsdbAge(LsdbAge lsdbAge) {
300 + this.lsdbAge = lsdbAge;
301 + }
302 +
303 + /**
304 + * Gets the current LSA Age.
305 + *
306 + * @return LSA age
307 + */
308 + public int currentAge() {
309 +
310 + int currentAge = 0;
311 + //ls age received
312 + if (lsdbAge.getAgeCounter() >= ageCounterWhenReceived) {
313 + currentAge = lsaAgeReceived + (lsdbAge.getAgeCounter() - ageCounterWhenReceived);
314 + } else {
315 + currentAge = lsaAgeReceived + ((OspfParameters.MAXAGE + lsdbAge.getAgeCounter())
316 + - ageCounterWhenReceived);
317 + }
318 +
319 + if (currentAge >= OspfParameters.MAXAGE) {
320 + return OspfParameters.MAXAGE;
321 + }
322 +
323 + return currentAge;
324 + }
325 +
326 + /**
327 + * Gets the age counter when received.
328 + *
329 + * @return the age counter when received
330 + */
331 + public int ageCounterWhenReceived() {
332 + return ageCounterWhenReceived;
333 + }
334 +
335 + /**
336 + * Sets the age counter when received.
337 + *
338 + * @param ageCounterWhenReceived the age counter when received
339 + */
340 + public void setAgeCounterWhenReceived(int ageCounterWhenReceived) {
341 + this.ageCounterWhenReceived = ageCounterWhenReceived;
342 + }
343 +
344 + /**
345 + * Gets the LSA process command.
346 + *
347 + * @return LSA process command
348 + */
349 + public String lsaProcessing() {
350 + return lsaProcessing;
351 + }
352 +
353 + /**
354 + * Sets the LSA process command.
355 + *
356 + * @param lsaProcessing LSA process command
357 + */
358 + public void setLsaProcessing(String lsaProcessing) {
359 + this.lsaProcessing = lsaProcessing;
360 + }
361 +
362 + /**
363 + * Gets bin number.
364 + *
365 + * @return bin number
366 + */
367 + public int binNumber() {
368 + return binNumber;
369 + }
370 +
371 + /**
372 + * Sets bin number.
373 + *
374 + * @param binNumber bin number
375 + */
376 + public void setBinNumber(int binNumber) {
377 + this.binNumber = binNumber;
378 + }
379 +
380 +
381 + /**
382 + * Get the OSPF interface.
383 + *
384 + * @return the OSPF interface.
385 + */
386 + public OspfInterface ospfInterface() {
387 + return ospfInterface;
388 + }
389 +
390 + /**
391 + * Sets the OSPF interface.
392 + *
393 + * @param ospfInterface OSPF interface instance
394 + */
395 + @Override
396 + public void setOspfInterface(OspfInterface ospfInterface) {
397 + this.ospfInterface = ospfInterface;
398 + }
399 +
400 + @Override
401 + public String toString() {
402 + return MoreObjects.toStringHelper(getClass())
403 + .omitNullValues()
404 + .add("lsaAgeReceived", lsaAgeReceived)
405 + .add("ageCounterWhenReceived", ageCounterWhenReceived)
406 + .add("isSelfOriginated", isSelfOriginated)
407 + .add("lsaHeader", lsaHeader)
408 + .add("lsaType", lsaType)
409 + .add("ospflsa", ospfLsa)
410 + .add("noReTransmissionLists", noReTransmissionLists)
411 + .add("inAnAgeBin", inAnAgeBin)
412 + .add("changedSinceLasFlood", changedSinceLastFlood)
413 + .add("isSequenceRollOver", isSequenceRollOver)
414 + .add("sentReplyForOlderLSA", sentReplyForOlderLsa)
415 + .add("checkAge", checkAge)
416 + .add("isAging", isAging)
417 + .add("lsaProcessing", lsaProcessing)
418 + .toString();
419 + }
420 +
421 + @Override
422 + public boolean equals(Object o) {
423 + if (this == o) {
424 + return true;
425 + }
426 + if (o == null || getClass() != o.getClass()) {
427 + return false;
428 + }
429 + LsaWrapperImpl that = (LsaWrapperImpl) o;
430 + return Objects.equal(lsaAgeReceived, that.lsaAgeReceived) &&
431 + Objects.equal(ageCounterWhenReceived, that.ageCounterWhenReceived) &&
432 + Objects.equal(isSelfOriginated, that.isSelfOriginated) &&
433 + Objects.equal(lsaHeader, that.lsaHeader) &&
434 + Objects.equal(ospfLsa, that.ospfLsa) &&
435 + Objects.equal(noReTransmissionLists, that.noReTransmissionLists) &&
436 + Objects.equal(inAnAgeBin, that.inAnAgeBin) &&
437 + Objects.equal(changedSinceLastFlood, that.changedSinceLastFlood) &&
438 + Objects.equal(isSequenceRollOver, that.isSequenceRollOver) &&
439 + Objects.equal(sentReplyForOlderLsa, that.sentReplyForOlderLsa) &&
440 + Objects.equal(checkAge, that.checkAge) &&
441 + Objects.equal(isAging, that.isAging) &&
442 + Objects.equal(lsaProcessing, that.lsaProcessing);
443 + }
444 +
445 + @Override
446 + public int hashCode() {
447 + return Objects.hashCode(lsaAgeReceived, lsaAgeReceived, ageCounterWhenReceived, isSelfOriginated,
448 + lsaHeader, lsaType, ospfLsa, noReTransmissionLists, inAnAgeBin,
449 + changedSinceLastFlood, isSequenceRollOver, sentReplyForOlderLsa,
450 + checkAge, isAging, lsaProcessing);
451 + }
452 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 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 +
17 +/**
18 + * Implementation of the OSPF Link state database and Ageing.
19 + */
20 +package org.onosproject.ospf.controller.lsdb;
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 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 +package org.onosproject.ospf.controller.util;
17 +
18 +import org.onlab.packet.Ip4Address;
19 +
20 +/**
21 + * Represents a router who is eligible for DR election.
22 + */
23 +public class OspfEligibleRouter {
24 +
25 + private Ip4Address ipAddress;
26 + private Ip4Address routerId;
27 + private int routerPriority;
28 + private boolean isDr;
29 + private boolean isBdr;
30 +
31 + /**
32 + * Creates an instance.
33 + * Initialize IP address of eligible router.
34 + */
35 + public OspfEligibleRouter() {
36 + ipAddress = Ip4Address.valueOf("0.0.0.0");
37 + }
38 +
39 + /**
40 + * Gets the value of IP address.
41 + *
42 + * @return IP address
43 + */
44 + public Ip4Address getIpAddress() {
45 + return ipAddress;
46 + }
47 +
48 + /**
49 + * Sets the value of IP address.
50 + *
51 + * @param ipAddress IP address
52 + */
53 + public void setIpAddress(Ip4Address ipAddress) {
54 + this.ipAddress = ipAddress;
55 + }
56 +
57 + /**
58 + * Gets the value of router id.
59 + *
60 + * @return router id.
61 + */
62 + public Ip4Address getRouterId() {
63 + return routerId;
64 + }
65 +
66 + /**
67 + * Sets the value of router id.
68 + *
69 + * @param routerId router id
70 + */
71 + public void setRouterId(Ip4Address routerId) {
72 + this.routerId = routerId;
73 + }
74 +
75 + /**
76 + * Gets the value of router priority.
77 + *
78 + * @return router priority.
79 + */
80 + public int getRouterPriority() {
81 + return routerPriority;
82 + }
83 +
84 + /**
85 + * Sets the value of router priority.
86 + *
87 + * @param routerPriority router priority
88 + */
89 + public void setRouterPriority(int routerPriority) {
90 + this.routerPriority = routerPriority;
91 + }
92 +
93 + /**
94 + * Gets whether the router is DR.
95 + *
96 + * @return boolean true if router is DR else return false.
97 + */
98 + public boolean isDr() {
99 + return isDr;
100 + }
101 +
102 + /**
103 + * Sets the router is DR or not.
104 + *
105 + * @param isDr router is DR or not
106 + */
107 + public void setIsDr(boolean isDr) {
108 + this.isDr = isDr;
109 + }
110 +
111 + /**
112 + * Gets whether the router is BDR or not.
113 + *
114 + * @return boolean true if router is Bdr else return false.
115 + */
116 + public boolean isBdr() {
117 + return isBdr;
118 + }
119 +
120 + /**
121 + * Sets the router is BDR or not.
122 + *
123 + * @param isBdr the router is BDR or not
124 + */
125 + public void setIsBdr(boolean isBdr) {
126 + this.isBdr = isBdr;
127 + }
128 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 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 +package org.onosproject.ospf.controller.util;
17 +
18 +/**
19 + * Enum represents OSPF interface types.
20 + */
21 +public enum OspfInterfaceType {
22 +
23 + POINT_TO_POINT(1),
24 + BROADCAST(2),
25 + VIRTUAL(3);
26 +
27 + private int value;
28 +
29 + /**
30 + * Creates an instance.
31 + *
32 + * @param value value represents interface type
33 + */
34 + OspfInterfaceType(int value) {
35 + this.value = value;
36 + }
37 +
38 + /**
39 + * Gets value represents interface type.
40 + *
41 + * @return value represents interface type
42 + */
43 + public int value() {
44 + return value;
45 + }
46 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 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 +package org.onosproject.ospf.controller.util;
17 +
18 +/**
19 + * Enum represents OSPF link type.
20 + */
21 +public enum OspfLinkType {
22 +
23 + /**
24 + * Indicates a point-to-point connection to another router.
25 + */
26 + POINT_TO_POINT,
27 +
28 + /**
29 + * Indicates a connection to a transit network.
30 + */
31 + TO_TRANSIT_NET,
32 +
33 + /**
34 + * Indicates a connection to a stub network.
35 + */
36 + TO_STUB_NET,
37 +
38 + /**
39 + * Indicates a Virtual link to another area border router.
40 + */
41 + VIRTUAL_LINK;
42 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 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 +
17 +/**
18 + * Implementation of the OSPF utilities.
19 + */
20 +package org.onosproject.ospf.controller.util;
...\ No newline at end of file ...\ No newline at end of file