sunish vk
Committed by Gerrit Code Review

ONOS-4665 OSPF refactoring to align with ISIS design

Change-Id: If4a15d5a1c4ae3a5b2f877fa688ce07972749205
Showing 104 changed files with 4343 additions and 4317 deletions
1 /* 1 /*
2 - * Copyright 2016-present Open Networking Laboratory 2 + * Copyright 2016 Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
......
1 /* 1 /*
2 - * Copyright 2016-present Open Networking Laboratory 2 + * Copyright 2016 Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
......
...@@ -98,4 +98,11 @@ public interface LsdbAge { ...@@ -98,4 +98,11 @@ public interface LsdbAge {
98 * @param lsaWrapper wrapper instance 98 * @param lsaWrapper wrapper instance
99 */ 99 */
100 public void removeLsaFromBin(LsaWrapper lsaWrapper); 100 public void removeLsaFromBin(LsaWrapper lsaWrapper);
101 +
102 + /**
103 + * Gets the age counter roll over.
104 + *
105 + * @return the age counter roll over
106 + */
107 + public int getAgeCounterRollOver();
101 } 108 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -49,6 +49,7 @@ public interface OspfAgent { ...@@ -49,6 +49,7 @@ public interface OspfAgent {
49 * Notifies that got a packet of link from network and need do processing. 49 * Notifies that got a packet of link from network and need do processing.
50 * 50 *
51 * @param ospfRouter router instance 51 * @param ospfRouter router instance
52 + * @param ospfLinkTed link ted instance
52 */ 53 */
53 - void deleteLink(OspfRouter ospfRouter); 54 + void deleteLink(OspfRouter ospfRouter, OspfLinkTed ospfLinkTed);
54 } 55 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -59,7 +59,7 @@ public interface OspfArea { ...@@ -59,7 +59,7 @@ public interface OspfArea {
59 * 59 *
60 * @return LSDB instance for this area 60 * @return LSDB instance for this area
61 */ 61 */
62 - public OspfLsdb database(); 62 + OspfLsdb database();
63 63
64 /** 64 /**
65 * Checks whether an instance of the given LSA exists in the database. 65 * Checks whether an instance of the given LSA exists in the database.
...@@ -67,19 +67,12 @@ public interface OspfArea { ...@@ -67,19 +67,12 @@ public interface OspfArea {
67 * @param lookupLsa LSA instance to lookup 67 * @param lookupLsa LSA instance to lookup
68 * @return LSA wrapper instance which contains the LSA 68 * @return LSA wrapper instance which contains the LSA
69 */ 69 */
70 - public LsaWrapper lsaLookup(OspfLsa lookupLsa); 70 + LsaWrapper lsaLookup(OspfLsa lookupLsa);
71 71
72 /** 72 /**
73 * Initializes link state database, this acts as a place holder for storing the received LSA. 73 * Initializes link state database, this acts as a place holder for storing the received LSA.
74 */ 74 */
75 - public void initializeDb(); 75 + void initializeDb();
76 -
77 - /**
78 - * Sets the stub cost.
79 - *
80 - * @param stubCost stub cost
81 - */
82 - void setStubCost(int stubCost);
83 76
84 /** 77 /**
85 * Sets the options value. 78 * Sets the options value.
...@@ -89,38 +82,6 @@ public interface OspfArea { ...@@ -89,38 +82,6 @@ public interface OspfArea {
89 void setOptions(int options); 82 void setOptions(int options);
90 83
91 /** 84 /**
92 - * Gets area address ranges to which this area belongs to.
93 - *
94 - * @return list of area address ranges
95 - */
96 - List<OspfAreaAddressRange> addressRanges();
97 -
98 - /**
99 - * Sets the area address ranges to which this area belongs to.
100 - *
101 - * @param addrRangeList list of area address ranges
102 - */
103 - void setAddressRanges(List<OspfAreaAddressRange> addrRangeList);
104 -
105 - /**
106 - * Gets whether the area is transit capable or not.
107 - * This indicates whether the area can carry data traffic that neither originates
108 - * nor terminates in the area itself.
109 - *
110 - * @return true if transit capable, else false
111 - */
112 - boolean isTransitCapability();
113 -
114 - /**
115 - * Sets whether the area is transit capable or not.
116 - * This indicates whether the area can carry data traffic that neither originates
117 - * nor terminates in the area itself.
118 - *
119 - * @param transitCapability true if transit capable, else false
120 - */
121 - void setTransitCapability(boolean transitCapability);
122 -
123 - /**
124 * Gets external routing capability. 85 * Gets external routing capability.
125 * This indicates Whether AS-external-LSAs will be flooded into/throughout the area. 86 * This indicates Whether AS-external-LSAs will be flooded into/throughout the area.
126 * 87 *
...@@ -137,13 +98,6 @@ public interface OspfArea { ...@@ -137,13 +98,6 @@ public interface OspfArea {
137 void setExternalRoutingCapability(boolean externalRoutingCapability); 98 void setExternalRoutingCapability(boolean externalRoutingCapability);
138 99
139 /** 100 /**
140 - * Gets the stub cost, which indicates if the area has been configured as a stub area.
141 - *
142 - * @return stub cost
143 - */
144 - int stubCost();
145 -
146 - /**
147 * Gets if the router is opaque enabled or not. 101 * Gets if the router is opaque enabled or not.
148 * This indicates whether the router accepts opaque LSA. 102 * This indicates whether the router accepts opaque LSA.
149 * 103 *
...@@ -156,14 +110,14 @@ public interface OspfArea { ...@@ -156,14 +110,14 @@ public interface OspfArea {
156 * 110 *
157 * @return list of interfaces 111 * @return list of interfaces
158 */ 112 */
159 - List<OspfInterface> getInterfacesLst(); 113 + List<OspfInterface> ospfInterfaceList();
160 114
161 /** 115 /**
162 * Sets the list of interfaces attached to this area. 116 * Sets the list of interfaces attached to this area.
163 * 117 *
164 * @param interfacesLst list of interface instances 118 * @param interfacesLst list of interface instances
165 */ 119 */
166 - void setInterfacesLst(List<OspfInterface> interfacesLst); 120 + void setOspfInterfaceList(List<OspfInterface> interfacesLst);
167 121
168 /** 122 /**
169 * Gets the options value, which indicates the supported optional capabilities. 123 * Gets the options value, which indicates the supported optional capabilities.
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
15 */ 15 */
16 package org.onosproject.ospf.controller; 16 package org.onosproject.ospf.controller;
17 17
18 +import com.fasterxml.jackson.databind.JsonNode;
19 +
18 import java.util.List; 20 import java.util.List;
19 import java.util.Set; 21 import java.util.Set;
20 22
...@@ -55,9 +57,9 @@ public interface OspfController { ...@@ -55,9 +57,9 @@ public interface OspfController {
55 /** 57 /**
56 * Updates configuration of processes. 58 * Updates configuration of processes.
57 * 59 *
58 - * @param processes process info to update 60 + * @param processesNode process info to update
59 */ 61 */
60 - public void updateConfig(List<OspfProcess> processes); 62 + void updateConfig(JsonNode processesNode);
61 63
62 /** 64 /**
63 * Deletes configuration parameters. 65 * Deletes configuration parameters.
...@@ -65,7 +67,7 @@ public interface OspfController { ...@@ -65,7 +67,7 @@ public interface OspfController {
65 * @param processes list of process instance 67 * @param processes list of process instance
66 * @param attribute attribute to delete 68 * @param attribute attribute to delete
67 */ 69 */
68 - public void deleteConfig(List<OspfProcess> processes, String attribute); 70 + void deleteConfig(List<OspfProcess> processes, String attribute);
69 71
70 /** 72 /**
71 * Gets the list of listeners registered for router events. 73 * Gets the list of listeners registered for router events.
......
...@@ -15,9 +15,10 @@ ...@@ -15,9 +15,10 @@
15 */ 15 */
16 package org.onosproject.ospf.controller; 16 package org.onosproject.ospf.controller;
17 17
18 +import org.jboss.netty.channel.ChannelHandlerContext;
18 import org.onlab.packet.Ip4Address; 19 import org.onlab.packet.Ip4Address;
19 20
20 -import java.util.HashMap; 21 +import java.util.Map;
21 22
22 /** 23 /**
23 * Represents an OSPF Interface. 24 * Represents an OSPF Interface.
...@@ -25,34 +26,39 @@ import java.util.HashMap; ...@@ -25,34 +26,39 @@ import java.util.HashMap;
25 public interface OspfInterface { 26 public interface OspfInterface {
26 27
27 /** 28 /**
28 - * Gets network mask of the interface. 29 + * Returns interface index.
29 * 30 *
30 - * @return network mask 31 + * @return interface index
31 */ 32 */
32 - Ip4Address ipNetworkMask(); 33 + public int interfaceIndex();
33 34
34 /** 35 /**
35 - * Sets area id, to which the interface belongs. 36 + * Set interface index.
36 * 37 *
37 - * @param areaId area identifier 38 + * @param interfaceIndex interface index
38 */ 39 */
39 - void setAreaId(int areaId); 40 + public void setInterfaceIndex(int interfaceIndex);
40 41
41 /** 42 /**
42 - * Sets the authentication key. 43 + * Returns OSPF area instance.
43 - * Interface uses this to authenticate while establishing communication with other routers.
44 * 44 *
45 - * @param authKey represents authentication key 45 + * @return OSPF area instance
46 */ 46 */
47 - void setAuthKey(String authKey); 47 + public OspfArea ospfArea();
48 48
49 /** 49 /**
50 - * Sets the authentication type, 50 + * Sets OSPF area instance.
51 - * Interface uses this to authenticate while establishing communication with other routers.
52 * 51 *
53 - * @param authType authType represents authentication type 52 + * @param ospfArea OSPF area instance
53 + */
54 + public void setOspfArea(OspfArea ospfArea);
55 +
56 + /**
57 + * Gets network mask of the interface.
58 + *
59 + * @return network mask
54 */ 60 */
55 - void setAuthType(String authType); 61 + Ip4Address ipNetworkMask();
56 62
57 /** 63 /**
58 * Sets the value of BDR. 64 * Sets the value of BDR.
...@@ -87,13 +93,6 @@ public interface OspfInterface { ...@@ -87,13 +93,6 @@ public interface OspfInterface {
87 void setRouterDeadIntervalTime(int routerDeadIntervalTime); 93 void setRouterDeadIntervalTime(int routerDeadIntervalTime);
88 94
89 /** 95 /**
90 - * Sets the interface cost which is the cost of sending a data packet onto the network.
91 - *
92 - * @param interfaceCost an integer represents interface cost
93 - */
94 - void setInterfaceCost(int interfaceCost);
95 -
96 - /**
97 * Sets interface type. 96 * Sets interface type.
98 * This indicates whether the interface is on point to point mode or broadcast mode. 97 * This indicates whether the interface is on point to point mode or broadcast mode.
99 * 98 *
...@@ -116,22 +115,6 @@ public interface OspfInterface { ...@@ -116,22 +115,6 @@ public interface OspfInterface {
116 void setIpNetworkMask(Ip4Address ipNetworkMask); 115 void setIpNetworkMask(Ip4Address ipNetworkMask);
117 116
118 /** 117 /**
119 - * Sets the polling interval.
120 - * Polling interval indicates the interval until when the Hello Packets are
121 - * sent to a dead neighbor.
122 - *
123 - * @param pollInterval an integer represents poll interval
124 - */
125 - void setPollInterval(int pollInterval);
126 -
127 - /**
128 - * Sets transmission delay.
129 - *
130 - * @param transmitDelay an integer represents delay
131 - */
132 - void setTransmitDelay(int transmitDelay);
133 -
134 - /**
135 * Sets retransmit interval which indicates the number of seconds between LSA retransmissions. 118 * Sets retransmit interval which indicates the number of seconds between LSA retransmissions.
136 * 119 *
137 * @param reTransmitInterval an integer represents interval 120 * @param reTransmitInterval an integer represents interval
...@@ -153,13 +136,6 @@ public interface OspfInterface { ...@@ -153,13 +136,6 @@ public interface OspfInterface {
153 void setRouterPriority(int routerPriority); 136 void setRouterPriority(int routerPriority);
154 137
155 /** 138 /**
156 - * Gets the area id to which router belongs.
157 - *
158 - * @return areaId an integer value
159 - */
160 - int areaId();
161 -
162 - /**
163 * Gets the IP address. 139 * Gets the IP address.
164 * 140 *
165 * @return an string represents IP address 141 * @return an string represents IP address
...@@ -181,32 +157,11 @@ public interface OspfInterface { ...@@ -181,32 +157,11 @@ public interface OspfInterface {
181 int mtu(); 157 int mtu();
182 158
183 /** 159 /**
184 - * Gets interface cost.
185 - *
186 - * @return an integer representing interface cost
187 - */
188 - int interfaceCost();
189 -
190 - /**
191 * Gets the list of neighbors associated with the interface. 160 * Gets the list of neighbors associated with the interface.
192 * 161 *
193 * @return listOfNeighbors as key value pair 162 * @return listOfNeighbors as key value pair
194 */ 163 */
195 - HashMap<String, OspfNbr> listOfNeighbors(); 164 + Map<String, OspfNbr> listOfNeighbors();
196 -
197 - /**
198 - * Gets poll interval.
199 - *
200 - * @return pollInterval an integer representing poll interval
201 - */
202 - int pollInterval();
203 -
204 - /**
205 - * Gets transmission delay.
206 - *
207 - * @return transmitDelay an integer representing delay
208 - */
209 - int transmitDelay();
210 165
211 /** 166 /**
212 * Gets the IP address of the BDR. 167 * Gets the IP address of the BDR.
...@@ -223,20 +178,6 @@ public interface OspfInterface { ...@@ -223,20 +178,6 @@ public interface OspfInterface {
223 Ip4Address dr(); 178 Ip4Address dr();
224 179
225 /** 180 /**
226 - * Gets authentication key.
227 - *
228 - * @return authKey represents authentication key
229 - */
230 - String authKey();
231 -
232 - /**
233 - * Gets authentication type.
234 - *
235 - * @return authType represents authentication type
236 - */
237 - String authType();
238 -
239 - /**
240 * Gets hello interval time in seconds, this defines how often we send the hello packet. 181 * Gets hello interval time in seconds, this defines how often we send the hello packet.
241 * 182 *
242 * @return hello interval time in seconds 183 * @return hello interval time in seconds
...@@ -294,4 +235,54 @@ public interface OspfInterface { ...@@ -294,4 +235,54 @@ public interface OspfInterface {
294 * @param lsaKey key used to store lsa in map 235 * @param lsaKey key used to store lsa in map
295 */ 236 */
296 void removeLsaFromNeighborMap(String lsaKey); 237 void removeLsaFromNeighborMap(String lsaKey);
238 +
239 + /**
240 + * When an OSPF message received it is handed over to this method.
241 + * Based on the type of the OSPF message received it will be handed over
242 + * to corresponding message handler methods.
243 + *
244 + * @param ospfMessage received OSPF message
245 + * @param ctx channel handler context instance.
246 + * @throws Exception might throws exception
247 + */
248 + void processOspfMessage(OspfMessage ospfMessage, ChannelHandlerContext ctx) throws Exception;
249 +
250 + /**
251 + * Represents an interface is up and connected.
252 + *
253 + * @throws Exception might throws exception
254 + */
255 + void interfaceUp() throws Exception;
256 +
257 + /**
258 + * Starts the timer which waits for configured seconds and sends Delayed Ack Packet.
259 + */
260 + void startDelayedAckTimer();
261 +
262 + /**
263 + * Stops the delayed acknowledge timer.
264 + */
265 + void stopDelayedAckTimer();
266 +
267 + /**
268 + * Starts the hello timer which sends hello packet every configured seconds.
269 + */
270 + void startHelloTimer();
271 +
272 + /**
273 + * Stops the hello timer.
274 + */
275 + void stopHelloTimer();
276 +
277 + /**
278 + * Gets called when an interface is down.
279 + * All interface variables are reset, and interface timers disabled.
280 + * Also all neighbor connections associated with the interface are destroyed.
281 + */
282 + void interfaceDown();
283 +
284 + /**
285 + * Removes all the neighbors.
286 + */
287 + void removeNeighbors();
297 } 288 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -32,6 +32,7 @@ public interface OspfLinkListener { ...@@ -32,6 +32,7 @@ public interface OspfLinkListener {
32 * Notifies that a link got removed from network. 32 * Notifies that a link got removed from network.
33 * 33 *
34 * @param ospfRouter router instance 34 * @param ospfRouter router instance
35 + * @param ospfLinkTed link TED information of router
35 */ 36 */
36 - void deleteLink(OspfRouter ospfRouter); 37 + void deleteLink(OspfRouter ospfRouter, OspfLinkTed ospfLinkTed);
37 } 38 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -13,12 +13,10 @@ ...@@ -13,12 +13,10 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 -package org.onosproject.ospf.protocol.ospfpacket; 16 +package org.onosproject.ospf.controller;
17 17
18 import org.jboss.netty.buffer.ChannelBuffer; 18 import org.jboss.netty.buffer.ChannelBuffer;
19 import org.onlab.packet.Ip4Address; 19 import org.onlab.packet.Ip4Address;
20 -import org.onosproject.ospf.exceptions.OspfParseException;
21 -import org.onosproject.ospf.protocol.util.OspfPacketType;
22 20
23 /** 21 /**
24 * Representation of an OSPF message. 22 * Representation of an OSPF message.
...@@ -26,6 +24,20 @@ import org.onosproject.ospf.protocol.util.OspfPacketType; ...@@ -26,6 +24,20 @@ import org.onosproject.ospf.protocol.util.OspfPacketType;
26 public interface OspfMessage { 24 public interface OspfMessage {
27 25
28 /** 26 /**
27 + * Returns the interface index on which the message received.
28 + *
29 + * @return interface index on which the message received
30 + */
31 + int interfaceIndex();
32 +
33 + /**
34 + * Sets the interface index on which the message received.
35 + *
36 + * @param interfaceIndex interface index on which the message received
37 + */
38 + void setInterfaceIndex(int interfaceIndex);
39 +
40 + /**
29 * Returns the type of OSPF message. 41 * Returns the type of OSPF message.
30 * 42 *
31 * @return OSPF message type 43 * @return OSPF message type
...@@ -36,9 +48,9 @@ public interface OspfMessage { ...@@ -36,9 +48,9 @@ public interface OspfMessage {
36 * Reads from ChannelBuffer and initializes the type of LSA. 48 * Reads from ChannelBuffer and initializes the type of LSA.
37 * 49 *
38 * @param channelBuffer channel buffer instance 50 * @param channelBuffer channel buffer instance
39 - * @throws OspfParseException might throws exception while parsing buffer 51 + * @throws Exception might throws exception while parsing buffer
40 */ 52 */
41 - void readFrom(ChannelBuffer channelBuffer) throws OspfParseException; 53 + void readFrom(ChannelBuffer channelBuffer) throws Exception;
42 54
43 /** 55 /**
44 * Returns OSPFMessage as byte array. 56 * Returns OSPFMessage as byte array.
......
...@@ -189,4 +189,36 @@ public interface OspfNbr { ...@@ -189,4 +189,36 @@ public interface OspfNbr {
189 * @return neighbor's state 189 * @return neighbor's state
190 */ 190 */
191 OspfNeighborState getState(); 191 OspfNeighborState getState();
192 +
193 + /**
194 + * Starts the inactivity timer.
195 + */
196 + void startInactivityTimeCheck();
197 +
198 + /**
199 + * Stops the inactivity timer.
200 + */
201 + void stopInactivityTimeCheck();
202 +
203 + /**
204 + * Sets router dead interval.
205 + *
206 + * @param routerDeadInterval router dead interval
207 + */
208 + void setRouterDeadInterval(int routerDeadInterval);
209 +
210 + /**
211 + * Stops the flooding timer.
212 + */
213 + void stopFloodingTimer();
214 +
215 + /**
216 + * Stops the Dd Retransmission executor task.
217 + */
218 + void stopRxMtDdTimer();
219 +
220 + /**
221 + * Stops Ls request retransmission executor task.
222 + */
223 + void stopRxMtLsrTimer();
192 } 224 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -13,17 +13,32 @@ ...@@ -13,17 +13,32 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 -package org.onosproject.ospf.protocol.util; 16 +package org.onosproject.ospf.controller;
17 17
18 /** 18 /**
19 * Representation of different OSPF packet types. 19 * Representation of different OSPF packet types.
20 */ 20 */
21 public enum OspfPacketType { 21 public enum OspfPacketType {
22 22
23 + /**
24 + * OSPF hello packet.
25 + */
23 HELLO(1), 26 HELLO(1),
27 + /**
28 + * OSPF device description packet.
29 + */
24 DD(2), 30 DD(2),
31 + /**
32 + * OSPF link state request packet.
33 + */
25 LSREQUEST(3), 34 LSREQUEST(3),
35 + /**
36 + * OSPF link state update packet.
37 + */
26 LSUPDATE(4), 38 LSUPDATE(4),
39 + /**
40 + * OSPF link state acknowledge packet.
41 + */
27 LSAACK(5); 42 LSAACK(5);
28 43
29 private int value; 44 private int value;
......
...@@ -109,4 +109,56 @@ public interface TopologyForDeviceAndLink { ...@@ -109,4 +109,56 @@ public interface TopologyForDeviceAndLink {
109 * @param ospfArea area instance 109 * @param ospfArea area instance
110 */ 110 */
111 void updateLinkInformation(OspfLsa ospfLsa, OspfArea ospfArea); 111 void updateLinkInformation(OspfLsa ospfLsa, OspfArea ospfArea);
112 +
113 + /**
114 + * Gets deviceInformation as map.
115 + *
116 + * @return deviceInformationMap to delete from core
117 + */
118 + Map<String, DeviceInformation> deviceInformationMapToDelete();
119 +
120 + /**
121 + * Sets deviceInformation as map.
122 + *
123 + * @param key key to store in device info map
124 + * @param deviceInformationMapToDelete device information instance
125 + */
126 + void setDeviceInformationMapToDelete(String key, DeviceInformation deviceInformationMapToDelete);
127 +
128 + /**
129 + * Removes Device Information from deviceInformationMapToDelete.
130 + *
131 + * @param key key to remove device information
132 + */
133 + void removeDeviceInformationMapFromDeleteMap(String key);
134 +
135 + /**
136 + * Gets deviceInformation as map for Point-To-Point.
137 + *
138 + * @return deviceInformationMap
139 + */
140 + Map<String, DeviceInformation> deviceInformationMapForPointToPoint();
141 +
142 + /**
143 + * Sets deviceInformation as map for Point-To-Point..
144 + *
145 + * @param key key to store in device info
146 + * @param deviceInformationMap device information instance
147 + */
148 + void setDeviceInformationMapForPointToPoint(String key, DeviceInformation deviceInformationMap);
149 +
150 + /**
151 + * Gets linkInformation as map for PointToPoint.
152 + *
153 + * @return linkInformationMap
154 + */
155 + Map<String, LinkInformation> linkInformationMapForPointToPoint();
156 +
157 + /**
158 + * Sets linkInformation as map for PointToPoint.
159 + *
160 + * @param key key to store link info
161 + * @param linkInformationMap link information instance
162 + */
163 + void setLinkInformationMapForPointToPoint(String key, LinkInformation linkInformationMap);
112 } 164 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -21,7 +21,6 @@ import com.google.common.base.Objects; ...@@ -21,7 +21,6 @@ import com.google.common.base.Objects;
21 import org.onlab.packet.Ip4Address; 21 import org.onlab.packet.Ip4Address;
22 import org.onosproject.ospf.controller.LsaWrapper; 22 import org.onosproject.ospf.controller.LsaWrapper;
23 import org.onosproject.ospf.controller.OspfArea; 23 import org.onosproject.ospf.controller.OspfArea;
24 -import org.onosproject.ospf.controller.OspfAreaAddressRange;
25 import org.onosproject.ospf.controller.OspfInterface; 24 import org.onosproject.ospf.controller.OspfInterface;
26 import org.onosproject.ospf.controller.OspfLsa; 25 import org.onosproject.ospf.controller.OspfLsa;
27 import org.onosproject.ospf.controller.OspfLsaType; 26 import org.onosproject.ospf.controller.OspfLsaType;
...@@ -54,28 +53,14 @@ import java.util.Map; ...@@ -54,28 +53,14 @@ import java.util.Map;
54 public class OspfAreaImpl implements OspfArea { 53 public class OspfAreaImpl implements OspfArea {
55 private static final Logger log = LoggerFactory.getLogger(OspfAreaImpl.class); 54 private static final Logger log = LoggerFactory.getLogger(OspfAreaImpl.class);
56 /** 55 /**
57 - * Address ranges in order to aggregate routing information at area.
58 - * boundaries. Each address range is specified by an [address,mask] pair and
59 - * a status indication of either Advertise or DoNotAdvertise
60 - */
61 - private List<OspfAreaAddressRange> addressRanges;
62 - /**
63 - * This parameter indicates whether the area can carry data traffic that.
64 - * neither originates nor terminates in the area itself.
65 - */
66 - private boolean transitCapability;
67 - /**
68 * Whether AS-external-LSAs will be flooded into/throughout the area. 56 * Whether AS-external-LSAs will be flooded into/throughout the area.
69 */ 57 */
70 private boolean externalRoutingCapability; 58 private boolean externalRoutingCapability;
71 - /** 59 +
72 - * Indicates the cost of the default summary-LSA.
73 - */
74 - private int stubCost;
75 /** 60 /**
76 * Represents a list of all router's interfaces associated with this area. 61 * Represents a list of all router's interfaces associated with this area.
77 */ 62 */
78 - private List<OspfInterface> interfacesLst; 63 + private List<OspfInterface> ospfInterfaceList;
79 /** 64 /**
80 * The LS Database for this area. It includes router-LSAs, network-LSAs and. 65 * The LS Database for this area. It includes router-LSAs, network-LSAs and.
81 * summary-LSAs. AS-external-LSAs are hold in the OSPF class itself. 66 * summary-LSAs. AS-external-LSAs are hold in the OSPF class itself.
...@@ -116,18 +101,15 @@ public class OspfAreaImpl implements OspfArea { ...@@ -116,18 +101,15 @@ public class OspfAreaImpl implements OspfArea {
116 OspfAreaImpl that = (OspfAreaImpl) o; 101 OspfAreaImpl that = (OspfAreaImpl) o;
117 return Objects.equal(areaId, that.areaId) && 102 return Objects.equal(areaId, that.areaId) &&
118 Objects.equal(routerId, that.routerId) && 103 Objects.equal(routerId, that.routerId) &&
119 - Objects.equal(addressRanges.size(), that.addressRanges.size()) &&
120 - Objects.equal(transitCapability, that.transitCapability) &&
121 Objects.equal(externalRoutingCapability, that.externalRoutingCapability) && 104 Objects.equal(externalRoutingCapability, that.externalRoutingCapability) &&
122 - Objects.equal(stubCost, that.stubCost) && 105 + Objects.equal(ospfInterfaceList.size(), that.ospfInterfaceList.size()) &&
123 - Objects.equal(interfacesLst.size(), that.interfacesLst.size()) &&
124 Objects.equal(database, that.database); 106 Objects.equal(database, that.database);
125 } 107 }
126 108
127 @Override 109 @Override
128 public int hashCode() { 110 public int hashCode() {
129 - return Objects.hashCode(areaId, routerId, addressRanges, transitCapability, externalRoutingCapability, 111 + return Objects.hashCode(areaId, routerId, externalRoutingCapability,
130 - stubCost, interfacesLst, database); 112 + ospfInterfaceList, database);
131 } 113 }
132 114
133 /** 115 /**
...@@ -234,7 +216,7 @@ public class OspfAreaImpl implements OspfArea { ...@@ -234,7 +216,7 @@ public class OspfAreaImpl implements OspfArea {
234 networkLsa.setNetworkMask(mask); 216 networkLsa.setNetworkMask(mask);
235 //Adding our own router. 217 //Adding our own router.
236 networkLsa.addAttachedRouter(routerId()); 218 networkLsa.addAttachedRouter(routerId());
237 - Iterator iter = interfacesLst.iterator(); 219 + Iterator iter = ospfInterfaceList.iterator();
238 OspfInterfaceImpl ospfInterface = null; 220 OspfInterfaceImpl ospfInterface = null;
239 while (iter.hasNext()) { 221 while (iter.hasNext()) {
240 ospfInterface = (OspfInterfaceImpl) iter.next(); 222 ospfInterface = (OspfInterfaceImpl) iter.next();
...@@ -310,7 +292,7 @@ public class OspfAreaImpl implements OspfArea { ...@@ -310,7 +292,7 @@ public class OspfAreaImpl implements OspfArea {
310 */ 292 */
311 private void buildLinkForRouterLsa(RouterLsa routerLsa, OspfInterface ospfInterface) { 293 private void buildLinkForRouterLsa(RouterLsa routerLsa, OspfInterface ospfInterface) {
312 OspfInterfaceImpl nextInterface; 294 OspfInterfaceImpl nextInterface;
313 - Iterator interfaces = interfacesLst.iterator(); 295 + Iterator interfaces = ospfInterfaceList.iterator();
314 while (interfaces.hasNext()) { 296 while (interfaces.hasNext()) {
315 nextInterface = (OspfInterfaceImpl) interfaces.next(); 297 nextInterface = (OspfInterfaceImpl) interfaces.next();
316 if (nextInterface.state() == OspfInterfaceState.DOWN) { 298 if (nextInterface.state() == OspfInterfaceState.DOWN) {
...@@ -418,44 +400,6 @@ public class OspfAreaImpl implements OspfArea { ...@@ -418,44 +400,6 @@ public class OspfAreaImpl implements OspfArea {
418 } 400 }
419 401
420 /** 402 /**
421 - * Gets address range.
422 - *
423 - * @return list of area address ranges
424 - */
425 - public List<OspfAreaAddressRange> addressRanges() {
426 - return addressRanges;
427 - }
428 -
429 - /**
430 - * Sets the area address ranges.
431 - *
432 - * @param addressRanges list of area address range
433 - */
434 - @JsonProperty("addressRange")
435 - public void setAddressRanges(List<OspfAreaAddressRange> addressRanges) {
436 - this.addressRanges = addressRanges;
437 - }
438 -
439 - /**
440 - * Gets is transit capable or not.
441 - *
442 - * @return true if transit capable, else false
443 - */
444 - public boolean isTransitCapability() {
445 - return transitCapability;
446 - }
447 -
448 - /**
449 - * Sets transit capability.
450 - *
451 - * @param transitCapability true if transit capable, else false
452 - */
453 - @JsonProperty("transitCapability")
454 - public void setTransitCapability(boolean transitCapability) {
455 - this.transitCapability = transitCapability;
456 - }
457 -
458 - /**
459 * Gets external routing capability. 403 * Gets external routing capability.
460 * 404 *
461 * @return true if external routing capable, else false 405 * @return true if external routing capable, else false
...@@ -475,41 +419,22 @@ public class OspfAreaImpl implements OspfArea { ...@@ -475,41 +419,22 @@ public class OspfAreaImpl implements OspfArea {
475 } 419 }
476 420
477 /** 421 /**
478 - * Gets the stub cost.
479 - *
480 - * @return stub cost
481 - */
482 - public int stubCost() {
483 - return stubCost;
484 - }
485 -
486 - /**
487 - * Sets the stub cost.
488 - *
489 - * @param stubCost stub cost
490 - */
491 - @JsonProperty("stubCost")
492 - public void setStubCost(int stubCost) {
493 - this.stubCost = stubCost;
494 - }
495 -
496 - /**
497 * Gets the list of interfaces in this area. 422 * Gets the list of interfaces in this area.
498 * 423 *
499 * @return list of interfaces 424 * @return list of interfaces
500 */ 425 */
501 - public List<OspfInterface> getInterfacesLst() { 426 + public List<OspfInterface> ospfInterfaceList() {
502 - return interfacesLst; 427 + return ospfInterfaceList;
503 } 428 }
504 429
505 /** 430 /**
506 * Sets the list of interfaces attached to the area. 431 * Sets the list of interfaces attached to the area.
507 * 432 *
508 - * @param interfacesLst list of OspfInterface instances 433 + * @param ospfInterfaceList list of OspfInterface instances
509 */ 434 */
510 @JsonProperty("interface") 435 @JsonProperty("interface")
511 - public void setInterfacesLst(List<OspfInterface> interfacesLst) { 436 + public void setOspfInterfaceList(List<OspfInterface> ospfInterfaceList) {
512 - this.interfacesLst = interfacesLst; 437 + this.ospfInterfaceList = ospfInterfaceList;
513 } 438 }
514 439
515 /** 440 /**
...@@ -522,7 +447,7 @@ public class OspfAreaImpl implements OspfArea { ...@@ -522,7 +447,7 @@ public class OspfAreaImpl implements OspfArea {
522 public boolean noNeighborInLsaExchangeProcess() { 447 public boolean noNeighborInLsaExchangeProcess() {
523 OspfInterfaceImpl nextInterface; 448 OspfInterfaceImpl nextInterface;
524 OspfNeighborState nextNeighborState; 449 OspfNeighborState nextNeighborState;
525 - Iterator interfaces = interfacesLst.iterator(); 450 + Iterator interfaces = ospfInterfaceList.iterator();
526 while (interfaces.hasNext()) { 451 while (interfaces.hasNext()) {
527 nextInterface = (OspfInterfaceImpl) interfaces.next(); 452 nextInterface = (OspfInterfaceImpl) interfaces.next();
528 Iterator neighbors = nextInterface.listOfNeighbors().values().iterator(); 453 Iterator neighbors = nextInterface.listOfNeighbors().values().iterator();
...@@ -659,19 +584,14 @@ public class OspfAreaImpl implements OspfArea { ...@@ -659,19 +584,14 @@ public class OspfAreaImpl implements OspfArea {
659 return MoreObjects.toStringHelper(getClass()) 584 return MoreObjects.toStringHelper(getClass())
660 .omitNullValues() 585 .omitNullValues()
661 .add("areaID", areaId) 586 .add("areaID", areaId)
662 - .add("stubCost", stubCost) 587 + .add("ospfInterfaceList", ospfInterfaceList)
663 - .add("addressRanges", addressRanges)
664 - .add("interfacesLst", interfacesLst)
665 - .add("transitCapability", transitCapability)
666 .add("externalRoutingCapability", externalRoutingCapability) 588 .add("externalRoutingCapability", externalRoutingCapability)
667 .toString(); 589 .toString();
668 } 590 }
669 591
670 /** 592 /**
671 * Checks all Neighbors belonging to this Area whether they are in state lesser than the EXCHANGE. 593 * Checks all Neighbors belonging to this Area whether they are in state lesser than the EXCHANGE.
672 - * <p>
673 * Creates list of such neighbors 594 * Creates list of such neighbors
674 - * <p>
675 * Returns list of neighbors who satisfy the conditions 595 * Returns list of neighbors who satisfy the conditions
676 * 596 *
677 * @param ospfInterface OSPF interface instance 597 * @param ospfInterface OSPF interface instance
...@@ -716,7 +636,7 @@ public class OspfAreaImpl implements OspfArea { ...@@ -716,7 +636,7 @@ public class OspfAreaImpl implements OspfArea {
716 public void addToOtherNeighborLsaTxList(LsaHeader recLsa) { 636 public void addToOtherNeighborLsaTxList(LsaHeader recLsa) {
717 //Add the received LSA in other neighbors retransmission list. 637 //Add the received LSA in other neighbors retransmission list.
718 log.debug("OspfAreaImpl: addToOtherNeighborLsaTxList"); 638 log.debug("OspfAreaImpl: addToOtherNeighborLsaTxList");
719 - List<OspfInterface> ospfInterfaces = getInterfacesLst(); 639 + List<OspfInterface> ospfInterfaces = ospfInterfaceList();
720 for (OspfInterface ospfInterfaceFromArea : ospfInterfaces) { 640 for (OspfInterface ospfInterfaceFromArea : ospfInterfaces) {
721 Map neighbors = ospfInterfaceFromArea.listOfNeighbors(); 641 Map neighbors = ospfInterfaceFromArea.listOfNeighbors();
722 for (Object neighborIP : neighbors.keySet()) { 642 for (Object neighborIP : neighbors.keySet()) {
......
...@@ -18,47 +18,93 @@ package org.onosproject.ospf.controller.area; ...@@ -18,47 +18,93 @@ package org.onosproject.ospf.controller.area;
18 18
19 import com.google.common.base.MoreObjects; 19 import com.google.common.base.MoreObjects;
20 import com.google.common.base.Objects; 20 import com.google.common.base.Objects;
21 +import org.jboss.netty.channel.Channel;
22 +import org.jboss.netty.channel.ChannelFuture;
23 +import org.jboss.netty.channel.ChannelHandlerContext;
21 import org.onlab.packet.Ip4Address; 24 import org.onlab.packet.Ip4Address;
25 +import org.onosproject.ospf.controller.LsaWrapper;
26 +import org.onosproject.ospf.controller.OspfArea;
22 import org.onosproject.ospf.controller.OspfInterface; 27 import org.onosproject.ospf.controller.OspfInterface;
28 +import org.onosproject.ospf.controller.OspfLinkTed;
29 +import org.onosproject.ospf.controller.OspfLsa;
30 +import org.onosproject.ospf.controller.OspfMessage;
23 import org.onosproject.ospf.controller.OspfNbr; 31 import org.onosproject.ospf.controller.OspfNbr;
32 +import org.onosproject.ospf.controller.OspfNeighborState;
33 +import org.onosproject.ospf.controller.OspfPacketType;
34 +import org.onosproject.ospf.controller.OspfRouter;
35 +import org.onosproject.ospf.controller.TopologyForDeviceAndLink;
36 +import org.onosproject.ospf.controller.impl.Controller;
37 +import org.onosproject.ospf.controller.impl.OspfNbrImpl;
38 +import org.onosproject.ospf.controller.impl.TopologyForDeviceAndLinkImpl;
39 +import org.onosproject.ospf.controller.lsdb.LsaWrapperImpl;
40 +import org.onosproject.ospf.controller.lsdb.OspfLsdbImpl;
41 +import org.onosproject.ospf.controller.util.OspfEligibleRouter;
42 +import org.onosproject.ospf.controller.util.OspfInterfaceType;
24 import org.onosproject.ospf.protocol.lsa.LsaHeader; 43 import org.onosproject.ospf.protocol.lsa.LsaHeader;
25 import org.onosproject.ospf.protocol.lsa.OpaqueLsaHeader; 44 import org.onosproject.ospf.protocol.lsa.OpaqueLsaHeader;
45 +import org.onosproject.ospf.protocol.ospfpacket.OspfMessageWriter;
46 +import org.onosproject.ospf.protocol.ospfpacket.OspfPacketHeader;
47 +import org.onosproject.ospf.protocol.ospfpacket.subtype.LsRequestPacket;
48 +import org.onosproject.ospf.protocol.ospfpacket.types.DdPacket;
49 +import org.onosproject.ospf.protocol.ospfpacket.types.HelloPacket;
50 +import org.onosproject.ospf.protocol.ospfpacket.types.LsAcknowledge;
51 +import org.onosproject.ospf.protocol.ospfpacket.types.LsRequest;
52 +import org.onosproject.ospf.protocol.ospfpacket.types.LsUpdate;
53 +import org.onosproject.ospf.protocol.util.ChecksumCalculator;
26 import org.onosproject.ospf.protocol.util.OspfInterfaceState; 54 import org.onosproject.ospf.protocol.util.OspfInterfaceState;
27 import org.onosproject.ospf.protocol.util.OspfParameters; 55 import org.onosproject.ospf.protocol.util.OspfParameters;
56 +import org.onosproject.ospf.protocol.util.OspfUtil;
28 import org.slf4j.Logger; 57 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory; 58 import org.slf4j.LoggerFactory;
30 59
31 import java.util.ArrayList; 60 import java.util.ArrayList;
32 import java.util.HashMap; 61 import java.util.HashMap;
62 +import java.util.Iterator;
33 import java.util.List; 63 import java.util.List;
64 +import java.util.ListIterator;
65 +import java.util.Map;
34 import java.util.Set; 66 import java.util.Set;
67 +import java.util.concurrent.ConcurrentHashMap;
68 +import java.util.concurrent.Executors;
69 +import java.util.concurrent.ScheduledExecutorService;
70 +import java.util.concurrent.ScheduledFuture;
71 +import java.util.concurrent.TimeUnit;
35 72
36 /** 73 /**
37 * Representation of an OSPF interface. 74 * Representation of an OSPF interface.
38 */ 75 */
39 public class OspfInterfaceImpl implements OspfInterface { 76 public class OspfInterfaceImpl implements OspfInterface {
40 private static final Logger log = LoggerFactory.getLogger(OspfInterfaceImpl.class); 77 private static final Logger log = LoggerFactory.getLogger(OspfInterfaceImpl.class);
78 + private int interfaceIndex;
41 private Ip4Address ipAddress; 79 private Ip4Address ipAddress;
42 private Ip4Address ipNetworkMask; 80 private Ip4Address ipNetworkMask;
43 - private int areaId; 81 + private Channel channel = null;
44 private int helloIntervalTime; 82 private int helloIntervalTime;
45 private int routerDeadIntervalTime; 83 private int routerDeadIntervalTime;
46 - private int transmitDelay;
47 private int routerPriority; 84 private int routerPriority;
48 - private int systemInterfaceType;
49 private int interfaceType; 85 private int interfaceType;
50 - private int interfaceCost;
51 - private String authType;
52 - private String authKey;
53 - private int pollInterval;
54 private int mtu; 86 private int mtu;
55 private int reTransmitInterval; 87 private int reTransmitInterval;
56 private Ip4Address dr; 88 private Ip4Address dr;
57 private Ip4Address bdr; 89 private Ip4Address bdr;
58 private OspfInterfaceState state; 90 private OspfInterfaceState state;
59 private List<LsaHeader> linkStateHeaders = new ArrayList<>(); 91 private List<LsaHeader> linkStateHeaders = new ArrayList<>();
60 - private HashMap<String, OspfNbr> listOfNeighbors = new HashMap<>(); 92 + private Map<String, OspfNbr> listOfNeighbors = new ConcurrentHashMap<>();
61 - private HashMap<String, LsaHeader> listOfNeighborMap = new HashMap<>(); 93 + private Map<String, LsaHeader> listOfNeighborMap = new ConcurrentHashMap<>();
94 + private long delay = 0;
95 + private InternalHelloTimer helloTimerTask;
96 + private InternalWaitTimer waitTimerTask;
97 + private InternalDelayedAckTimer delayedAckTimerTask;
98 + private ScheduledExecutorService exServiceHello;
99 + private ScheduledExecutorService exServiceWait;
100 + private ScheduledExecutorService exServiceDelayedAck;
101 + private boolean isDelayedAckTimerScheduled = false;
102 + private int delayedAckTimerInterval = 2500;
103 + private int interfaceTypeOldValue = 0;
104 + private TopologyForDeviceAndLink topologyForDeviceAndLink = new TopologyForDeviceAndLinkImpl();
105 + private OspfArea ospfArea;
106 + private Controller controller;
107 +
62 108
63 /** 109 /**
64 * Gets the interface state. 110 * Gets the interface state.
...@@ -79,6 +125,51 @@ public class OspfInterfaceImpl implements OspfInterface { ...@@ -79,6 +125,51 @@ public class OspfInterfaceImpl implements OspfInterface {
79 } 125 }
80 126
81 /** 127 /**
128 + * Sets the netty channel.
129 + *
130 + * @param channel channel
131 + */
132 + public void setChannel(Channel channel) {
133 + this.channel = channel;
134 + }
135 +
136 + /**
137 + * Returns OSPF area instance.
138 + *
139 + * @return OSPF area instance
140 + */
141 + public OspfArea ospfArea() {
142 + return ospfArea;
143 + }
144 +
145 + /**
146 + * Sets OSPF controller instance.
147 + *
148 + * @param controller OSPF controller instance
149 + */
150 + public void setController(Controller controller) {
151 + this.controller = controller;
152 + }
153 +
154 + /**
155 + * Sets OSPF area instance.
156 + *
157 + * @param ospfArea OSPF area instance
158 + */
159 + public void setOspfArea(OspfArea ospfArea) {
160 + this.ospfArea = ospfArea;
161 + }
162 +
163 + /**
164 + * Gets interface state.
165 + *
166 + * @return interface state
167 + */
168 + public String interfaceState() {
169 + return state.interfaceState();
170 + }
171 +
172 + /**
82 * Gets link state headers. 173 * Gets link state headers.
83 * 174 *
84 * @return get the list of lsa headers 175 * @return get the list of lsa headers
...@@ -130,6 +221,33 @@ public class OspfInterfaceImpl implements OspfInterface { ...@@ -130,6 +221,33 @@ public class OspfInterfaceImpl implements OspfInterface {
130 return listOfNeighbors.get(neighborId); 221 return listOfNeighbors.get(neighborId);
131 } 222 }
132 223
224 + /**
225 + * Removes all the neighbors.
226 + */
227 + public void removeNeighbors() {
228 + Set<String> neighbors = listOfNeighbors.keySet();
229 + for (String neighborId : neighbors) {
230 + removeNeighbor(listOfNeighbors.get(neighborId));
231 + log.debug("Neighbor removed - {}", neighborId);
232 + }
233 + listOfNeighbors.clear();
234 + }
235 +
236 + /**
237 + * Removes neighbor from the interface neighbor map.
238 + *
239 + * @param ospfNeighbor OSPF neighbor instance
240 + */
241 + public void removeNeighbor(OspfNbr ospfNeighbor) {
242 + log.debug("Neighbor removed - {}", ospfNeighbor.neighborId());
243 + ospfNeighbor.stopInactivityTimeCheck();
244 + ospfNeighbor.stopFloodingTimer();
245 + ospfNeighbor.stopRxMtDdTimer();
246 + ospfNeighbor.stopRxMtLsrTimer();
247 +
248 + listOfNeighbors.remove(ospfNeighbor.neighborId());
249 + }
250 +
133 251
134 /** 252 /**
135 * Adds LSAHeader to map. 253 * Adds LSAHeader to map.
...@@ -175,7 +293,7 @@ public class OspfInterfaceImpl implements OspfInterface { ...@@ -175,7 +293,7 @@ public class OspfInterfaceImpl implements OspfInterface {
175 * 293 *
176 * @return listOfNeighbors as key value pair 294 * @return listOfNeighbors as key value pair
177 */ 295 */
178 - public HashMap<String, OspfNbr> listOfNeighbors() { 296 + public Map<String, OspfNbr> listOfNeighbors() {
179 return listOfNeighbors; 297 return listOfNeighbors;
180 } 298 }
181 299
...@@ -189,6 +307,24 @@ public class OspfInterfaceImpl implements OspfInterface { ...@@ -189,6 +307,24 @@ public class OspfInterfaceImpl implements OspfInterface {
189 } 307 }
190 308
191 /** 309 /**
310 + * Returns interface index.
311 + *
312 + * @return interface index
313 + */
314 + public int interfaceIndex() {
315 + return interfaceIndex;
316 + }
317 +
318 + /**
319 + * Set interface index.
320 + *
321 + * @param interfaceIndex interface index
322 + */
323 + public void setInterfaceIndex(int interfaceIndex) {
324 + this.interfaceIndex = interfaceIndex;
325 + }
326 +
327 + /**
192 * Gets the IP address. 328 * Gets the IP address.
193 * 329 *
194 * @return IP address 330 * @return IP address
...@@ -225,25 +361,6 @@ public class OspfInterfaceImpl implements OspfInterface { ...@@ -225,25 +361,6 @@ public class OspfInterfaceImpl implements OspfInterface {
225 } 361 }
226 362
227 /** 363 /**
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. 364 * Gets hello interval time.
248 * 365 *
249 * @return hello interval time 366 * @return hello interval time
...@@ -298,167 +415,1143 @@ public class OspfInterfaceImpl implements OspfInterface { ...@@ -298,167 +415,1143 @@ public class OspfInterfaceImpl implements OspfInterface {
298 } 415 }
299 416
300 /** 417 /**
301 - * Gets interface cost. 418 + * Gets max transfer unit.
302 * 419 *
303 - * @return interface cost 420 + * @return mtu an integer represents max transfer unit
304 */ 421 */
305 - public int interfaceCost() { 422 + public int mtu() {
306 - return interfaceCost; 423 + return mtu;
307 } 424 }
308 425
309 /** 426 /**
310 - * Sets interface cost. 427 + * Sets max transfer unit.
311 * 428 *
312 - * @param interfaceCost interface cost 429 + * @param mtu max transfer unit
313 */ 430 */
314 - public void setInterfaceCost(int interfaceCost) { 431 + public void setMtu(int mtu) {
315 - this.interfaceCost = interfaceCost; 432 + this.mtu = mtu;
316 } 433 }
317 434
318 /** 435 /**
319 - * Gets authentication type. 436 + * Gets retransmit interval.
320 * 437 *
321 - * @return authType represents authentication type 438 + * @return retransmit interval
322 */ 439 */
323 - public String authType() { 440 + public int reTransmitInterval() {
324 - return authType; 441 + return reTransmitInterval;
325 } 442 }
326 443
327 /** 444 /**
328 - * Sets authentication type. 445 + * Sets retransmit interval.
329 * 446 *
330 - * @param authType authType represents authentication type 447 + * @param reTransmitInterval retransmit interval
331 */ 448 */
332 - public void setAuthType(String authType) { 449 + public void setReTransmitInterval(int reTransmitInterval) {
333 - this.authType = authType; 450 + this.reTransmitInterval = reTransmitInterval;
334 } 451 }
335 452
336 /** 453 /**
337 - * Gets authentication key. 454 + * Gets designated routers IP address.
338 * 455 *
339 - * @return authKey represents authentication key 456 + * @return dr designated routers IP address
340 */ 457 */
341 - public String authKey() { 458 + public Ip4Address dr() {
342 - return authKey; 459 + return dr;
343 } 460 }
344 461
345 /** 462 /**
346 - * Sets authentication key. 463 + * Sets designated routers IP address.
347 * 464 *
348 - * @param authKey represents authentication key 465 + * @param dr designated routers IP address
349 */ 466 */
350 - public void setAuthKey(String authKey) { 467 + public void setDr(Ip4Address dr) {
351 - this.authKey = authKey; 468 + this.dr = dr;
352 } 469 }
353 470
354 /** 471 /**
355 - * Gets poll interval. 472 + * Gets backup designated routers IP address.
356 * 473 *
357 - * @return pollInterval an integer represents poll interval 474 + * @return bdr backup designated routers IP address
358 */ 475 */
359 - public int pollInterval() { 476 + public Ip4Address bdr() {
360 - return pollInterval; 477 + return bdr;
361 } 478 }
362 479
363 /** 480 /**
364 - * Sets poll interval. 481 + * Sets backup designated routers IP address.
365 * 482 *
366 - * @param pollInterval an integer represents poll interval 483 + * @param bdr backup designated routers IP address
367 */ 484 */
368 - public void setPollInterval(int pollInterval) { 485 + public void setBdr(Ip4Address bdr) {
369 - this.pollInterval = pollInterval; 486 + this.bdr = bdr;
370 } 487 }
371 488
372 /** 489 /**
373 - * Gets max transfer unit. 490 + * Represents an interface is up and connected.
374 * 491 *
375 - * @return mtu an integer represents max transfer unit 492 + * @throws Exception might throws exception
376 */ 493 */
377 - public int mtu() { 494 + public void interfaceUp() throws Exception {
378 - return mtu; 495 + log.debug("OSPFInterfaceChannelHandler::interfaceUp...!!!");
496 + if (interfaceType() == OspfInterfaceType.POINT_TO_POINT.value()) {
497 + setState(OspfInterfaceState.POINT2POINT);
498 + interfaceTypeOldValue = interfaceType();
499 + log.debug("OSPFInterfaceChannelHandler::InterfaceType {} state {} ",
500 + interfaceType(), state());
501 + } else if (interfaceType() == OspfInterfaceType.BROADCAST.value()) {
502 + //if router priority is 0, move the state to DROther
503 + interfaceTypeOldValue = interfaceType();
504 + if (routerPriority() == 0) {
505 + setState(OspfInterfaceState.DROTHER);
506 + } else {
507 + log.debug("OSPFInterfaceChannelHandler::InterfaceType {} state {} RouterPriority {}",
508 + interfaceType(),
509 + state(), routerPriority());
510 + setState(OspfInterfaceState.WAITING);
511 + //start wait timer - like inactivity timer with router deadInterval
512 + startWaitTimer();
513 + }
514 + }
515 + // Start hello timer with interval from config - convert seconds to milliseconds
516 + startHelloTimer();
517 + ospfArea.refreshArea(this);
379 } 518 }
380 519
520 +
381 /** 521 /**
382 - * Sets max transfer unit. 522 + * Gets called when a BDR was detected before the wait timer expired.
383 * 523 *
384 - * @param mtu max transfer unit 524 + * @param ch channel instance
525 + * @throws Exception might throws exception
385 */ 526 */
386 - public void setMtu(int mtu) { 527 + public void backupSeen(Channel ch) throws Exception {
387 - this.mtu = mtu; 528 + log.debug("OSPFInterfaceChannelHandler::backupSeen ");
529 + if (state() == OspfInterfaceState.WAITING) {
530 + electRouter(ch);
531 + }
388 } 532 }
389 533
390 /** 534 /**
391 - * Gets retransmit interval. 535 + * Gets called when no hello message received for particular period.
392 * 536 *
393 - * @return retransmit interval 537 + * @param ch channel instance
538 + * @throws Exception might throws exception
394 */ 539 */
395 - public int reTransmitInterval() { 540 + public void waitTimer(Channel ch) throws Exception {
396 - return reTransmitInterval; 541 + log.debug("OSPFInterfaceChannelHandler::waitTimer ");
542 + //section 9.4
543 + if (state() == OspfInterfaceState.WAITING) {
544 + electRouter(ch);
545 + }
397 } 546 }
398 547
399 /** 548 /**
400 - * Sets retransmit interval. 549 + * Initiates DR election process.
401 * 550 *
402 - * @param reTransmitInterval retransmit interval 551 + * @param ch netty channel instance
552 + * @throws Exception might throws exception
403 */ 553 */
404 - public void setReTransmitInterval(int reTransmitInterval) { 554 + public void callDrElection(Channel ch) throws Exception {
405 - this.reTransmitInterval = reTransmitInterval; 555 + log.debug("OSPFInterfaceChannelHandler::callDrElection ");
556 + //call when timer expired
557 + //no hello message received for particular interval
558 + //section 9.4
559 + electRouter(ch);
560 + interfaceTypeOldValue = interfaceType();
406 } 561 }
407 562
408 /** 563 /**
409 - * Gets designated routers IP address. 564 + * Neighbor change event is triggered when the router priority gets changed.
410 * 565 *
411 - * @return dr designated routers IP address 566 + * @throws Exception might throws exception
412 */ 567 */
413 - public Ip4Address dr() { 568 + public void neighborChange() throws Exception {
414 - return dr; 569 + log.debug("OSPFInterfaceChannelHandler::neighborChange ");
570 + if (state() == OspfInterfaceState.DR || state() == OspfInterfaceState.BDR ||
571 + state() == OspfInterfaceState.DROTHER) {
572 + electRouter(channel);
573 + }
415 } 574 }
416 575
417 /** 576 /**
418 - * Sets designated routers IP address. 577 + * Gets called when an interface is down.
578 + * All interface variables are reset, and interface timers disabled.
579 + * Also all neighbor connections associated with the interface are destroyed.
580 + */
581 + public void interfaceDown() {
582 + log.debug("OSPFInterfaceChannelHandler::interfaceDown ");
583 + stopHelloTimer();
584 + listOfNeighbors().clear();
585 + setState(OspfInterfaceState.DOWN);
586 + }
587 +
588 + /**
589 + * When an OSPF message received it is handed over to this method.
590 + * Based on the type of the OSPF message received it will be handed over
591 + * to corresponding message handler methods.
419 * 592 *
420 - * @param dr designated routers IP address 593 + * @param ospfMessage received OSPF message
594 + * @param ctx channel handler context instance.
595 + * @throws Exception might throws exception
421 */ 596 */
422 - public void setDr(Ip4Address dr) { 597 + public void processOspfMessage(OspfMessage ospfMessage, ChannelHandlerContext ctx) throws Exception {
423 - this.dr = dr; 598 + log.debug("OspfChannelHandler::processOspfMessage...!!!");
599 +
600 + if (!validateMessage(ospfMessage)) {
601 + return;
602 + }
603 +
604 + switch (ospfMessage.ospfMessageType().value()) {
605 + case OspfParameters.HELLO:
606 + processHelloMessage(ospfMessage, ctx);
607 + break;
608 + case OspfParameters.DD:
609 + processDdMessage(ospfMessage, ctx);
610 + break;
611 + case OspfParameters.LSREQUEST:
612 + processLsRequestMessage(ospfMessage, ctx);
613 + break;
614 + case OspfParameters.LSUPDATE:
615 + processLsUpdateMessage(ospfMessage, ctx);
616 + break;
617 + case OspfParameters.LSACK:
618 + processLsAckMessage(ospfMessage, ctx);
619 + break;
620 + default:
621 + log.debug("Unknown packet to process...!!!");
622 + break;
623 + }
424 } 624 }
425 625
426 /** 626 /**
427 - * Gets backup designated routers IP address. 627 + * Validates the OSPF message received.
428 * 628 *
429 - * @return bdr backup designated routers IP address 629 + * @param ospfMessage OSPF message.
630 + * @return true if it is a valid else false.
631 + * @throws Exception might throws exception
430 */ 632 */
431 - public Ip4Address bdr() { 633 + private boolean validateMessage(OspfMessage ospfMessage) throws Exception {
432 - return bdr; 634 + boolean isValid = true;
635 + OspfPacketHeader header = (OspfPacketHeader) ospfMessage;
636 +
637 + //added the check to eliminate self origin packets also two interfaces on same router.
638 + if (!header.sourceIp().equals(ipAddress()) && !header.routerId().equals(
639 + ospfArea.routerId())) {
640 + //Verify the checksum
641 + ChecksumCalculator checksum = new ChecksumCalculator();
642 + if (!checksum.isValidOspfCheckSum(ospfMessage, OspfUtil.OSPFPACKET_CHECKSUM_POS1,
643 + OspfUtil.OSPFPACKET_CHECKSUM_POS2)) {
644 + log.debug("Checksum mismatch. Received packet type {} ", ospfMessage.ospfMessageType());
645 + return false;
646 + }
647 + if (((OspfPacketHeader) ospfMessage).ospfVersion() != OspfUtil.OSPF_VERSION_2) {
648 + log.debug("Received osfpMessage Version should match with Interface Version ");
649 + return false;
650 + }
651 + if (!((OspfPacketHeader) ospfMessage).areaId().equals(ospfArea.areaId())) {
652 + log.debug("Received ospf packets are from different area than our Area ID. " +
653 + "Received Area ID {}, Our AreaId {} ",
654 + ((OspfPacketHeader) ospfMessage).areaId(), ospfArea.areaId());
655 + return false;
433 } 656 }
434 657
658 + //According to RFC-2328 (8.2)
435 /** 659 /**
436 - * Sets backup designated routers IP address. 660 + * ABR should receive packets from backbone 0.0.0.0 as we are not acting as ABR
661 + * we are rejecting the packet.
662 + */
663 + if (((OspfPacketHeader) ospfMessage).areaId().equals(Ip4Address.valueOf("0.0.0.0"))) {
664 + log.debug("ABR should receive packets from backbone 0.0.0.0 as we are not acting as " +
665 + "ABR we are rejecting the ospf packet");
666 + return false;
667 + }
668 + if (interfaceType() == OspfInterfaceType.BROADCAST.value() &&
669 + !OspfUtil.sameNetwork(((OspfPacketHeader) ospfMessage).sourceIp(),
670 + ipAddress(), ipNetworkMask())) {
671 + log.debug("Received packets from different subnets. Discarding...!!!");
672 + return false;
673 + }
674 + } else {
675 + isValid = false;
676 + }
677 +
678 + return isValid;
679 + }
680 +
681 + /**
682 + * Processes Hello message.
437 * 683 *
438 - * @param bdr backup designated routers IP address 684 + * @param ospfMessage OSPF message instance.
685 + * @param ctx context instance.
686 + * @throws Exception might throws exception
439 */ 687 */
440 - public void setBdr(Ip4Address bdr) { 688 + void processHelloMessage(OspfMessage ospfMessage, ChannelHandlerContext ctx) throws Exception {
441 - this.bdr = bdr; 689 + Channel channel = ctx.getChannel();
690 + log.debug("OspfChannelHandler::processHelloMessage...!!!");
691 + HelloPacket helloPacket = (HelloPacket) ospfMessage;
692 +
693 + // processing of hello packet as per RFC 2328 section 10.5
694 + log.debug("OspfChannelHandler::processHelloMessage::Interface Type {} OSPFInterfaceState {} ",
695 + interfaceType(), state());
696 +
697 + if (interfaceType() != OspfInterfaceType.POINT_TO_POINT.value()) {
698 + if (!helloPacket.networkMask().equals(ipNetworkMask())) {
699 + log.debug("OspfChannelHandler::processHelloMessage::Hello Packet Received does not " +
700 + "match the same network mask as the configure Interface");
701 + return;
702 + }
703 + }
704 + if (helloPacket.helloInterval() != helloIntervalTime()) {
705 + log.debug("OspfChannelHandler::processHelloMessage::Hello Packet Received have the same " +
706 + "hello interval as configured Interface");
707 + return;
708 + }
709 + if (helloPacket.routerDeadInterval() != routerDeadIntervalTime()) {
710 + log.debug("OspfChannelHandler::processHelloMessage::Hello Packet Received have the same " +
711 + "Router Dead interval as configured Interface");
712 + return;
713 + }
714 +
715 + if (interfaceType == OspfInterfaceType.POINT_TO_POINT.value() &&
716 + !helloPacket.dr().equals(OspfUtil.DEFAULTIP)) {
717 + log.debug("OspfChannelHandler::processHelloMessage:: Neighbor in broadcast network");
718 + return;
719 + }
720 +
721 + if (interfaceType == OspfInterfaceType.POINT_TO_POINT.value()) {
722 + // to verify if the neighbor which sent the hello is present in the OSPF Interface neighboring list .
723 + OspfNbr nbr;
724 + if (!isNeighborInList(helloPacket.routerId().toString())) {
725 + nbr = new OspfNbrImpl(ospfArea, this, helloPacket.sourceIp(),
726 + helloPacket.routerId(), helloPacket.options(), topologyForDeviceAndLink);
727 + addNeighbouringRouter(nbr);
728 + } else {
729 + nbr = neighbouringRouter(helloPacket.routerId().toString());
730 + nbr.setRouterPriority(helloPacket.routerPriority());
731 + }
732 + if (!helloPacket.containsNeighbour(ospfArea.routerId())) {
733 + ((OspfNbrImpl) nbr).oneWayReceived(helloPacket, channel);
734 + } else {
735 + ((OspfNbrImpl) nbr).twoWayReceived(helloPacket, ctx.getChannel());
736 + }
737 + } else if (interfaceType == OspfInterfaceType.BROADCAST.value()) {
738 +
739 + if (state() == OspfInterfaceState.WAITING) {
740 + if ((!helloPacket.dr().equals(Ip4Address.valueOf("0.0.0.0"))) &&
741 + (!helloPacket.bdr().equals(Ip4Address.valueOf("0.0.0.0")))) {
742 + stopWaitTimer();
743 + setDr(helloPacket.dr());
744 + setBdr(helloPacket.bdr());
745 + if (helloPacket.dr().equals(ipAddress())) {
746 + setState(OspfInterfaceState.DR);
747 + //refresh router Lsa
748 + ospfArea.refreshArea(this);
749 + } else if (helloPacket.bdr().equals(ipAddress())) {
750 + setState(OspfInterfaceState.BDR);
751 + //refresh router Lsa
752 + ospfArea.refreshArea(this);
753 + } else {
754 + setState(OspfInterfaceState.DROTHER);
755 + ospfArea.refreshArea(this);
756 + }
757 +
758 + } else if (!helloPacket.dr().equals(Ip4Address.valueOf("0.0.0.0")) ||
759 + !helloPacket.bdr().equals(Ip4Address.valueOf("0.0.0.0"))) {
760 + setDr(helloPacket.dr());
761 + setBdr(helloPacket.bdr());
762 + }
763 + Ip4Address sourceIp = helloPacket.sourceIp();
764 + OspfNbr nbr;
765 + if (!isNeighborInList(helloPacket.routerId().toString())) {
766 + nbr = new OspfNbrImpl(ospfArea, this, sourceIp, helloPacket.routerId(),
767 + helloPacket.options(), topologyForDeviceAndLink);
768 + nbr.setNeighborId(helloPacket.routerId());
769 + nbr.setNeighborBdr(helloPacket.bdr());
770 + nbr.setNeighborDr(helloPacket.dr());
771 + nbr.setRouterPriority(helloPacket.routerPriority());
772 + addNeighbouringRouter(nbr);
773 + } else {
774 + nbr = neighbouringRouter(helloPacket.routerId().toString());
775 + nbr.setRouterPriority(helloPacket.routerPriority());
776 + }
777 + if (!helloPacket.containsNeighbour(ospfArea.routerId())) {
778 + ((OspfNbrImpl) nbr).oneWayReceived(helloPacket, channel);
779 + } else {
780 + ((OspfNbrImpl) nbr).twoWayReceived(helloPacket, ctx.getChannel());
781 + }
782 +
783 + if (helloPacket.dr().equals(sourceIp)) {
784 + if (helloPacket.bdr().equals(Ip4Address.valueOf("0.0.0.0"))) {
785 + // call backup seen
786 + stopWaitTimer();
787 + backupSeen(ctx.getChannel());
788 + }
789 + }
790 +
791 + if (helloPacket.bdr().equals(sourceIp)) {
792 + // call backup seen
793 + stopWaitTimer();
794 + backupSeen(ctx.getChannel());
795 + }
796 + } else {
797 +
798 + if ((!helloPacket.dr().equals(Ip4Address.valueOf("0.0.0.0")) ||
799 + !helloPacket.bdr().equals(Ip4Address.valueOf("0.0.0.0")))
800 + && routerPriority() == 0) {
801 + setDr(helloPacket.dr());
802 + setBdr(helloPacket.bdr());
803 + }
804 + //To verify if the neighbor which sent the hello is present in the OSPF Interface neighboring list .
805 + Ip4Address sourceIp = helloPacket.sourceIp();
806 + OspfNbr nbr;
807 + if (!isNeighborInList(helloPacket.routerId().toString())) {
808 + nbr = new OspfNbrImpl(ospfArea, this, sourceIp, helloPacket.routerId(),
809 + helloPacket.options(), topologyForDeviceAndLink);
810 + nbr.setNeighborId(helloPacket.routerId());
811 + nbr.setNeighborBdr(helloPacket.bdr());
812 + nbr.setNeighborDr(helloPacket.dr());
813 + nbr.setRouterPriority(helloPacket.routerPriority());
814 + addNeighbouringRouter(nbr);
815 + ((OspfNbrImpl) nbr).oneWayReceived(helloPacket, channel);
816 + } else {
817 + log.debug("OspfChannelHandler::NeighborInList::helloPacket.bdr(): {}, " +
818 + "helloPacket.dr(): {}", helloPacket.bdr(), helloPacket.dr());
819 + nbr = neighbouringRouter(helloPacket.routerId().toString());
820 + nbr.setRouterPriority(helloPacket.routerPriority());
821 + if (!helloPacket.containsNeighbour(ospfArea.routerId())) {
822 + ((OspfNbrImpl) nbr).oneWayReceived(helloPacket, channel);
823 + } else {
824 + ((OspfNbrImpl) nbr).twoWayReceived(helloPacket, ctx.getChannel());
825 + }
826 + if (nbr.routerPriority() != helloPacket.routerPriority()) {
827 + nbr.setNeighborBdr(helloPacket.bdr());
828 + nbr.setNeighborDr(helloPacket.dr());
829 + neighborChange();
830 + }
831 +
832 +
833 + if (nbr.neighborIpAddr().equals(helloPacket.dr()) &&
834 + !(nbr.neighborIpAddr().equals(nbr.neighborDr()))) {
835 + nbr.setNeighborBdr(helloPacket.bdr());
836 + nbr.setNeighborDr(helloPacket.dr());
837 + neighborChange();
838 + }
839 +
840 + if (!(nbr.neighborIpAddr().equals(helloPacket.dr())) &&
841 + (nbr.neighborIpAddr().equals(nbr.neighborDr()))) {
842 + nbr.setNeighborBdr(helloPacket.bdr());
843 + nbr.setNeighborDr(helloPacket.dr());
844 + neighborChange();
845 + }
846 +
847 + if (nbr.neighborIpAddr().equals(helloPacket.bdr()) &&
848 + !(nbr.neighborIpAddr().equals(nbr.neighborBdr()))) {
849 + nbr.setNeighborBdr(helloPacket.bdr());
850 + nbr.setNeighborDr(helloPacket.dr());
851 + neighborChange();
852 + }
853 +
854 + if (!(nbr.neighborIpAddr().equals(helloPacket.bdr())) &&
855 + (nbr.neighborIpAddr().equals(nbr.neighborBdr()))) {
856 + nbr.setNeighborBdr(helloPacket.bdr());
857 + nbr.setNeighborDr(helloPacket.dr());
858 + neighborChange();
859 + }
860 +
861 + nbr.setNeighborBdr(helloPacket.bdr());
862 + nbr.setNeighborDr(helloPacket.dr());
863 + }
864 +
865 + }
866 + }
867 + }
868 +
869 + /**
870 + * process the DD message which received.
871 + *
872 + * @param ospfMessage OSPF message instance.
873 + * @param ctx channel handler context instance
874 + * @throws Exception might throws exception
875 + */
876 + void processDdMessage(OspfMessage ospfMessage, ChannelHandlerContext ctx) throws Exception {
877 + log.debug("OspfChannelHandler::processDdMessage...!!!");
878 + Channel channel = ctx.getChannel();
879 + DdPacket ddPacket = (DdPacket) ospfMessage;
880 + log.debug("Got DD packet from {}", ddPacket.sourceIp());
881 + //check it is present in listOfNeighbors
882 + Ip4Address neighbourId = ddPacket.routerId();
883 + OspfNbr nbr = neighbouringRouter(neighbourId.toString());
884 +
885 + if (nbr != null) {
886 + log.debug("OspfChannelHandler::processDdMessage:: OSPFNeighborState {}", nbr.getState());
887 + // set options for the NBR
888 + nbr.setIsOpaqueCapable(ddPacket.isOpaqueCapable());
889 + if (ddPacket.imtu() > mtu()) {
890 + log.debug("the MTU size is greater than the interface MTU");
891 + return;
892 + }
893 + if (nbr.getState() == OspfNeighborState.DOWN) {
894 + return;
895 + }
896 + if (nbr.getState() == OspfNeighborState.ATTEMPT) {
897 + return;
898 + }
899 + if (nbr.getState() == OspfNeighborState.TWOWAY) {
900 + nbr.adjOk(channel);
901 + return;
902 + }
903 + //if init is the state call twoWayReceived
904 + if (nbr.getState() == OspfNeighborState.INIT) {
905 + ((OspfNbrImpl) nbr).twoWayReceived(ddPacket, ctx.getChannel());
906 + } else if (nbr.getState() == OspfNeighborState.EXSTART) {
907 + //get I,M,MS Bits
908 + int initialize = ddPacket.isInitialize();
909 + int more = ddPacket.isMore();
910 + int masterOrSlave = ddPacket.isMaster();
911 + int options = ddPacket.options();
912 + nbr.setOptions(options);
913 +
914 + if (initialize == OspfUtil.INITIALIZE_SET && more == OspfUtil.MORE_SET &&
915 + masterOrSlave == OspfUtil.IS_MASTER) {
916 + if (ddPacket.getLsaHeaderList().isEmpty()) {
917 + if (OspfUtil.ipAddressToLong(ddPacket.routerId().toString()) >
918 + OspfUtil.ipAddressToLong(ospfArea.routerId().toString())) {
919 + nbr.setIsMaster(OspfUtil.IS_MASTER);
920 + ((OspfNbrImpl) nbr).setLastDdPacket(ddPacket);
921 + nbr.setDdSeqNum(ddPacket.sequenceNo());
922 + nbr.setOptions(ddPacket.options());
923 + ((OspfNbrImpl) nbr).negotiationDone(ddPacket, true, ddPacket.getLsaHeaderList(),
924 + ctx.getChannel());
925 + }
926 + }
927 + }
928 + if (initialize == OspfUtil.INITIALIZE_NOTSET && masterOrSlave == OspfUtil.NOT_MASTER) {
929 + if (nbr.ddSeqNum() == ddPacket.sequenceNo()) {
930 + if (OspfUtil.ipAddressToLong(ddPacket.routerId().toString()) <
931 + OspfUtil.ipAddressToLong(ospfArea.routerId().toString())) {
932 + ((OspfNbrImpl) nbr).setLastDdPacket(ddPacket);
933 + nbr.setOptions(ddPacket.options());
934 + nbr.setDdSeqNum(nbr.ddSeqNum() + 1);
935 + ((OspfNbrImpl) nbr).negotiationDone(ddPacket, false, ddPacket.getLsaHeaderList(),
936 + ctx.getChannel());
937 + }
938 + }
939 + }
940 +
941 + } else if (nbr.getState() == OspfNeighborState.EXCHANGE) {
942 + //get I,M,MS Bits
943 + log.debug("Neighbor state:: EXCHANGE");
944 + boolean isDuplicateDDPacket = compareDdPackets(ddPacket, ((OspfNbrImpl) nbr).lastDdPacket());
945 + int initialize = ddPacket.isInitialize();
946 + int more = ddPacket.isMore();
947 + int masterOrSlave = ddPacket.isMaster();
948 + int options = ddPacket.options();
949 +
950 + if (!isDuplicateDDPacket) {
951 + //if dd packet is not duplicate then continue
952 + if (nbr.isMaster() != masterOrSlave) {
953 + DdPacket newResPacket =
954 + (DdPacket) ((OspfNbrImpl) nbr).seqNumMismatch("Master/Slave Inconsistency");
955 + newResPacket.setDestinationIp(ddPacket.sourceIp());
956 + log.debug("Sending back DDPacket to {}", ddPacket.sourceIp());
957 + byte[] messageToWrite = getMessage(newResPacket);
958 + ctx.getChannel().write(messageToWrite);
959 + } else if (initialize == 1) {
960 + DdPacket newResPacket =
961 + (DdPacket) ((OspfNbrImpl) nbr).seqNumMismatch("Initialize bit inconsistency");
962 + newResPacket.setDestinationIp(ddPacket.sourceIp());
963 + log.debug("Sending back DDPacket to {}", ddPacket.sourceIp());
964 + byte[] messageToWrite = getMessage(newResPacket);
965 + ctx.getChannel().write(messageToWrite);
966 + } else {
967 +
968 + if (masterOrSlave == OspfUtil.NOT_MASTER) {
969 + if (ddPacket.sequenceNo() == nbr.ddSeqNum()) {
970 + //Process the DD Packet
971 + ((OspfNbrImpl) nbr).processDdPacket(false, ddPacket, ctx.getChannel());
972 + log.debug("Received DD Packet");
973 + } else {
974 + DdPacket newResPacket =
975 + (DdPacket) ((OspfNbrImpl) nbr).seqNumMismatch("Sequence Number Mismatch");
976 + newResPacket.setDestinationIp(ddPacket.sourceIp());
977 + log.debug("Sending back DDPacket to {}", ddPacket.sourceIp());
978 + byte[] messageToWrite = getMessage(newResPacket);
979 + ctx.getChannel().write(messageToWrite);
980 + }
981 + } else {
982 + //we are the slave
983 + if (ddPacket.sequenceNo() == (nbr.ddSeqNum() + 1)) {
984 + ((OspfNbrImpl) nbr).setLastDdPacket(ddPacket);
985 + ((OspfNbrImpl) nbr).processDdPacket(true, ddPacket, ctx.getChannel());
986 + log.debug("Process DD Packet");
987 + } else {
988 + DdPacket newResPacket =
989 + (DdPacket) ((OspfNbrImpl) nbr).seqNumMismatch("options inconsistency");
990 + newResPacket.setDestinationIp(ddPacket.sourceIp());
991 + log.debug("Sending back DDPacket to {}", ddPacket.sourceIp());
992 + byte[] messageToWrite = getMessage(newResPacket);
993 + ctx.getChannel().write(messageToWrite);
994 + }
995 + }
996 + }
997 + } else {
998 + if (masterOrSlave == OspfUtil.NOT_MASTER) {
999 + return;
1000 + } else {
1001 + DdPacket newResPacket = ((OspfNbrImpl) nbr).lastSentDdPacket();
1002 + log.debug("Sending back DDPacket to {}", ddPacket.sourceIp());
1003 + byte[] messageToWrite = getMessage(newResPacket);
1004 + ctx.getChannel().write(messageToWrite);
1005 + }
1006 + }
1007 + } else if (nbr.getState() == OspfNeighborState.LOADING || nbr.getState() == OspfNeighborState.FULL) {
1008 + //In case if we are slave then we have to send the last received DD Packet
1009 + int options = ddPacket.options();
1010 + if (nbr.options() != options) {
1011 + OspfMessage newResPacket = ((OspfNbrImpl) nbr).seqNumMismatch("Initialize bit inconsistency");
1012 + newResPacket.setDestinationIp(ddPacket.sourceIp());
1013 + byte[] messageToWrite = getMessage(newResPacket);
1014 + ctx.getChannel().write(messageToWrite);
1015 + } else if (ddPacket.isInitialize() == OspfUtil.INITIALIZE_SET) {
1016 + OspfMessage newResPacket = ((OspfNbrImpl) nbr).seqNumMismatch("Initialize bit inconsistency");
1017 + newResPacket.setDestinationIp(ddPacket.sourceIp());
1018 + byte[] messageToWrite = getMessage(newResPacket);
1019 + ctx.getChannel().write(messageToWrite);
1020 + }
1021 + boolean isDuplicate = compareDdPackets(ddPacket, ((OspfNbrImpl) nbr).lastDdPacket());
1022 + //we are master
1023 + if (nbr.isMaster() != OspfUtil.IS_MASTER) {
1024 + // check if the packet is duplicate, duplicates should be discarded by the master
1025 + if (isDuplicate) {
1026 + log.debug("received a duplicate DD packet");
1027 + }
1028 + } else {
1029 + //The slave must respond to duplicates by repeating the last Database Description packet
1030 + //that it had sent.
1031 + if (isDuplicate) {
1032 + ddPacket.setDestinationIp(ddPacket.sourceIp());
1033 + byte[] messageToWrite = getMessage(((OspfNbrImpl) nbr).lastSentDdPacket());
1034 + ctx.getChannel().write(messageToWrite);
1035 + log.debug("Sending back the duplicate packet ");
1036 + }
1037 + }
1038 + }
1039 + }
1040 + }
1041 +
1042 + /**
1043 + * Process the Ls Request message.
1044 + *
1045 + * @param ospfMessage OSPF message instance.
1046 + * @param ctx channel handler context instance.
1047 + * @throws Exception might throws exception
1048 + */
1049 + void processLsRequestMessage(OspfMessage ospfMessage, ChannelHandlerContext ctx) throws Exception {
1050 + log.debug("OspfChannelHandler::processLsRequestMessage...!!!");
1051 + Channel channel = ctx.getChannel();
1052 + LsRequest lsrPacket = (LsRequest) ospfMessage;
1053 + OspfNbr nbr = neighbouringRouter(lsrPacket.routerId().toString());
1054 +
1055 + if (nbr.getState() == OspfNeighborState.EXCHANGE || nbr.getState() == OspfNeighborState.LOADING ||
1056 + nbr.getState() == OspfNeighborState.FULL) {
1057 +
1058 + LsRequest reqMsg = (LsRequest) ospfMessage;
1059 + if (reqMsg.getLinkStateRequests().isEmpty()) {
1060 + log.debug("Received Link State Request Vector is Empty ");
1061 + return;
1062 + } else {
1063 + //Send the LsUpdate back
1064 + ListIterator<LsRequestPacket> listItr = reqMsg.getLinkStateRequests().listIterator();
1065 + while (listItr.hasNext()) {
1066 + LsUpdate lsupdate = new LsUpdate();
1067 + lsupdate.setOspfVer(OspfUtil.OSPF_VERSION);
1068 + lsupdate.setOspftype(OspfPacketType.LSUPDATE.value());
1069 + lsupdate.setRouterId(ospfArea.routerId());
1070 + lsupdate.setAreaId(ospfArea.areaId());
1071 + lsupdate.setAuthType(OspfUtil.NOT_ASSIGNED);
1072 + lsupdate.setAuthentication(OspfUtil.NOT_ASSIGNED);
1073 + lsupdate.setOspfPacLength(OspfUtil.NOT_ASSIGNED); // to calculate packet length
1074 + lsupdate.setChecksum(OspfUtil.NOT_ASSIGNED);
1075 +
1076 + //limit to mtu
1077 + int currentLength = OspfUtil.OSPF_HEADER_LENGTH + OspfUtil.FOUR_BYTES;
1078 + int maxSize = mtu() -
1079 + OspfUtil.LSA_HEADER_LENGTH; // subtract a normal IP header.
1080 + int noLsa = 0;
1081 + while (listItr.hasNext()) {
1082 + LsRequestPacket lsRequest = (LsRequestPacket) listItr.next();
1083 + // to verify length of the LSA
1084 + LsaWrapper wrapper = ospfArea.getLsa(lsRequest.lsType(), lsRequest.linkStateId(),
1085 + lsRequest.ownRouterId());
1086 + OspfLsa ospflsa = wrapper.ospfLsa();
1087 + if ((currentLength + ((LsaWrapperImpl) wrapper).lsaHeader().lsPacketLen()) >= maxSize) {
1088 + listItr.previous();
1089 + break;
1090 + }
1091 + if (ospflsa != null) {
1092 + lsupdate.addLsa(ospflsa);
1093 + noLsa++;
1094 +
1095 + currentLength = currentLength + ((LsaWrapperImpl) wrapper).lsaHeader().lsPacketLen();
1096 + } else {
1097 + nbr.badLSReq(channel);
1098 + }
1099 + }
1100 + lsupdate.setNumberOfLsa(noLsa);
1101 + //set the destination
1102 + if (state() == OspfInterfaceState.DR ||
1103 + state() == OspfInterfaceState.BDR ||
1104 + state() == OspfInterfaceState.POINT2POINT) {
1105 + lsupdate.setDestinationIp(OspfUtil.ALL_SPF_ROUTERS);
1106 + } else if (state() == OspfInterfaceState.DROTHER) {
1107 + lsupdate.setDestinationIp(OspfUtil.ALL_DROUTERS);
1108 + }
1109 + byte[] messageToWrite = getMessage(lsupdate);
1110 + ctx.getChannel().write(messageToWrite);
1111 + }
1112 + }
1113 + }
1114 + }
1115 +
1116 + /**
1117 + * Process the ls update message.
1118 + *
1119 + * @param ospfMessage OSPF message instance.
1120 + * @param ctx channel handler context instance.
1121 + * @throws Exception might throws exception
1122 + */
1123 + void processLsUpdateMessage(OspfMessage ospfMessage, ChannelHandlerContext ctx) throws Exception {
1124 + log.debug("OspfChannelHandler::processLsUpdateMessage");
1125 + LsUpdate lsUpdate = (LsUpdate) ospfMessage;
1126 + String neighbourId = lsUpdate.routerId().toString();
1127 + //LSUpdate packet has been associated with a particular neighbor.
1128 + //Neighbor should not be in lesser state than Exchange.
1129 + if (isNeighborInList(neighbourId)) {
1130 + OspfNbrImpl nbr = (OspfNbrImpl) neighbouringRouter(neighbourId);
1131 + if (nbr.getState() == OspfNeighborState.EXCHANGE ||
1132 + nbr.getState() == OspfNeighborState.LOADING) {
1133 + nbr.processLsUpdate(lsUpdate, ctx.getChannel());
1134 + } else if (nbr.getState() == OspfNeighborState.FULL) {
1135 + if (lsUpdate.noLsa() != 0) {
1136 + List<OspfLsa> list = lsUpdate.getLsaList();
1137 + Iterator itr = list.iterator();
1138 + while (itr.hasNext()) {
1139 + LsaHeader lsa = (LsaHeader) itr.next();
1140 + nbr.processReceivedLsa(lsa, true, ctx.getChannel(), lsUpdate.sourceIp());
1141 + }
1142 + } else {
1143 + return;
1144 + }
1145 + }
1146 + }
1147 + }
1148 +
1149 + /**
1150 + * Process the ls acknowledge message.
1151 + *
1152 + * @param ospfMessage OSPF message instance.
1153 + * @param ctx channel handler context instance.
1154 + * @throws Exception might throws exception
1155 + */
1156 + void processLsAckMessage(OspfMessage ospfMessage, ChannelHandlerContext ctx) throws Exception {
1157 + log.debug("OspfChannelHandler::processLsAckMessage");
1158 + LsAcknowledge lsAckPacket = (LsAcknowledge) ospfMessage;
1159 + //check it is present in listOfNeighbors
1160 + OspfNbrImpl nbr = (OspfNbrImpl) neighbouringRouter(lsAckPacket.routerId().toString());
1161 + if (nbr != null) {
1162 + if (nbr.getState().getValue() < OspfNeighborState.EXCHANGE.getValue()) {
1163 + // discard the packet.
1164 + return;
1165 + } else {
1166 + // process ls acknowledgements
1167 + Iterator itr = lsAckPacket.getLinkStateHeaders().iterator();
1168 + while (itr.hasNext()) {
1169 + LsaHeader lsRequest = (LsaHeader) itr.next();
1170 +
1171 + OspfLsa ospfLsa =
1172 + (OspfLsa) nbr.getPendingReTxList().get(((OspfAreaImpl) ospfArea).getLsaKey(lsRequest));
1173 + if (lsRequest != null && ospfLsa != null) {
1174 + String isSame = ((OspfLsdbImpl) ospfArea.database()).isNewerOrSameLsa(
1175 + lsRequest, (LsaHeader) ospfLsa);
1176 + if (isSame.equals("same")) {
1177 + nbr.getPendingReTxList().remove(((OspfAreaImpl) ospfArea).getLsaKey(lsRequest));
1178 + }
1179 + }
1180 + }
1181 + }
1182 + }
1183 + }
1184 +
1185 + /**
1186 + * Compares two Dd Packets to check whether its duplicate or not.
1187 + *
1188 + * @param receivedDPacket received DD packet from network.
1189 + * @param lastDdPacket Last DdPacket which we sent.
1190 + * @return true if it is a duplicate packet else false.
1191 + */
1192 + public boolean compareDdPackets(DdPacket receivedDPacket, DdPacket lastDdPacket) {
1193 + if (receivedDPacket.isInitialize() == lastDdPacket.isInitialize()) {
1194 + if (receivedDPacket.isMaster() == lastDdPacket.isMaster()) {
1195 + if (receivedDPacket.isMore() == lastDdPacket.isMore()) {
1196 + if (receivedDPacket.options() == lastDdPacket.options()) {
1197 + if (receivedDPacket.sequenceNo() == lastDdPacket.sequenceNo()) {
1198 + return true;
1199 + }
1200 + }
1201 + }
1202 + }
1203 + }
1204 + return false;
1205 + }
1206 +
1207 + /**
1208 + * Starts the hello timer which sends hello packet every configured seconds.
1209 + */
1210 + public void startHelloTimer() {
1211 + log.debug("OSPFInterfaceChannelHandler::startHelloTimer");
1212 + exServiceHello = Executors.newSingleThreadScheduledExecutor();
1213 + helloTimerTask = new InternalHelloTimer();
1214 + final ScheduledFuture<?> helloHandle =
1215 + exServiceHello.scheduleAtFixedRate(helloTimerTask, delay, helloIntervalTime, TimeUnit.SECONDS);
1216 + }
1217 +
1218 + /**
1219 + * Stops the hello timer.
1220 + */
1221 + public void stopHelloTimer() {
1222 + log.debug("OSPFInterfaceChannelHandler::stopHelloTimer ");
1223 + exServiceHello.shutdown();
1224 + }
1225 +
1226 + /**
1227 + * Starts the wait timer.
1228 + */
1229 + public void startWaitTimer() {
1230 + log.debug("OSPFNbr::startWaitTimer");
1231 + exServiceWait = Executors.newSingleThreadScheduledExecutor();
1232 + waitTimerTask = new InternalWaitTimer();
1233 + final ScheduledFuture<?> waitTimerHandle =
1234 + exServiceWait.schedule(waitTimerTask, routerDeadIntervalTime(), TimeUnit.SECONDS);
1235 + }
1236 +
1237 + /**
1238 + * Stops the wait timer.
1239 + */
1240 + public void stopWaitTimer() {
1241 + log.debug("OSPFNbr::stopWaitTimer ");
1242 + exServiceWait.shutdown();
1243 + }
1244 +
1245 + /**
1246 + * Starts the timer which waits for configured seconds and sends Delayed Ack Packet.
1247 + */
1248 + public void startDelayedAckTimer() {
1249 + if (!isDelayedAckTimerScheduled) {
1250 + log.debug("Started DelayedAckTimer...!!!");
1251 + exServiceDelayedAck = Executors.newSingleThreadScheduledExecutor();
1252 + delayedAckTimerTask = new InternalDelayedAckTimer();
1253 + final ScheduledFuture<?> delayAckHandle =
1254 + exServiceDelayedAck.scheduleAtFixedRate(delayedAckTimerTask, delayedAckTimerInterval,
1255 + delayedAckTimerInterval, TimeUnit.MILLISECONDS);
1256 + isDelayedAckTimerScheduled = true;
1257 + }
1258 + }
1259 +
1260 + /**
1261 + * Stops the delayed acknowledge timer.
1262 + */
1263 + public void stopDelayedAckTimer() {
1264 + if (isDelayedAckTimerScheduled) {
1265 + log.debug("Stopped DelayedAckTimer...!!!");
1266 + isDelayedAckTimerScheduled = false;
1267 + exServiceDelayedAck.shutdown();
1268 + }
1269 + }
1270 +
1271 + /**
1272 + * Performs DR election.
1273 + *
1274 + * @param ch Netty Channel instance.
1275 + * @throws Exception might throws exception
1276 + */
1277 + public void electRouter(Channel ch) throws Exception {
1278 +
1279 + Ip4Address currentDr = dr();
1280 + Ip4Address currentBdr = bdr();
1281 + OspfInterfaceState oldState = state();
1282 + OspfInterfaceState newState;
1283 +
1284 + log.debug("OSPFInterfaceChannelHandler::electRouter -> currentDr: {}, currentBdr: {}",
1285 + currentDr, currentBdr);
1286 + List<OspfEligibleRouter> eligibleRouters = calculateListOfEligibleRouters(new OspfEligibleRouter());
1287 +
1288 + log.debug("OSPFInterfaceChannelHandler::electRouter -> eligibleRouters: {}", eligibleRouters);
1289 + OspfEligibleRouter electedBdr = electBdr(eligibleRouters);
1290 + OspfEligibleRouter electedDr = electDr(eligibleRouters, electedBdr);
1291 +
1292 + setBdr(electedBdr.getIpAddress());
1293 + setDr(electedDr.getIpAddress());
1294 +
1295 + if (electedBdr.getIpAddress().equals(ipAddress()) &&
1296 + !electedBdr.getIpAddress().equals(currentBdr)) {
1297 + setState(OspfInterfaceState.BDR);
1298 + }
1299 +
1300 + if (electedDr.getIpAddress().equals(ipAddress()) &&
1301 + !electedDr.getIpAddress().equals(currentDr)) {
1302 + setState(OspfInterfaceState.DR);
1303 + }
1304 +
1305 + if (state() != oldState &&
1306 + !(state() == OspfInterfaceState.DROTHER &&
1307 + oldState.value() < OspfInterfaceState.DROTHER.value())) {
1308 + log.debug("Recalculating as the State is changed ");
1309 + log.debug("OSPFInterfaceChannelHandler::electRouter -> currentDr: {}, currentBdr: {}",
1310 + currentDr, currentBdr);
1311 + eligibleRouters = calculateListOfEligibleRouters(new OspfEligibleRouter());
1312 +
1313 + log.debug("OSPFInterfaceChannelHandler::electRouter -> eligibleRouters: {}", eligibleRouters);
1314 + electedBdr = electBdr(eligibleRouters);
1315 + electedDr = electDr(eligibleRouters, electedBdr);
1316 +
1317 + setBdr(electedBdr.getIpAddress());
1318 + setDr(electedDr.getIpAddress());
1319 + }
1320 +
1321 + if (electedBdr.getIpAddress().equals(ipAddress()) &&
1322 + !electedBdr.getIpAddress().equals(currentBdr)) {
1323 + setState(OspfInterfaceState.BDR);
1324 + ospfArea.refreshArea(this);
1325 + }
1326 +
1327 + if (electedDr.getIpAddress().equals(ipAddress()) &&
1328 + !electedDr.getIpAddress().equals(currentDr)) {
1329 + setState(OspfInterfaceState.DR);
1330 + //Refresh Router Lsa & Network Lsa
1331 + ospfArea.refreshArea(this);
1332 + }
1333 +
1334 + if (currentDr != electedDr.getIpAddress() || currentBdr != electedBdr.getIpAddress()) {
1335 + Set<String> negibhorIdList;
1336 + negibhorIdList = listOfNeighbors().keySet();
1337 + for (String routerid : negibhorIdList) {
1338 + OspfNbrImpl nbr = (OspfNbrImpl) neighbouringRouter(routerid);
1339 + if (nbr.getState().getValue() >= OspfNeighborState.TWOWAY.getValue()) {
1340 + nbr.adjOk(ch);
1341 + }
1342 + }
1343 + }
1344 +
1345 + log.debug("OSPFInterfaceChannelHandler::electRouter -> ElectedDR: {}, ElectedBDR: {}",
1346 + electedDr.getIpAddress(), electedBdr.getIpAddress());
1347 + }
1348 +
1349 +
1350 + /**
1351 + * BDR Election process. Find the list of eligible router to participate in the process.
1352 + *
1353 + * @param electedDr router elected as DR.
1354 + * @return list of eligible routers
1355 + */
1356 + public List<OspfEligibleRouter> calculateListOfEligibleRouters(OspfEligibleRouter electedDr) {
1357 + log.debug("OSPFNbr::calculateListOfEligibleRouters ");
1358 + Set<String> neighborIdList;
1359 + List<OspfEligibleRouter> eligibleRouters = new ArrayList<>();
1360 +
1361 + neighborIdList = listOfNeighbors().keySet();
1362 + for (String routerId : neighborIdList) {
1363 + OspfNbrImpl nbr = (OspfNbrImpl) neighbouringRouter(routerId);
1364 + if (nbr.getState().getValue() >= OspfNeighborState.TWOWAY.getValue() &&
1365 + nbr.routerPriority() > 0) {
1366 + OspfEligibleRouter router = new OspfEligibleRouter();
1367 + router.setIpAddress(nbr.neighborIpAddr());
1368 + router.setRouterId(nbr.neighborId());
1369 + router.setRouterPriority(nbr.routerPriority());
1370 + if (nbr.neighborDr().equals(nbr.neighborIpAddr()) ||
1371 + electedDr.getIpAddress().equals(nbr.neighborIpAddr())) {
1372 + router.setIsDr(true);
1373 + } else if (nbr.neighborBdr().equals(nbr.neighborIpAddr())) {
1374 + router.setIsBdr(true);
1375 + }
1376 + eligibleRouters.add(router);
1377 + }
1378 + }
1379 + // interface does not have states like two and all
1380 + if (routerPriority() > 0) {
1381 + OspfEligibleRouter router = new OspfEligibleRouter();
1382 + router.setIpAddress(ipAddress());
1383 + router.setRouterId(ospfArea.routerId());
1384 + router.setRouterPriority(routerPriority());
1385 + if (dr().equals(ipAddress()) ||
1386 + electedDr.getIpAddress().equals(ipAddress())) {
1387 + router.setIsDr(true);
1388 + } else if (bdr().equals(ipAddress()) &&
1389 + !dr().equals(ipAddress())) {
1390 + router.setIsBdr(true);
1391 + }
1392 +
1393 + eligibleRouters.add(router);
1394 + }
1395 +
1396 + return eligibleRouters;
1397 + }
1398 +
1399 + /**
1400 + * Based on router priority assigns BDR.
1401 + *
1402 + * @param eligibleRouters list of routers to participate in bdr election.
1403 + * @return OSPF Eligible router instance.
1404 + */
1405 + public OspfEligibleRouter electBdr(List<OspfEligibleRouter> eligibleRouters) {
1406 + log.debug("OSPFInterfaceChannelHandler::electBdr -> eligibleRouters: {}", eligibleRouters);
1407 + List<OspfEligibleRouter> declaredAsBdr = new ArrayList<>();
1408 + List<OspfEligibleRouter> notDrAndBdr = new ArrayList<>();
1409 + for (OspfEligibleRouter router : eligibleRouters) {
1410 + if (router.isBdr()) {
1411 + declaredAsBdr.add(router);
1412 + }
1413 + if (!router.isBdr() && !router.isDr()) {
1414 + notDrAndBdr.add(router);
1415 + }
1416 + }
1417 +
1418 + OspfEligibleRouter electedBdr = new OspfEligibleRouter();
1419 + if (!declaredAsBdr.isEmpty()) {
1420 + if (declaredAsBdr.size() == 1) {
1421 + electedBdr = declaredAsBdr.get(0);
1422 + } else if (declaredAsBdr.size() > 1) {
1423 + electedBdr = selectRouterBasedOnPriority(declaredAsBdr);
1424 + }
1425 + } else {
1426 + if (notDrAndBdr.size() == 1) {
1427 + electedBdr = notDrAndBdr.get(0);
1428 + } else if (notDrAndBdr.size() > 1) {
1429 + electedBdr = selectRouterBasedOnPriority(notDrAndBdr);
1430 + }
1431 + }
1432 +
1433 + electedBdr.setIsBdr(true);
1434 + electedBdr.setIsDr(false);
1435 +
1436 + return electedBdr;
442 } 1437 }
443 1438
444 /** 1439 /**
445 - * Get transmission delay. 1440 + * DR Election process.
446 * 1441 *
447 - * @return transmission delay 1442 + * @param eligibleRouters list of eligible routers.
1443 + * @param electedBdr Elected Bdr, OSPF eligible router instance.
1444 + * @return OSPF eligible router instance.
448 */ 1445 */
449 - public int transmitDelay() { 1446 + public OspfEligibleRouter electDr(List<OspfEligibleRouter> eligibleRouters,
450 - return transmitDelay; 1447 + OspfEligibleRouter electedBdr) {
1448 +
1449 + List<OspfEligibleRouter> declaredAsDr = new ArrayList<>();
1450 + for (OspfEligibleRouter router : eligibleRouters) {
1451 + if (router.isDr()) {
1452 + declaredAsDr.add(router);
1453 + }
1454 + }
1455 +
1456 + OspfEligibleRouter electedDr = new OspfEligibleRouter();
1457 + if (!declaredAsDr.isEmpty()) {
1458 + if (declaredAsDr.size() == 1) {
1459 + electedDr = declaredAsDr.get(0);
1460 + } else if (eligibleRouters.size() > 1) {
1461 + electedDr = selectRouterBasedOnPriority(declaredAsDr);
1462 + }
1463 + } else {
1464 + electedDr = electedBdr;
1465 + electedDr.setIsDr(true);
1466 + electedDr.setIsBdr(false);
1467 + }
1468 +
1469 + return electedDr;
451 } 1470 }
452 1471
453 /** 1472 /**
454 - * Sets transmission delay. 1473 + * DR election process.
455 * 1474 *
456 - * @param transmitDelay transmission delay 1475 + * @param routersList list of eligible routers.
1476 + * @return OSPF eligible router instance.
457 */ 1477 */
458 - public void setTransmitDelay(int transmitDelay) { 1478 + public OspfEligibleRouter selectRouterBasedOnPriority(List<OspfEligibleRouter> routersList) {
459 - this.transmitDelay = transmitDelay; 1479 +
1480 + OspfEligibleRouter initialRouter = routersList.get(0);
1481 +
1482 + for (int i = 1; i < routersList.size(); i++) {
1483 + OspfEligibleRouter router = routersList.get(i);
1484 + if (router.getRouterPriority() > initialRouter.getRouterPriority()) {
1485 + initialRouter = router;
1486 + } else if (router.getRouterPriority() == initialRouter.getRouterPriority()) {
1487 + try {
1488 + if (OspfUtil.ipAddressToLong(router.getIpAddress().toString()) >
1489 + OspfUtil.ipAddressToLong(initialRouter.getIpAddress().toString())) {
1490 + initialRouter = router;
1491 + }
1492 + } catch (Exception e) {
1493 + log.debug("OSPFInterfaceChannelHandler::selectRouterBasedOnPriority ->" +
1494 + " eligibleRouters: {}", initialRouter);
1495 + }
1496 + }
460 } 1497 }
461 1498
1499 + return initialRouter;
1500 + }
1501 +
1502 + /**
1503 + * Adds device information.
1504 + *
1505 + * @param ospfRouter OSPF router instance
1506 + */
1507 + public void addDeviceInformation(OspfRouter ospfRouter) {
1508 + controller.addDeviceDetails(ospfRouter);
1509 + }
1510 +
1511 + /**
1512 + * removes device information.
1513 + *
1514 + * @param ospfRouter OSPF neighbor instance
1515 + */
1516 + public void removeDeviceInformation(OspfRouter ospfRouter) {
1517 + controller.removeDeviceDetails(ospfRouter);
1518 + }
1519 +
1520 + /**
1521 + * Adds link information.
1522 + *
1523 + * @param ospfRouter OSPF router instance
1524 + * @param ospfLinkTed list link ted instances
1525 + */
1526 + public void addLinkInformation(OspfRouter ospfRouter, OspfLinkTed ospfLinkTed) {
1527 + controller.addLinkDetails(ospfRouter, ospfLinkTed);
1528 + }
1529 +
1530 + /**
1531 + * Removes link information.
1532 + *
1533 + * @param ospfRouter OSPF router instance
1534 + * @param ospfLinkTed OSPF link TED instance
1535 + */
1536 + public void removeLinkInformation(OspfRouter ospfRouter, OspfLinkTed ospfLinkTed) {
1537 + controller.removeLinkDetails(ospfRouter, ospfLinkTed);
1538 + }
1539 +
1540 + /**
1541 + * Gets message as bytes.
1542 + *
1543 + * @param ospfMessage OSPF message
1544 + * @return OSPF message
1545 + */
1546 + private byte[] getMessage(OspfMessage ospfMessage) {
1547 + OspfMessageWriter messageWriter = new OspfMessageWriter();
1548 + if (state().equals(OspfInterfaceState.POINT2POINT)) {
1549 + ospfMessage.setDestinationIp(OspfUtil.ALL_SPF_ROUTERS);
1550 + }
1551 + return (messageWriter.getMessage(ospfMessage, interfaceIndex, state.value()));
1552 + }
1553 +
1554 +
462 @Override 1555 @Override
463 public boolean equals(Object o) { 1556 public boolean equals(Object o) {
464 if (this == o) { 1557 if (this == o) {
...@@ -468,32 +1561,24 @@ public class OspfInterfaceImpl implements OspfInterface { ...@@ -468,32 +1561,24 @@ public class OspfInterfaceImpl implements OspfInterface {
468 return false; 1561 return false;
469 } 1562 }
470 OspfInterfaceImpl that = (OspfInterfaceImpl) o; 1563 OspfInterfaceImpl that = (OspfInterfaceImpl) o;
471 - return Objects.equal(areaId, that.areaId) && 1564 + return Objects.equal(helloIntervalTime, that.helloIntervalTime) &&
472 - Objects.equal(helloIntervalTime, that.helloIntervalTime) &&
473 Objects.equal(routerDeadIntervalTime, that.routerDeadIntervalTime) && 1565 Objects.equal(routerDeadIntervalTime, that.routerDeadIntervalTime) &&
474 - Objects.equal(transmitDelay, that.transmitDelay) &&
475 Objects.equal(routerPriority, that.routerPriority) && 1566 Objects.equal(routerPriority, that.routerPriority) &&
476 - Objects.equal(systemInterfaceType, that.systemInterfaceType) &&
477 Objects.equal(interfaceType, that.interfaceType) && 1567 Objects.equal(interfaceType, that.interfaceType) &&
478 - Objects.equal(interfaceCost, that.interfaceCost) &&
479 - Objects.equal(pollInterval, that.pollInterval) &&
480 Objects.equal(mtu, that.mtu) && 1568 Objects.equal(mtu, that.mtu) &&
481 Objects.equal(reTransmitInterval, that.reTransmitInterval) && 1569 Objects.equal(reTransmitInterval, that.reTransmitInterval) &&
482 Objects.equal(ipAddress, that.ipAddress) && 1570 Objects.equal(ipAddress, that.ipAddress) &&
483 Objects.equal(ipNetworkMask, that.ipNetworkMask) && 1571 Objects.equal(ipNetworkMask, that.ipNetworkMask) &&
484 Objects.equal(listOfNeighbors, that.listOfNeighbors) && 1572 Objects.equal(listOfNeighbors, that.listOfNeighbors) &&
485 - Objects.equal(authType, that.authType) &&
486 - Objects.equal(authKey, that.authKey) &&
487 Objects.equal(dr, that.dr) && 1573 Objects.equal(dr, that.dr) &&
488 Objects.equal(bdr, that.bdr); 1574 Objects.equal(bdr, that.bdr);
489 } 1575 }
490 1576
491 @Override 1577 @Override
492 public int hashCode() { 1578 public int hashCode() {
493 - return Objects.hashCode(ipAddress, ipNetworkMask, areaId, helloIntervalTime, 1579 + return Objects.hashCode(ipAddress, ipNetworkMask, helloIntervalTime,
494 - routerDeadIntervalTime, transmitDelay, routerPriority, listOfNeighbors, 1580 + routerDeadIntervalTime, routerPriority, listOfNeighbors,
495 - systemInterfaceType, interfaceType, interfaceCost, authType, authKey, 1581 + interfaceType, mtu, reTransmitInterval, dr, bdr);
496 - pollInterval, mtu, reTransmitInterval, dr, bdr);
497 } 1582 }
498 1583
499 @Override 1584 @Override
...@@ -502,19 +1587,188 @@ public class OspfInterfaceImpl implements OspfInterface { ...@@ -502,19 +1587,188 @@ public class OspfInterfaceImpl implements OspfInterface {
502 .omitNullValues() 1587 .omitNullValues()
503 .add("ipAddress", ipAddress) 1588 .add("ipAddress", ipAddress)
504 .add("routerPriority", routerPriority) 1589 .add("routerPriority", routerPriority)
505 - .add("areaID", areaId)
506 .add("helloIntervalTime", helloIntervalTime) 1590 .add("helloIntervalTime", helloIntervalTime)
507 .add("routerDeadIntervalTime", routerDeadIntervalTime) 1591 .add("routerDeadIntervalTime", routerDeadIntervalTime)
508 .add("interfaceType", interfaceType) 1592 .add("interfaceType", interfaceType)
509 - .add("interfaceCost", interfaceCost)
510 - .add("authType", authType)
511 - .add("authKey", authKey)
512 - .add("pollInterval", pollInterval)
513 .add("mtu", mtu) 1593 .add("mtu", mtu)
514 .add("reTransmitInterval", reTransmitInterval) 1594 .add("reTransmitInterval", reTransmitInterval)
515 .add("dr", dr) 1595 .add("dr", dr)
516 .add("bdr", bdr) 1596 .add("bdr", bdr)
517 - .add("transmitDelay", transmitDelay)
518 .toString(); 1597 .toString();
519 } 1598 }
1599 +
1600 + /**
1601 + * Represents a Hello task which sent a hello message every configured time interval.
1602 + */
1603 + private class InternalHelloTimer implements Runnable {
1604 +
1605 + /**
1606 + * Creates an instance of Hello Timer.
1607 + */
1608 + InternalHelloTimer() {
1609 + }
1610 +
1611 + @Override
1612 + public void run() {
1613 + if (channel != null && channel.isOpen() && channel.isConnected()) {
1614 + if (interfaceType() == OspfInterfaceType.BROADCAST.value()) {
1615 + if (interfaceTypeOldValue != interfaceType()) {
1616 + try {
1617 + callDrElection(channel);
1618 + } catch (Exception e) {
1619 + log.debug("Error while calling interfaceUp {}", e.getMessage());
1620 + }
1621 + }
1622 + } else {
1623 + if (interfaceTypeOldValue != interfaceType()) {
1624 + interfaceTypeOldValue = interfaceType();
1625 + }
1626 + }
1627 + HelloPacket hellopacket = new HelloPacket();
1628 + //Headers
1629 + hellopacket.setOspfVer(OspfUtil.OSPF_VERSION);
1630 + hellopacket.setOspftype(OspfPacketType.HELLO.value());
1631 + hellopacket.setOspfPacLength(0); //will be modified while encoding
1632 + hellopacket.setRouterId(ospfArea.routerId());
1633 + hellopacket.setAreaId(ospfArea.areaId());
1634 + hellopacket.setChecksum(0); //will be modified while encoding
1635 + hellopacket.setAuthType(OspfUtil.NOT_ASSIGNED);
1636 + hellopacket.setAuthentication(OspfUtil.NOT_ASSIGNED);
1637 + //Body
1638 + hellopacket.setNetworkMask(ipNetworkMask());
1639 + hellopacket.setOptions(ospfArea.options());
1640 + hellopacket.setHelloInterval(helloIntervalTime());
1641 + hellopacket.setRouterPriority(routerPriority());
1642 + hellopacket.setRouterDeadInterval(routerDeadIntervalTime());
1643 + hellopacket.setDr(dr());
1644 + hellopacket.setBdr(bdr());
1645 +
1646 + Map<String, OspfNbr> listOfNeighbors = listOfNeighbors();
1647 + Set<String> keys = listOfNeighbors.keySet();
1648 + Iterator itr = keys.iterator();
1649 + while (itr.hasNext()) {
1650 + String nbrKey = (String) itr.next();
1651 + OspfNbrImpl nbr = (OspfNbrImpl) listOfNeighbors.get(nbrKey);
1652 + if (nbr.getState() != OspfNeighborState.DOWN) {
1653 + hellopacket.addNeighbor(Ip4Address.valueOf(nbrKey));
1654 + }
1655 + }
1656 + // build a hello Packet
1657 + if (channel == null || !channel.isOpen() || !channel.isConnected()) {
1658 + log.debug("Hello Packet not sent !!.. Channel Issue...");
1659 + return;
1660 + }
1661 +
1662 + hellopacket.setDestinationIp(OspfUtil.ALL_SPF_ROUTERS);
1663 + byte[] messageToWrite = getMessage(hellopacket);
1664 + ChannelFuture future = channel.write(messageToWrite);
1665 + if (future.isSuccess()) {
1666 + log.debug("Hello Packet successfully sent !!");
1667 + } else {
1668 + future.awaitUninterruptibly();
1669 + }
1670 +
1671 + }
1672 + }
1673 + }
1674 +
1675 + /**
1676 + * Represents a Wait Timer task which waits the interface state to become WAITING.
1677 + * It initiates DR election process.
1678 + */
1679 + private class InternalWaitTimer implements Runnable {
1680 + Channel ch;
1681 +
1682 + /**
1683 + * Creates an instance of Wait Timer.
1684 + */
1685 + InternalWaitTimer() {
1686 + this.ch = channel;
1687 + }
1688 +
1689 + @Override
1690 + public void run() {
1691 + log.debug("Wait timer expires...");
1692 + if (ch != null && ch.isConnected()) {
1693 + try {
1694 + waitTimer(ch);
1695 + } catch (Exception e) {
1696 + log.debug("Exception at wait timer ...!!!");
1697 + }
1698 +
1699 + }
1700 + }
1701 + }
1702 +
1703 + /**
1704 + * Represents a task which sent a LS Acknowledge from the link state headers list.
1705 + */
1706 + private class InternalDelayedAckTimer implements Runnable {
1707 + Channel ch;
1708 +
1709 + /**
1710 + * Creates an instance of Delayed acknowledge timer.
1711 + */
1712 + InternalDelayedAckTimer() {
1713 + this.ch = channel;
1714 + }
1715 +
1716 + @Override
1717 + public void run() {
1718 + if (!linkStateHeaders().isEmpty()) {
1719 + isDelayedAckTimerScheduled = true;
1720 + if (ch != null && ch.isConnected()) {
1721 +
1722 + List<LsaHeader> listOfLsaHeadersAcknowledged = new ArrayList<>();
1723 + List<LsaHeader> listOfLsaHeaders = linkStateHeaders();
1724 + log.debug("Delayed Ack, Number of Lsa's to Ack {}", listOfLsaHeaders.size());
1725 + Iterator itr = listOfLsaHeaders.iterator();
1726 + while (itr.hasNext()) {
1727 + LsAcknowledge ackContent = new LsAcknowledge();
1728 + //Setting OSPF Header
1729 + ackContent.setOspfVer(OspfUtil.OSPF_VERSION);
1730 + ackContent.setOspftype(OspfPacketType.LSAACK.value());
1731 + ackContent.setRouterId(ospfArea.routerId());
1732 + ackContent.setAreaId(ospfArea.areaId());
1733 + ackContent.setAuthType(OspfUtil.NOT_ASSIGNED);
1734 + ackContent.setAuthentication(OspfUtil.NOT_ASSIGNED);
1735 + ackContent.setOspfPacLength(OspfUtil.NOT_ASSIGNED);
1736 + ackContent.setChecksum(OspfUtil.NOT_ASSIGNED);
1737 + //limit to mtu
1738 + int currentLength = OspfUtil.OSPF_HEADER_LENGTH;
1739 + int maxSize = mtu() -
1740 + OspfUtil.LSA_HEADER_LENGTH; // subtract a normal IP header.
1741 + while (itr.hasNext()) {
1742 + if ((currentLength + OspfUtil.LSA_HEADER_LENGTH) >= maxSize) {
1743 + break;
1744 + }
1745 + LsaHeader lsaHeader = (LsaHeader) itr.next();
1746 + ackContent.addLinkStateHeader(lsaHeader);
1747 + currentLength = currentLength + OspfUtil.LSA_HEADER_LENGTH;
1748 + listOfLsaHeadersAcknowledged.add(lsaHeader);
1749 + log.debug("Delayed Ack, Added Lsa's to Ack {}", lsaHeader);
1750 + }
1751 +
1752 + log.debug("Delayed Ack, Number of Lsa's in LsAck packet {}",
1753 + ackContent.getLinkStateHeaders().size());
1754 +
1755 + //set the destination
1756 + if (state() == OspfInterfaceState.DR || state() == OspfInterfaceState.BDR
1757 + || state() == OspfInterfaceState.POINT2POINT) {
1758 + ackContent.setDestinationIp(OspfUtil.ALL_SPF_ROUTERS);
1759 + } else if (state() == OspfInterfaceState.DROTHER) {
1760 + ackContent.setDestinationIp(OspfUtil.ALL_DROUTERS);
1761 + }
1762 + byte[] messageToWrite = getMessage(ackContent);
1763 + ch.write(messageToWrite);
1764 +
1765 + for (LsaHeader lsa : listOfLsaHeadersAcknowledged) {
1766 + linkStateHeaders().remove(lsa);
1767 + removeLsaFromNeighborMap(((OspfAreaImpl) ospfArea).getLsaKey(lsa));
1768 + }
1769 + }
1770 + }
1771 + }
1772 + }
1773 + }
520 } 1774 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -15,13 +15,15 @@ ...@@ -15,13 +15,15 @@
15 */ 15 */
16 package org.onosproject.ospf.controller.impl; 16 package org.onosproject.ospf.controller.impl;
17 17
18 -import org.jboss.netty.bootstrap.ServerBootstrap; 18 +import org.jboss.netty.bootstrap.ClientBootstrap;
19 import org.jboss.netty.channel.AdaptiveReceiveBufferSizePredictor; 19 import org.jboss.netty.channel.AdaptiveReceiveBufferSizePredictor;
20 +import org.jboss.netty.channel.ChannelFuture;
21 +import org.jboss.netty.channel.ChannelFutureListener;
20 import org.jboss.netty.channel.ChannelPipelineFactory; 22 import org.jboss.netty.channel.ChannelPipelineFactory;
21 import org.jboss.netty.channel.FixedReceiveBufferSizePredictorFactory; 23 import org.jboss.netty.channel.FixedReceiveBufferSizePredictorFactory;
22 -import org.jboss.netty.channel.group.ChannelGroup; 24 +import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory;
23 -import org.jboss.netty.channel.group.DefaultChannelGroup; 25 +import org.onlab.packet.Ip4Address;
24 -import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; 26 +import org.onlab.packet.TpPort;
25 import org.onosproject.net.driver.DriverService; 27 import org.onosproject.net.driver.DriverService;
26 import org.onosproject.ospf.controller.OspfAgent; 28 import org.onosproject.ospf.controller.OspfAgent;
27 import org.onosproject.ospf.controller.OspfArea; 29 import org.onosproject.ospf.controller.OspfArea;
...@@ -29,42 +31,137 @@ import org.onosproject.ospf.controller.OspfInterface; ...@@ -29,42 +31,137 @@ import org.onosproject.ospf.controller.OspfInterface;
29 import org.onosproject.ospf.controller.OspfLinkTed; 31 import org.onosproject.ospf.controller.OspfLinkTed;
30 import org.onosproject.ospf.controller.OspfProcess; 32 import org.onosproject.ospf.controller.OspfProcess;
31 import org.onosproject.ospf.controller.OspfRouter; 33 import org.onosproject.ospf.controller.OspfRouter;
34 +import org.onosproject.ospf.protocol.util.OspfUtil;
32 import org.slf4j.Logger; 35 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory; 36 import org.slf4j.LoggerFactory;
34 37
35 import java.net.InetAddress; 38 import java.net.InetAddress;
36 import java.net.InetSocketAddress; 39 import java.net.InetSocketAddress;
37 import java.net.NetworkInterface; 40 import java.net.NetworkInterface;
38 -import java.net.SocketException;
39 -import java.util.ArrayList;
40 -import java.util.Collections;
41 import java.util.Enumeration; 41 import java.util.Enumeration;
42 -import java.util.HashSet;
43 -import java.util.Iterator;
44 import java.util.List; 42 import java.util.List;
45 -import java.util.Set;
46 -import java.util.concurrent.Executor;
47 import java.util.concurrent.Executors; 43 import java.util.concurrent.Executors;
44 +import java.util.concurrent.ScheduledExecutorService;
45 +import java.util.concurrent.TimeUnit;
46 +
47 +import static org.onlab.util.Tools.groupedThreads;
48 48
49 /** 49 /**
50 - * Representation of the main controller class. Handles all setup and network listeners. 50 + * Representation of an OSPF controller.
51 */ 51 */
52 public class Controller { 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; 53 protected static final int BUFFER_SIZE = 4 * 1024 * 1024;
56 - private static final String PROCESS = "process"; 54 + private static final Logger log = LoggerFactory.getLogger(Controller.class);
57 - private static final String AREA = "area"; 55 + private static final int RETRY_INTERVAL = 4;
58 - private static final String INTERFACE = "interface"; 56 + private final int peerWorkerThreads = 16;
59 -
60 - protected int ospfPort = 7000;
61 - protected int workerThreads = 16;
62 protected long systemStartTime; 57 protected long systemStartTime;
58 + byte[] configPacket = null;
59 + private List<OspfProcess> processes = null;
60 + private OspfInterfaceChannelHandler ospfChannelHandler;
61 + private NioClientSocketChannelFactory peerExecFactory;
62 + private ClientBootstrap peerBootstrap = null;
63 + private TpPort isisPort = TpPort.tpPort(OspfUtil.SPORT);
64 + private ScheduledExecutorService connectExecutor = null;
65 + private int connectRetryCounter = 0;
66 + private int connectRetryTime;
63 private DriverService driverService; 67 private DriverService driverService;
64 private OspfAgent agent; 68 private OspfAgent agent;
65 - private List<ChannelGroup> cgList = new ArrayList(); 69 +
66 - private List<NioServerSocketChannelFactory> execFactoryLst = new ArrayList<>(); 70 + /**
67 - private List<OspfProcess> processes; 71 + * Deactivates OSPF controller.
72 + */
73 + public void isisDeactivate() {
74 + peerExecFactory.shutdown();
75 + }
76 +
77 + /**
78 + * Updates the processes configuration.
79 + *
80 + * @param ospfProcesses list of OSPF process instances
81 + * @throws Exception might throws parse exception
82 + */
83 + public void updateConfig(List<OspfProcess> ospfProcesses) throws Exception {
84 + log.debug("Controller::UpdateConfig called");
85 + configPacket = new byte[OspfUtil.CONFIG_LENGTH];
86 + byte numberOfInterface = 0; // number of interfaces to configure
87 + configPacket[0] = (byte) 0xFF; // its a conf packet - identifier
88 + for (OspfProcess ospfProcess : ospfProcesses) {
89 + log.debug("OspfProcessDetails : " + ospfProcess);
90 + for (OspfArea ospfArea : ospfProcess.areas()) {
91 + for (OspfInterface ospfInterface : ospfArea.ospfInterfaceList()) {
92 + log.debug("OspfInterfaceDetails : " + ospfInterface);
93 + numberOfInterface++;
94 + configPacket[2 * numberOfInterface] = (byte) ospfInterface.interfaceIndex();
95 + configPacket[(2 * numberOfInterface) + 1] = (byte) 4;
96 + }
97 + }
98 + }
99 + configPacket[1] = numberOfInterface;
100 + //First time configuration
101 + if (processes == null) {
102 + if (ospfProcesses.size() > 0) {
103 + processes = ospfProcesses;
104 + connectPeer();
105 + }
106 + } else {
107 + ospfChannelHandler.updateInterfaceMap(ospfProcesses);
108 + //Send the config packet
109 + ospfChannelHandler.sentConfigPacket(configPacket);
110 + }
111 + }
112 +
113 + /**
114 + * Initializes the netty client channel connection.
115 + */
116 + private void initConnection() {
117 + if (peerBootstrap != null) {
118 + return;
119 + }
120 + peerBootstrap = createPeerBootStrap();
121 +
122 + peerBootstrap.setOption("reuseAddress", true);
123 + peerBootstrap.setOption("tcpNoDelay", true);
124 + peerBootstrap.setOption("keepAlive", true);
125 + peerBootstrap.setOption("receiveBufferSize", Controller.BUFFER_SIZE);
126 + peerBootstrap.setOption("receiveBufferSizePredictorFactory",
127 + new FixedReceiveBufferSizePredictorFactory(
128 + Controller.BUFFER_SIZE));
129 + peerBootstrap.setOption("receiveBufferSizePredictor",
130 + new AdaptiveReceiveBufferSizePredictor(64, 4096, 65536));
131 + peerBootstrap.setOption("child.keepAlive", true);
132 + peerBootstrap.setOption("child.tcpNoDelay", true);
133 + peerBootstrap.setOption("child.sendBufferSize", Controller.BUFFER_SIZE);
134 + peerBootstrap.setOption("child.receiveBufferSize", Controller.BUFFER_SIZE);
135 + peerBootstrap.setOption("child.receiveBufferSizePredictorFactory",
136 + new FixedReceiveBufferSizePredictorFactory(
137 + Controller.BUFFER_SIZE));
138 + peerBootstrap.setOption("child.reuseAddress", true);
139 +
140 + ospfChannelHandler = new OspfInterfaceChannelHandler(this, processes);
141 + ChannelPipelineFactory pfact = new OspfPipelineFactory(ospfChannelHandler);
142 + peerBootstrap.setPipelineFactory(pfact);
143 + }
144 +
145 + /**
146 + * Creates peer boot strap.
147 + *
148 + * @return client bootstrap instance
149 + */
150 + private ClientBootstrap createPeerBootStrap() {
151 +
152 + if (peerWorkerThreads == 0) {
153 + peerExecFactory = new NioClientSocketChannelFactory(
154 + Executors.newCachedThreadPool(groupedThreads("onos/isis", "boss-%d")),
155 + Executors.newCachedThreadPool(groupedThreads("onos/isis", "worker-%d")));
156 + return new ClientBootstrap(peerExecFactory);
157 + } else {
158 + peerExecFactory = new NioClientSocketChannelFactory(
159 + Executors.newCachedThreadPool(groupedThreads("onos/isis", "boss-%d")),
160 + Executors.newCachedThreadPool(groupedThreads("onos/isis", "worker-%d")),
161 + peerWorkerThreads);
162 + return new ClientBootstrap(peerExecFactory);
163 + }
164 + }
68 165
69 /** 166 /**
70 * Gets all configured processes. 167 * Gets all configured processes.
...@@ -107,35 +204,13 @@ public class Controller { ...@@ -107,35 +204,13 @@ public class Controller {
107 * Removes link details. 204 * Removes link details.
108 * 205 *
109 * @param ospfRouter OSPF router instance 206 * @param ospfRouter OSPF router instance
207 + * @param ospfLinkTed OSPF link ted instance
110 */ 208 */
111 - public void removeLinkDetails(OspfRouter ospfRouter) { 209 + public void removeLinkDetails(OspfRouter ospfRouter, OspfLinkTed ospfLinkTed) {
112 - agent.deleteLink(ospfRouter); 210 + agent.deleteLink(ospfRouter, ospfLinkTed);
113 } 211 }
114 212
115 /** 213 /**
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. 214 * Initializes internal data structures.
140 */ 215 */
141 public void init() { 216 public void init() {
...@@ -149,7 +224,7 @@ public class Controller { ...@@ -149,7 +224,7 @@ public class Controller {
149 * @param driverService driver service instance 224 * @param driverService driver service instance
150 */ 225 */
151 public void start(OspfAgent ag, DriverService driverService) { 226 public void start(OspfAgent ag, DriverService driverService) {
152 - log.info("Starting OSPF Controller...!!!"); 227 + log.info("Starting OSPF controller...!!!");
153 this.agent = ag; 228 this.agent = ag;
154 this.driverService = driverService; 229 this.driverService = driverService;
155 this.init(); 230 this.init();
...@@ -159,615 +234,143 @@ public class Controller { ...@@ -159,615 +234,143 @@ public class Controller {
159 * Stops the Controller. 234 * Stops the Controller.
160 */ 235 */
161 public void stop() { 236 public void stop() {
162 - log.info("Stopping OSPF Controller...!!!"); 237 + log.info("Stopping OSPF controller...!!!");
163 - 238 + isisDeactivate();
164 - for (ChannelGroup cg : cgList) {
165 - cg.close();
166 - }
167 -
168 - for (NioServerSocketChannelFactory execFactory : execFactoryLst) {
169 - execFactory.shutdown();
170 - }
171 -
172 processes.clear(); 239 processes.clear();
173 } 240 }
174 241
175 /** 242 /**
176 - * Deletes configured interface from the area. 243 + * Returns interface IP by index.
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 * 244 *
276 - * @param ospfProcesses list of OSPF processes to create 245 + * @param interfaceIndex interface index
246 + * @return interface IP by index
277 */ 247 */
278 - private void createProcessWhenNoProcessesExists(List<OspfProcess> ospfProcesses) { 248 + private Ip4Address getInterfaceIp(int interfaceIndex) {
279 - Set<String> interfaceIpList = new HashSet<>(); 249 + Ip4Address ipAddress = null;
280 - Set<String> areaIdList = new HashSet<>(); 250 + try {
281 - if (processes != null) { 251 + NetworkInterface networkInterface = NetworkInterface.getByIndex(interfaceIndex);
282 - if (processes.size() == 0) { 252 + Enumeration ipAddresses = networkInterface.getInetAddresses();
283 - 253 + while (ipAddresses.hasMoreElements()) {
284 - processes.addAll(ospfProcesses); 254 + InetAddress address = (InetAddress) ipAddresses.nextElement();
285 - for (OspfProcess process : ospfProcesses) { 255 + if (!address.isLinkLocalAddress()) {
286 - for (OspfArea area : process.areas()) { 256 + ipAddress = Ip4Address.valueOf(address.getAddress());
287 - areaIdList.add(area.areaId().toString()); 257 + break;
288 - for (OspfInterface intrfc : area.getInterfacesLst()) {
289 - interfaceIpList.add(intrfc.ipAddress().toString());
290 - }
291 } 258 }
292 } 259 }
293 - createBootStrapForCreatedInterface(interfaceIpList, areaIdList); 260 + } catch (Exception e) {
261 + log.debug("Error while getting Interface IP by index");
262 + return OspfUtil.DEFAULTIP;
294 } 263 }
295 - } else {
296 - processes = new ArrayList<>();
297 - processes.addAll(ospfProcesses);
298 264
299 - for (OspfProcess process : ospfProcesses) { 265 + return ipAddress;
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 } 266 }
310 267
311 /** 268 /**
312 - * Creates processes when already process exist. 269 + * Returns interface mask by index.
313 - * It can be modifying existing process or adding a new process.
314 * 270 *
315 - * @param ospfProcesses list of processes 271 + * @param interfaceIndex interface index
272 + * @return interface IP by index
316 */ 273 */
317 - private void createProcessWhenProcessesExists(List<OspfProcess> ospfProcesses) { 274 + private String getInterfaceMask(int interfaceIndex) {
318 - if (ospfProcesses != null) { 275 + String subnetMask = null;
319 - for (OspfProcess process : ospfProcesses) { 276 + try {
320 - if (!checkProcess(process.processId())) { 277 + Ip4Address ipAddress = getInterfaceIp(interfaceIndex);
321 - createNewProcess(process.processId(), process); 278 + NetworkInterface networkInterface = NetworkInterface.getByInetAddress(
322 - } else { 279 + InetAddress.getByName(ipAddress.toString()));
323 - List<OspfArea> areas = process.areas(); 280 + Enumeration ipAddresses = networkInterface.getInetAddresses();
324 - for (OspfArea area : areas) { 281 + int index = 0;
325 - if (!checkArea(process.processId(), area.areaId().toString())) { 282 + while (ipAddresses.hasMoreElements()) {
326 - createAreaInProcess(process.processId(), 283 + InetAddress address = (InetAddress) ipAddresses.nextElement();
327 - area.areaId().toString(), area); 284 + if (!address.isLinkLocalAddress()) {
328 - } else { 285 + break;
329 - updateAreaInProcess(process.processId(), area.areaId().toString(), area); 286 + }
330 - for (OspfInterface interfc : area.getInterfacesLst()) { 287 + index++;
331 - if (!checkInterface(process.processId(), 288 + }
332 - area.areaId().toString(), interfc.ipAddress().toString())) { 289 + int prfLen = networkInterface.getInterfaceAddresses().get(index).getNetworkPrefixLength();
333 - createInterfaceInAreaInProcess(process.processId(), 290 + int shft = 0xffffffff << (32 - prfLen);
334 - area.areaId().toString(), interfc); 291 + int oct1 = ((byte) ((shft & 0xff000000) >> 24)) & 0xff;
335 - } else { 292 + int oct2 = ((byte) ((shft & 0x00ff0000) >> 16)) & 0xff;
336 - updateInterfaceParameters(process.processId(), 293 + int oct3 = ((byte) ((shft & 0x0000ff00) >> 8)) & 0xff;
337 - area.areaId().toString(), 294 + int oct4 = ((byte) (shft & 0x000000ff)) & 0xff;
338 - interfc.ipAddress().toString(), interfc); 295 + subnetMask = oct1 + "." + oct2 + "." + oct3 + "." + oct4;
339 - } 296 + } catch (Exception e) {
340 - } 297 + log.debug("Error while getting Interface network mask by index");
341 - } 298 + return subnetMask;
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 } 299 }
380 300
381 - /** 301 + return subnetMask;
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 } 302 }
398 303
399 /** 304 /**
400 - * Deletes configuration. 305 + * Disconnects the executor.
401 - *
402 - * @param ospfProcesses OSPF processes
403 - * @param attribute attribute to delete
404 */ 306 */
405 - public void deleteConfig(List<OspfProcess> ospfProcesses, String attribute) { 307 + public void disconnectExecutor() {
406 - log.info("Controller::UpdateConfig called"); 308 + if (connectExecutor != null) {
407 - if (processes != null) { 309 + connectExecutor.shutdown();
408 - if (processes.size() == 0) { 310 + connectExecutor = null;
409 - log.debug("DeleteConfig:: No process exists");
410 - } else {
411 - deleteProcessWhenExists(ospfProcesses, attribute);
412 - }
413 - } else {
414 - log.debug("DeleteConfig:: No process exists");
415 } 311 }
416 } 312 }
417 313
418 /** 314 /**
419 - * Creates a new process. 315 + * Connects to peer.
420 - *
421 - * @param processId process id
422 - * @param process OSPF process instance
423 */ 316 */
424 - private void createNewProcess(String processId, OspfProcess process) { 317 + public void connectPeer() {
425 - Set<String> interfaceIpList = new HashSet<>(); 318 + scheduleConnectionRetry(this.connectRetryTime);
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 } 319 }
441 320
442 /** 321 /**
443 - * Creates a new area information in the process. 322 + * Retry connection with exponential back-off mechanism.
444 * 323 *
445 - * @param processId process id 324 + * @param retryDelay retry delay
446 - * @param areaId area id
447 - * @param area OSPF area instance
448 */ 325 */
449 - private void createAreaInProcess(String processId, String areaId, OspfArea area) { 326 + private void scheduleConnectionRetry(long retryDelay) {
450 - Set<String> interfaceIpList = new HashSet<>(); 327 + if (this.connectExecutor == null) {
451 - Set<String> areaIdList = new HashSet<>(); 328 + this.connectExecutor = Executors.newSingleThreadScheduledExecutor();
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 } 329 }
469 - createBootStrapForCreatedInterface(interfaceIpList, areaIdList); 330 + this.connectExecutor.schedule(new ConnectionRetry(), retryDelay, TimeUnit.MINUTES);
470 - log.debug("createAreaInProcess:: all processes::{}", processes);
471 } 331 }
472 332
473 /** 333 /**
474 - * Creates an interface in the given area and process. 334 + * Implements ISIS connection and manages connection to peer with back-off mechanism in case of failure.
475 - *
476 - * @param processId process id
477 - * @param areaId area id
478 - * @param ospfInterface OSPF interface instance
479 */ 335 */
480 - private void createInterfaceInAreaInProcess(String processId, 336 + class ConnectionRetry implements Runnable {
481 - String areaId, OspfInterface ospfInterface) { 337 + @Override
482 - Set<String> interfaceIpList = new HashSet<>(); 338 + public void run() {
483 - Set<String> areaIdList = new HashSet<>(); 339 + log.debug("Connect to peer {}", OspfUtil.SHOST);
484 - 340 + initConnection();
485 - Iterator<OspfProcess> processItr = processes.iterator(); 341 + ospfChannelHandler.sentConfigPacket(configPacket);
486 - while (processItr.hasNext()) { 342 + InetSocketAddress connectToSocket = new InetSocketAddress(OspfUtil.SHOST, isisPort.toInt());
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 { 343 try {
598 - log.debug("Creating ServerBootstrap for {} @ {}", ipFromConfig, ospfPort); 344 + peerBootstrap.connect(connectToSocket).addListener(new ChannelFutureListener() {
599 - 345 + @Override
600 - final ServerBootstrap bootstrap = createServerBootStrap(); 346 + public void operationComplete(ChannelFuture future) throws Exception {
601 - 347 + if (!future.isSuccess()) {
602 - bootstrap.setOption("receiveBufferSize", Controller.BUFFER_SIZE); 348 + connectRetryCounter++;
603 - bootstrap.setOption("receiveBufferSizePredictorFactory", 349 + log.error("Connection failed, ConnectRetryCounter {} remote host {}", connectRetryCounter,
604 - new FixedReceiveBufferSizePredictorFactory( 350 + OspfUtil.SHOST);
605 - Controller.BUFFER_SIZE)); 351 + /*
606 - bootstrap.setOption("reuseAddress", true); 352 + * Reconnect to peer on failure is exponential till 4 mins, later on retry after every 4
607 - bootstrap.setOption("tcpNoDelay", true); 353 + * mins.
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 */ 354 */
720 - private void deleteAreaFromProcess(String processId, String areaId, OspfArea area) { 355 + if (connectRetryTime < RETRY_INTERVAL) {
721 - if (processes != null) { 356 + connectRetryTime = (connectRetryTime != 0) ? connectRetryTime * 2 : 1;
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 } 357 }
358 + scheduleConnectionRetry(connectRetryTime);
359 + } else {
360 + //Send the config packet
361 + ospfChannelHandler.sentConfigPacket(configPacket);
362 + connectRetryCounter++;
363 + log.info("Connected to remote host {}, Connect Counter {}", OspfUtil.SHOST,
364 + connectRetryCounter);
365 + disconnectExecutor();
739 366
740 - /** 367 + return;
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 } 368 }
770 } 369 }
370 + });
371 + } catch (Exception e) {
372 + log.info("Connect peer exception : " + e.toString());
373 + disconnectExecutor();
771 } 374 }
772 } 375 }
773 } 376 }
......
1 +/*
2 + * Copyright 2016-present 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 com.fasterxml.jackson.databind.JsonNode;
19 +import org.onlab.packet.Ip4Address;
20 +import org.onosproject.ospf.controller.OspfArea;
21 +import org.onosproject.ospf.controller.OspfInterface;
22 +import org.onosproject.ospf.controller.OspfProcess;
23 +import org.onosproject.ospf.controller.area.OspfAreaImpl;
24 +import org.onosproject.ospf.controller.area.OspfInterfaceImpl;
25 +import org.onosproject.ospf.controller.area.OspfProcessImpl;
26 +import org.onosproject.ospf.protocol.util.OspfUtil;
27 +import org.slf4j.Logger;
28 +import org.slf4j.LoggerFactory;
29 +
30 +import java.net.InetAddress;
31 +import java.net.NetworkInterface;
32 +import java.util.ArrayList;
33 +import java.util.Enumeration;
34 +import java.util.List;
35 +
36 +/**
37 + * Representation of OSPF network configuration parsing util.
38 + */
39 +public final class OspfConfigUtil {
40 + public static final String PROCESSID = "processId";
41 + public static final String AREAS = "areas";
42 + public static final String INTERFACEINDEX = "interfaceIndex";
43 + public static final String AREAID = "areaId";
44 + public static final String ROUTERID = "routerId";
45 + public static final String INTERFACE = "interface";
46 + public static final String HELLOINTERVAL = "helloIntervalTime";
47 + public static final String ROUTERDEADINTERVAL = "routerDeadIntervalTime";
48 + public static final String INTERFACETYPE = "interfaceType";
49 + public static final String EXTERNALROUTINGCAPABILITY = "externalRoutingCapability";
50 + protected static final Logger log = LoggerFactory.getLogger(OspfConfigUtil.class);
51 + private static final String ISOPAQUE = "isOpaqueEnable";
52 +
53 + /**
54 + * Creates an instance of this.
55 + */
56 + private OspfConfigUtil() {
57 +
58 + }
59 +
60 + /**
61 + * Returns list of OSPF process from the json nodes.
62 + *
63 + * @param jsonNodes json node instance
64 + * @return list of OSPF processes.
65 + */
66 + public static List<OspfProcess> processes(JsonNode jsonNodes) {
67 + List<OspfProcess> ospfProcesses = new ArrayList<>();
68 + if (jsonNodes == null) {
69 + return ospfProcesses;
70 + }
71 + jsonNodes.forEach(jsonNode -> {
72 + List<OspfArea> areas = new ArrayList<>();
73 + for (JsonNode areaNode : jsonNode.path(AREAS)) {
74 + List<OspfInterface> interfaceList = new ArrayList<>();
75 + for (JsonNode interfaceNode : areaNode.path(INTERFACE)) {
76 + OspfInterface ospfInterface = new OspfInterfaceImpl();
77 + String index = interfaceNode.path(INTERFACEINDEX).asText();
78 + if (isValidDigit(index)) {
79 + ospfInterface.setInterfaceIndex(Integer.parseInt(index));
80 + } else {
81 + log.debug("Wrong interface index: {}", index);
82 + continue;
83 + }
84 + ospfInterface.setIpAddress(getInterfaceIp(ospfInterface.interfaceIndex()));
85 + ospfInterface.setIpNetworkMask(Ip4Address.valueOf(getInterfaceMask(
86 + ospfInterface.interfaceIndex())));
87 + ospfInterface.setBdr(OspfUtil.DEFAULTIP);
88 + ospfInterface.setDr(OspfUtil.DEFAULTIP);
89 + String helloInterval = interfaceNode.path(HELLOINTERVAL).asText();
90 + if (isValidDigit(helloInterval)) {
91 + ospfInterface.setHelloIntervalTime(Integer.parseInt(helloInterval));
92 + } else {
93 + log.debug("Wrong hello interval: {}", helloInterval);
94 + continue;
95 + }
96 + String routerDeadInterval = interfaceNode.path(ROUTERDEADINTERVAL).asText();
97 + if (isValidDigit(routerDeadInterval)) {
98 + ospfInterface.setRouterDeadIntervalTime(Integer.parseInt(routerDeadInterval));
99 + } else {
100 + log.debug("Wrong routerDeadInterval: {}", routerDeadInterval);
101 + continue;
102 + }
103 + String interfaceType = interfaceNode.path(INTERFACETYPE).asText();
104 + if (isValidDigit(interfaceType)) {
105 + ospfInterface.setInterfaceType(Integer.parseInt(interfaceType));
106 + } else {
107 + log.debug("Wrong interfaceType: {}", interfaceType);
108 + continue;
109 + }
110 + ospfInterface.setReTransmitInterval(OspfUtil.RETRANSMITINTERVAL);
111 + ospfInterface.setMtu(OspfUtil.MTU);
112 + ospfInterface.setRouterPriority(OspfUtil.ROUTER_PRIORITY);
113 + interfaceList.add(ospfInterface);
114 + }
115 + OspfArea area = new OspfAreaImpl();
116 + String areaId = areaNode.path(AREAID).asText();
117 + if (isValidIpAddress(areaId)) {
118 + area.setAreaId(Ip4Address.valueOf(areaId));
119 + } else {
120 + log.debug("Wrong areaId: {}", areaId);
121 + continue;
122 + }
123 + String routerId = areaNode.path(ROUTERID).asText();
124 + if (isValidIpAddress(routerId)) {
125 + area.setRouterId(Ip4Address.valueOf(routerId));
126 + } else {
127 + log.debug("Wrong routerId: {}", routerId);
128 + continue;
129 + }
130 + String routingCapability = areaNode.path(EXTERNALROUTINGCAPABILITY).asText();
131 + if (isBoolean(routingCapability)) {
132 + area.setExternalRoutingCapability(Boolean.valueOf(routingCapability));
133 + } else {
134 + log.debug("Wrong routingCapability: {}", routingCapability);
135 + continue;
136 + }
137 + String isOpaqueEnabled = areaNode.path(ISOPAQUE).asText();
138 + if (isBoolean(isOpaqueEnabled)) {
139 + area.setIsOpaqueEnabled(Boolean.valueOf(isOpaqueEnabled));
140 + } else {
141 + log.debug("Wrong isOpaqueEnabled: {}", isOpaqueEnabled);
142 + continue;
143 + }
144 + area.setOptions(OspfUtil.HELLO_PACKET_OPTIONS);
145 + area.setOspfInterfaceList(interfaceList);
146 + areas.add(area);
147 + }
148 + OspfProcess process = new OspfProcessImpl();
149 + process.setProcessId(jsonNode.path(PROCESSID).asText());
150 + process.setAreas(areas);
151 + ospfProcesses.add(process);
152 + });
153 +
154 + return ospfProcesses;
155 + }
156 +
157 + /**
158 + * Returns interface IP by index.
159 + *
160 + * @param interfaceIndex interface index
161 + * @return interface IP by index
162 + */
163 + private static Ip4Address getInterfaceIp(int interfaceIndex) {
164 + Ip4Address ipAddress = null;
165 + try {
166 + NetworkInterface networkInterface = NetworkInterface.getByIndex(interfaceIndex);
167 + Enumeration ipAddresses = networkInterface.getInetAddresses();
168 + while (ipAddresses.hasMoreElements()) {
169 + InetAddress address = (InetAddress) ipAddresses.nextElement();
170 + if (!address.isLinkLocalAddress()) {
171 + ipAddress = Ip4Address.valueOf(address.getAddress());
172 + break;
173 + }
174 + }
175 + } catch (Exception e) {
176 + log.debug("Error while getting Interface IP by index");
177 + return OspfUtil.DEFAULTIP;
178 + }
179 + return ipAddress;
180 + }
181 +
182 + /**
183 + * Returns interface MAC by index.
184 + *
185 + * @param interfaceIndex interface index
186 + * @return interface IP by index
187 + */
188 + private static String getInterfaceMask(int interfaceIndex) {
189 + String subnetMask = null;
190 + try {
191 + Ip4Address ipAddress = getInterfaceIp(interfaceIndex);
192 + NetworkInterface networkInterface = NetworkInterface.getByInetAddress(
193 + InetAddress.getByName(ipAddress.toString()));
194 + Enumeration ipAddresses = networkInterface.getInetAddresses();
195 + int index = 0;
196 + while (ipAddresses.hasMoreElements()) {
197 + InetAddress address = (InetAddress) ipAddresses.nextElement();
198 + if (!address.isLinkLocalAddress()) {
199 + break;
200 + }
201 + index++;
202 + }
203 + int prfLen = networkInterface.getInterfaceAddresses().get(index).getNetworkPrefixLength();
204 + int shft = 0xffffffff << (32 - prfLen);
205 + int oct1 = ((byte) ((shft & 0xff000000) >> 24)) & 0xff;
206 + int oct2 = ((byte) ((shft & 0x00ff0000) >> 16)) & 0xff;
207 + int oct3 = ((byte) ((shft & 0x0000ff00) >> 8)) & 0xff;
208 + int oct4 = ((byte) (shft & 0x000000ff)) & 0xff;
209 + subnetMask = oct1 + "." + oct2 + "." + oct3 + "." + oct4;
210 + } catch (Exception e) {
211 + log.debug("Error while getting Interface network mask by index");
212 + return subnetMask;
213 + }
214 + return subnetMask;
215 + }
216 +
217 + /**
218 + * Checks if valid digit or not.
219 + *
220 + * @param strInput input value
221 + * @return true if valid else false
222 + */
223 + private static boolean isValidDigit(String strInput) {
224 + boolean isValid = true;
225 + if (isPrimitive(strInput)) {
226 + int input = Integer.parseInt(strInput);
227 + if (input < 1 || input > 255) {
228 + log.debug("Wrong config input value: {}", strInput);
229 + isValid = false;
230 + } else {
231 + isValid = true;
232 + }
233 +
234 + } else {
235 + isValid = false;
236 + }
237 +
238 + return isValid;
239 + }
240 +
241 + /**
242 + * Checks if primitive or not.
243 + *
244 + * @param value input value
245 + * @return true if number else false
246 + */
247 + private static boolean isPrimitive(String value) {
248 + boolean status = true;
249 + value = value.trim();
250 + if (value.length() < 1) {
251 + return false;
252 + }
253 + for (int i = 0; i < value.length(); i++) {
254 + char c = value.charAt(i);
255 + if (!Character.isDigit(c)) {
256 + status = false;
257 + break;
258 + }
259 + }
260 +
261 + return status;
262 + }
263 +
264 + /**
265 + * Checks if boolean or not.
266 + *
267 + * @param value input value
268 + * @return true if boolean else false
269 + */
270 + private static boolean isBoolean(String value) {
271 + boolean status = false;
272 + value = value.trim();
273 + if (value.equals("true") || value.equals("false")) {
274 + return true;
275 + }
276 +
277 + return status;
278 + }
279 +
280 + /**
281 + * Checks if given id is valid or not.
282 + *
283 + * @param value input value
284 + * @return true if valid else false
285 + */
286 + private static boolean isValidIpAddress(String value) {
287 + boolean status = true;
288 + try {
289 + Ip4Address ipAddress = Ip4Address.valueOf(value);
290 + } catch (Exception e) {
291 + log.debug("Invalid IP address string: {}", value);
292 + return false;
293 + }
294 +
295 + return status;
296 + }
297 +}
...\ No newline at end of file ...\ No newline at end of file
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 16
17 package org.onosproject.ospf.controller.impl; 17 package org.onosproject.ospf.controller.impl;
18 18
19 +import com.fasterxml.jackson.databind.JsonNode;
19 import com.google.common.collect.Sets; 20 import com.google.common.collect.Sets;
20 import org.apache.felix.scr.annotations.Activate; 21 import org.apache.felix.scr.annotations.Activate;
21 import org.apache.felix.scr.annotations.Component; 22 import org.apache.felix.scr.annotations.Component;
...@@ -34,7 +35,6 @@ import org.onosproject.ospf.controller.OspfRouterListener; ...@@ -34,7 +35,6 @@ import org.onosproject.ospf.controller.OspfRouterListener;
34 import org.slf4j.Logger; 35 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory; 36 import org.slf4j.LoggerFactory;
36 37
37 -import java.util.ArrayList;
38 import java.util.HashSet; 38 import java.util.HashSet;
39 import java.util.List; 39 import java.util.List;
40 import java.util.Set; 40 import java.util.Set;
...@@ -111,27 +111,23 @@ public class OspfControllerImpl implements OspfController { ...@@ -111,27 +111,23 @@ public class OspfControllerImpl implements OspfController {
111 } 111 }
112 112
113 @Override 113 @Override
114 - public void updateConfig(List processes) { 114 + public void updateConfig(JsonNode processesNode) {
115 - List<OspfProcess> ospfProcesses = new ArrayList<>(); 115 + try {
116 - if (processes != null) { 116 + List<OspfProcess> ospfProcesses = OspfConfigUtil.processes(processesNode);
117 - for (Object process : processes) { 117 + //if there is interface details then update configuration
118 - ospfProcesses.add((OspfProcess) process); 118 + if (ospfProcesses.size() > 0 &&
119 + ospfProcesses.get(0).areas() != null && ospfProcesses.get(0).areas().size() > 0 &&
120 + ospfProcesses.get(0).areas().get(0) != null &&
121 + ospfProcesses.get(0).areas().get(0).ospfInterfaceList().size() > 0) {
122 + ctrl.updateConfig(ospfProcesses);
119 } 123 }
124 + } catch (Exception e) {
125 + log.debug("Error::updateConfig::{}", e.getMessage());
120 } 126 }
121 - log.debug("updateConfig::OspfList::processes::{}", ospfProcesses);
122 - ctrl.updateConfig(ospfProcesses);
123 } 127 }
124 128
125 @Override 129 @Override
126 public void deleteConfig(List<OspfProcess> processes, String attribute) { 130 public void deleteConfig(List<OspfProcess> processes, String attribute) {
127 - List<OspfProcess> ospfProcesses = new ArrayList<>();
128 - if (processes != null) {
129 - for (Object process : processes) {
130 - ospfProcesses.add((OspfProcess) process);
131 - }
132 - }
133 - log.debug("deleteConfig::OspfList::processes::{}", ospfProcesses);
134 - ctrl.deleteConfig(ospfProcesses, attribute);
135 } 131 }
136 132
137 /** 133 /**
...@@ -163,9 +159,9 @@ public class OspfControllerImpl implements OspfController { ...@@ -163,9 +159,9 @@ public class OspfControllerImpl implements OspfController {
163 } 159 }
164 160
165 @Override 161 @Override
166 - public void deleteLink(OspfRouter ospfRouter) { 162 + public void deleteLink(OspfRouter ospfRouter, OspfLinkTed ospfLinkTed) {
167 for (OspfLinkListener l : linkListener()) { 163 for (OspfLinkListener l : linkListener()) {
168 - l.deleteLink(ospfRouter); 164 + l.deleteLink(ospfRouter, ospfLinkTed);
169 } 165 }
170 } 166 }
171 } 167 }
......
...@@ -13,13 +13,9 @@ ...@@ -13,13 +13,9 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 -
17 package org.onosproject.ospf.controller.impl; 16 package org.onosproject.ospf.controller.impl;
18 17
19 -import org.apache.felix.scr.annotations.Reference;
20 -import org.apache.felix.scr.annotations.ReferenceCardinality;
21 import org.jboss.netty.channel.Channel; 18 import org.jboss.netty.channel.Channel;
22 -import org.jboss.netty.channel.ChannelFuture;
23 import org.jboss.netty.channel.ChannelHandlerContext; 19 import org.jboss.netty.channel.ChannelHandlerContext;
24 import org.jboss.netty.channel.ChannelStateEvent; 20 import org.jboss.netty.channel.ChannelStateEvent;
25 import org.jboss.netty.channel.ExceptionEvent; 21 import org.jboss.netty.channel.ExceptionEvent;
...@@ -27,235 +23,203 @@ import org.jboss.netty.channel.MessageEvent; ...@@ -27,235 +23,203 @@ import org.jboss.netty.channel.MessageEvent;
27 import org.jboss.netty.handler.timeout.IdleStateAwareChannelHandler; 23 import org.jboss.netty.handler.timeout.IdleStateAwareChannelHandler;
28 import org.jboss.netty.handler.timeout.ReadTimeoutException; 24 import org.jboss.netty.handler.timeout.ReadTimeoutException;
29 import org.onlab.packet.Ip4Address; 25 import org.onlab.packet.Ip4Address;
30 -import org.onosproject.ospf.controller.LsaWrapper;
31 import org.onosproject.ospf.controller.OspfArea; 26 import org.onosproject.ospf.controller.OspfArea;
32 import org.onosproject.ospf.controller.OspfInterface; 27 import org.onosproject.ospf.controller.OspfInterface;
33 -import org.onosproject.ospf.controller.OspfLinkTed; 28 +import org.onosproject.ospf.controller.OspfMessage;
34 -import org.onosproject.ospf.controller.OspfLsa;
35 import org.onosproject.ospf.controller.OspfNbr; 29 import org.onosproject.ospf.controller.OspfNbr;
36 -import org.onosproject.ospf.controller.OspfNeighborState; 30 +import org.onosproject.ospf.controller.OspfProcess;
37 -import org.onosproject.ospf.controller.OspfRouter;
38 -import org.onosproject.ospf.controller.TopologyForDeviceAndLink;
39 -import org.onosproject.ospf.controller.area.OspfAreaImpl;
40 import org.onosproject.ospf.controller.area.OspfInterfaceImpl; 31 import org.onosproject.ospf.controller.area.OspfInterfaceImpl;
41 -import org.onosproject.ospf.controller.lsdb.LsaWrapperImpl;
42 -import org.onosproject.ospf.controller.lsdb.OspfLsdbImpl;
43 -import org.onosproject.ospf.controller.util.OspfEligibleRouter;
44 import org.onosproject.ospf.controller.util.OspfInterfaceType; 32 import org.onosproject.ospf.controller.util.OspfInterfaceType;
45 import org.onosproject.ospf.exceptions.OspfParseException; 33 import org.onosproject.ospf.exceptions.OspfParseException;
46 -import org.onosproject.ospf.protocol.lsa.LsaHeader;
47 -import org.onosproject.ospf.protocol.ospfpacket.OspfMessage;
48 -import org.onosproject.ospf.protocol.ospfpacket.OspfPacketHeader;
49 -import org.onosproject.ospf.protocol.ospfpacket.subtype.LsRequestPacket;
50 -import org.onosproject.ospf.protocol.ospfpacket.types.DdPacket;
51 -import org.onosproject.ospf.protocol.ospfpacket.types.HelloPacket;
52 -import org.onosproject.ospf.protocol.ospfpacket.types.LsAcknowledge;
53 -import org.onosproject.ospf.protocol.ospfpacket.types.LsRequest;
54 -import org.onosproject.ospf.protocol.ospfpacket.types.LsUpdate;
55 -import org.onosproject.ospf.protocol.util.ChecksumCalculator;
56 import org.onosproject.ospf.protocol.util.OspfInterfaceState; 34 import org.onosproject.ospf.protocol.util.OspfInterfaceState;
57 -import org.onosproject.ospf.protocol.util.OspfPacketType;
58 -import org.onosproject.ospf.protocol.util.OspfParameters;
59 -import org.onosproject.ospf.protocol.util.OspfUtil;
60 import org.slf4j.Logger; 35 import org.slf4j.Logger;
61 import org.slf4j.LoggerFactory; 36 import org.slf4j.LoggerFactory;
62 37
63 import java.io.IOException; 38 import java.io.IOException;
64 import java.nio.channels.ClosedChannelException; 39 import java.nio.channels.ClosedChannelException;
65 -import java.util.ArrayList;
66 -import java.util.HashMap;
67 -import java.util.Iterator;
68 import java.util.List; 40 import java.util.List;
69 -import java.util.ListIterator; 41 +import java.util.Map;
70 -import java.util.Set; 42 +import java.util.concurrent.ConcurrentHashMap;
71 -import java.util.concurrent.Executors;
72 import java.util.concurrent.RejectedExecutionException; 43 import java.util.concurrent.RejectedExecutionException;
73 -import java.util.concurrent.ScheduledExecutorService;
74 -import java.util.concurrent.ScheduledFuture;
75 -import java.util.concurrent.TimeUnit;
76 44
77 /** 45 /**
78 * Channel handler deals with the OSPF channel connection. 46 * Channel handler deals with the OSPF channel connection.
79 - * Also it dispatches messages to the appropriate handlers. 47 + * Also it dispatches messages to the appropriate handlers for processing.
80 */ 48 */
81 public class OspfInterfaceChannelHandler extends IdleStateAwareChannelHandler { 49 public class OspfInterfaceChannelHandler extends IdleStateAwareChannelHandler {
82 50
83 - private static final Logger log = 51 + private static final Logger log = LoggerFactory.getLogger(OspfInterfaceChannelHandler.class);
84 - LoggerFactory.getLogger(OspfInterfaceChannelHandler.class); 52 + private static Map<Integer, Object> isisDb = null;
85 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 53 + private Channel channel = null;
86 - private OspfInterface ospfInterface;
87 - private OspfArea ospfArea;
88 - private boolean isClosed = false;
89 private Controller controller; 54 private Controller controller;
90 - private Channel channel; 55 + private List<OspfProcess> processes = null;
91 - private long delay = 0; 56 + private byte[] configPacket = null;
92 - private InternalHelloTimer helloTimerTask; 57 + private Map<Integer, OspfInterface> ospfInterfaceMap = new ConcurrentHashMap<>();
93 - private InternalWaitTimer waitTimerTask;
94 - private InternalDelayedAckTimer delayedAckTimerTask;
95 - private ScheduledExecutorService exServiceHello;
96 - private ScheduledExecutorService exServiceWait;
97 - private ScheduledExecutorService exServiceDelayedAck;
98 - private boolean isDelayedAckTimerScheduled = false;
99 - private int delayedAckTimerInterval = 2500;
100 - private TopologyForDeviceAndLink topologyForDeviceAndLink;
101 -
102 - public OspfInterfaceChannelHandler() {
103 -
104 - }
105 58
106 /** 59 /**
107 * Creates an instance of OSPF channel handler. 60 * Creates an instance of OSPF channel handler.
108 * 61 *
109 * @param controller controller instance 62 * @param controller controller instance
110 - * @param ospfArea ospf area instance 63 + * @param processes list of configured processes
111 - * @param ospfInterface ospf interface instance
112 */ 64 */
113 - public OspfInterfaceChannelHandler(Controller controller, OspfArea ospfArea, OspfInterface ospfInterface) { 65 + public OspfInterfaceChannelHandler(Controller controller, List<OspfProcess> processes) {
114 -
115 - this.ospfArea = ospfArea;
116 - this.ospfInterface = ospfInterface;
117 this.controller = controller; 66 this.controller = controller;
118 - ((OspfInterfaceImpl) ospfInterface).setState(OspfInterfaceState.DOWN); 67 + this.processes = processes;
119 - this.ospfInterface.setDr(Ip4Address.valueOf("0.0.0.0"));
120 - this.ospfInterface.setBdr(Ip4Address.valueOf("0.0.0.0"));
121 - this.topologyForDeviceAndLink = new TopologyForDeviceAndLinkImpl();
122 } 68 }
123 69
124 /** 70 /**
125 - * Represents an interface is up and connected. 71 + * Initializes the interface map with interface details.
126 * 72 *
127 * @throws Exception might throws exception 73 * @throws Exception might throws exception
128 */ 74 */
129 - public void interfaceUp() throws Exception { 75 + public void initializeInterfaceMap() throws Exception {
130 - log.debug("OSPFInterfaceChannelHandler::interfaceUp...!!!"); 76 + for (OspfProcess process : processes) {
131 - if (ospfInterface.interfaceType() == OspfInterfaceType.POINT_TO_POINT.value()) { 77 + for (OspfArea area : process.areas()) {
132 - ((OspfInterfaceImpl) ospfInterface).setState(OspfInterfaceState.POINT2POINT); 78 + for (OspfInterface ospfInterface : area.ospfInterfaceList()) {
133 - log.debug("OSPFInterfaceChannelHandler::InterfaceType {} state {} ", 79 + OspfInterface anInterface = ospfInterfaceMap.get(ospfInterface.interfaceIndex());
134 - ospfInterface.interfaceType(), ((OspfInterfaceImpl) ospfInterface).state()); 80 + if (anInterface == null) {
135 - } else if (ospfInterface.interfaceType() == OspfInterfaceType.BROADCAST.value()) { 81 + ospfInterface.setOspfArea(area);
136 - //if router priority is 0, move the state to DROther 82 + ((OspfInterfaceImpl) ospfInterface).setController(controller);
137 - if (ospfInterface.routerPriority() == 0) { 83 + ((OspfInterfaceImpl) ospfInterface).setState(OspfInterfaceState.DOWN);
138 - ((OspfInterfaceImpl) ospfInterface).setState(OspfInterfaceState.DROTHER); 84 + ospfInterface.setDr(Ip4Address.valueOf("0.0.0.0"));
139 - } else { 85 + ospfInterface.setBdr(Ip4Address.valueOf("0.0.0.0"));
140 - log.debug("OSPFInterfaceChannelHandler::InterfaceType {} state {} RouterPriority {}", 86 + ospfInterfaceMap.put(ospfInterface.interfaceIndex(), ospfInterface);
141 - ospfInterface.interfaceType(),
142 - ((OspfInterfaceImpl) ospfInterface).state(), ospfInterface.routerPriority());
143 - ((OspfInterfaceImpl) ospfInterface).setState(OspfInterfaceState.WAITING);
144 - //start wait timer - like inactivity timer with router deadInterval
145 - startWaitTimer();
146 } 87 }
147 - 88 + ((OspfInterfaceImpl) ospfInterface).setChannel(channel);
89 + ospfInterface.interfaceUp();
90 + ospfInterface.startDelayedAckTimer();
148 } 91 }
149 - // Start hello timer with interval from config - convert seconds to milliseconds 92 + //Initialize the LSDB and aging process
150 - startHelloTimer(ospfInterface.helloIntervalTime()); 93 + area.initializeDb();
151 - ospfArea.refreshArea(ospfInterface);
152 } 94 }
153 -
154 -
155 - /**
156 - * Gets called when a BDR was detected before the wait timer expired.
157 - *
158 - * @param ch channel instance
159 - * @throws Exception might throws exception
160 - */
161 - public void backupSeen(Channel ch) throws Exception {
162 - log.debug("OSPFInterfaceChannelHandler::backupSeen ");
163 - if (((OspfInterfaceImpl) ospfInterface).state() == OspfInterfaceState.WAITING) {
164 - electRouter(ch);
165 } 95 }
166 } 96 }
167 97
168 /** 98 /**
169 - * Gets called when no hello message received for particular period. 99 + * Updates the interface map with interface details.
170 * 100 *
171 - * @param ch channel instance 101 + * @param ospfProcesses updated process instances
172 * @throws Exception might throws exception 102 * @throws Exception might throws exception
173 */ 103 */
174 - public void waitTimer(Channel ch) throws Exception { 104 + public void updateInterfaceMap(List<OspfProcess> ospfProcesses) throws Exception {
175 - log.debug("OSPFInterfaceChannelHandler::waitTimer "); 105 + for (OspfProcess ospfUpdatedProcess : ospfProcesses) {
176 - //section 9.4 106 + for (OspfArea updatedArea : ospfUpdatedProcess.areas()) {
177 - if (((OspfInterfaceImpl) ospfInterface).state() == OspfInterfaceState.WAITING) { 107 + for (OspfInterface ospfUpdatedInterface : updatedArea.ospfInterfaceList()) {
178 - electRouter(ch); 108 + OspfInterface ospfInterface = ospfInterfaceMap.get(ospfUpdatedInterface.interfaceIndex());
109 + if (ospfInterface == null) {
110 + ospfUpdatedInterface.setOspfArea(updatedArea);
111 + ((OspfInterfaceImpl) ospfUpdatedInterface).setController(controller);
112 + ((OspfInterfaceImpl) ospfUpdatedInterface).setState(OspfInterfaceState.DOWN);
113 + ospfUpdatedInterface.setDr(Ip4Address.valueOf("0.0.0.0"));
114 + ospfUpdatedInterface.setBdr(Ip4Address.valueOf("0.0.0.0"));
115 + ospfInterfaceMap.put(ospfUpdatedInterface.interfaceIndex(), ospfUpdatedInterface);
116 + ((OspfInterfaceImpl) ospfUpdatedInterface).setChannel(channel);
117 + ospfUpdatedInterface.interfaceUp();
118 + ospfUpdatedInterface.startDelayedAckTimer();
119 + } else {
120 + ospfInterface.setOspfArea(updatedArea);
121 +
122 + if (ospfInterface.routerDeadIntervalTime() != ospfUpdatedInterface.routerDeadIntervalTime()) {
123 + ospfInterface.setRouterDeadIntervalTime(ospfUpdatedInterface.routerDeadIntervalTime());
124 + Map<String, OspfNbr> neighbors = ospfInterface.listOfNeighbors();
125 + for (String key : neighbors.keySet()) {
126 + OspfNbr ospfNbr = ospfInterface.neighbouringRouter(key);
127 + ospfNbr.setRouterDeadInterval(ospfInterface.routerDeadIntervalTime());
128 + ospfNbr.stopInactivityTimeCheck();
129 + ospfNbr.startInactivityTimeCheck();
130 + }
131 + }
132 + if (ospfInterface.interfaceType() != ospfUpdatedInterface.interfaceType()) {
133 + ospfInterface.setInterfaceType(ospfUpdatedInterface.interfaceType());
134 + if (ospfInterface.interfaceType() == OspfInterfaceType.POINT_TO_POINT.value()) {
135 + ospfInterface.setDr(Ip4Address.valueOf("0.0.0.0"));
136 + ospfInterface.setBdr(Ip4Address.valueOf("0.0.0.0"));
137 + }
138 + ospfInterface.removeNeighbors();
139 + }
140 + if (ospfInterface.helloIntervalTime() != ospfUpdatedInterface.helloIntervalTime()) {
141 + ospfInterface.setHelloIntervalTime(ospfUpdatedInterface.helloIntervalTime());
142 + ospfInterface.stopHelloTimer();
143 + ospfInterface.startHelloTimer();
144 + }
145 + ospfInterfaceMap.put(ospfInterface.interfaceIndex(), ospfInterface);
146 + }
179 } 147 }
180 } 148 }
181 -
182 - /**
183 - * Neighbor change event is triggered when the router priority gets changed.
184 - *
185 - * @throws Exception might throws exception
186 - */
187 - public void neighborChange() throws Exception {
188 - log.debug("OSPFInterfaceChannelHandler::neighborChange ");
189 - if (((OspfInterfaceImpl) ospfInterface).state() == OspfInterfaceState.DR ||
190 - ((OspfInterfaceImpl) ospfInterface).state() == OspfInterfaceState.BDR ||
191 - ((OspfInterfaceImpl) ospfInterface).state() == OspfInterfaceState.DROTHER) {
192 - electRouter(channel);
193 } 149 }
194 } 150 }
195 151
196 /** 152 /**
197 - * Gets called when an interface is down. 153 + * Initialize channel, start hello sender and initialize LSDB.
198 - * All interface variables are reset, and interface timers disabled.
199 - * Also all neighbor connections associated with the interface are destroyed.
200 */ 154 */
201 - public void interfaceDown() { 155 + private void initialize() throws Exception {
202 - log.debug("OSPFInterfaceChannelHandler::interfaceDown "); 156 + log.debug("OspfChannelHandler initialize..!!!");
203 - stopHelloTimer(); 157 + if (configPacket != null) {
204 - ospfInterface.listOfNeighbors().clear(); 158 + log.debug("OspfChannelHandler initialize -> sentConfig packet of length ::"
205 - ((OspfInterfaceImpl) ospfInterface).setState(OspfInterfaceState.DOWN); 159 + + configPacket.length);
160 + sentConfigPacket(configPacket);
161 + }
162 + initializeInterfaceMap();
206 } 163 }
207 164
208 @Override 165 @Override
209 public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent evt) throws Exception { 166 public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent evt) throws Exception {
210 log.info("OSPF channelConnected from {}", evt.getChannel().getRemoteAddress()); 167 log.info("OSPF channelConnected from {}", evt.getChannel().getRemoteAddress());
211 - channel = evt.getChannel(); 168 + this.channel = evt.getChannel();
212 - interfaceUp(); 169 + initialize();
213 - startDelayedAckTimer();
214 } 170 }
215 171
216 @Override 172 @Override
217 public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent evt) { 173 public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent evt) {
218 - interfaceDown();
219 - stopDelayedAckTimer();
220 log.debug("OspfChannelHandler::channelDisconnected...!!!"); 174 log.debug("OspfChannelHandler::channelDisconnected...!!!");
175 +
176 + for (Integer interfaceIndex : ospfInterfaceMap.keySet()) {
177 + OspfInterface anInterface = ospfInterfaceMap.get(interfaceIndex);
178 + if (anInterface != null) {
179 + anInterface.interfaceDown();
180 + anInterface.stopDelayedAckTimer();
181 + }
182 + }
183 +
184 + if (controller != null) {
185 + controller.connectPeer();
186 + }
221 } 187 }
222 188
223 @Override 189 @Override
224 - public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception { 190 + public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent
225 - log.info("[exceptionCaught]: " + e.toString()); 191 + e) throws Exception {
192 + log.debug("[exceptionCaught]: " + e.toString());
226 if (e.getCause() instanceof ReadTimeoutException) { 193 if (e.getCause() instanceof ReadTimeoutException) {
227 - // device timeout 194 + log.debug("Disconnecting device {} due to read timeout", e.getChannel().getRemoteAddress());
228 - log.error("Disconnecting device {} due to read timeout", e.getChannel().getRemoteAddress());
229 return; 195 return;
230 } else if (e.getCause() instanceof ClosedChannelException) { 196 } else if (e.getCause() instanceof ClosedChannelException) {
231 log.debug("Channel for OSPF {} already closed", e.getChannel().getRemoteAddress()); 197 log.debug("Channel for OSPF {} already closed", e.getChannel().getRemoteAddress());
232 } else if (e.getCause() instanceof IOException) { 198 } else if (e.getCause() instanceof IOException) {
233 - log.error("Disconnecting OSPF {} due to IO Error: {}", e.getChannel().getRemoteAddress(), 199 + log.debug("Disconnecting OSPF {} due to IO Error: {}", e.getChannel().getRemoteAddress(),
234 e.getCause().getMessage()); 200 e.getCause().getMessage());
235 - if (log.isDebugEnabled()) {
236 - log.debug("StackTrace for previous Exception: {}", e.getCause());
237 - }
238 } else if (e.getCause() instanceof OspfParseException) { 201 } else if (e.getCause() instanceof OspfParseException) {
239 OspfParseException errMsg = (OspfParseException) e.getCause(); 202 OspfParseException errMsg = (OspfParseException) e.getCause();
240 byte errorCode = errMsg.errorCode(); 203 byte errorCode = errMsg.errorCode();
241 byte errorSubCode = errMsg.errorSubCode(); 204 byte errorSubCode = errMsg.errorSubCode();
242 - log.error("Error while parsing message from OSPF {}, ErrorCode {}", 205 + log.debug("Error while parsing message from OSPF {}, ErrorCode {}",
243 e.getChannel().getRemoteAddress(), errorCode); 206 e.getChannel().getRemoteAddress(), errorCode);
244 } else if (e.getCause() instanceof RejectedExecutionException) { 207 } else if (e.getCause() instanceof RejectedExecutionException) {
245 - log.warn("Could not process message: queue full"); 208 + log.debug("Could not process message: queue full");
246 } else { 209 } else {
247 - log.error("Error while processing message from OSPF {}, state {}", 210 + log.debug("Error while processing message from OSPF {}, {}",
248 - e.getChannel().getRemoteAddress(), ((OspfInterfaceImpl) ospfInterface).state()); 211 + e.getChannel().getRemoteAddress(), e.getCause().getMessage());
249 } 212 }
250 } 213 }
251 214
252 @Override 215 @Override
253 - public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { 216 + public void messageReceived(ChannelHandlerContext ctx, MessageEvent
217 + e) throws Exception {
254 log.debug("OspfChannelHandler::messageReceived...!!!"); 218 log.debug("OspfChannelHandler::messageReceived...!!!");
255 Object message = e.getMessage(); 219 Object message = e.getMessage();
256 if (message instanceof List) { 220 if (message instanceof List) {
257 List<OspfMessage> ospfMessageList = (List<OspfMessage>) message; 221 List<OspfMessage> ospfMessageList = (List<OspfMessage>) message;
258 - log.debug("OspfChannelHandler::List of OspfMessages Size {}", ospfMessageList.size()); 222 + log.debug("OspfChannelHandler::List of IsisMessages Size {}", ospfMessageList.size());
259 if (ospfMessageList != null) { 223 if (ospfMessageList != null) {
260 for (OspfMessage ospfMessage : ospfMessageList) { 224 for (OspfMessage ospfMessage : ospfMessageList) {
261 processOspfMessage(ospfMessage, ctx); 225 processOspfMessage(ospfMessage, ctx);
...@@ -280,1121 +244,28 @@ public class OspfInterfaceChannelHandler extends IdleStateAwareChannelHandler { ...@@ -280,1121 +244,28 @@ public class OspfInterfaceChannelHandler extends IdleStateAwareChannelHandler {
280 * @param ctx channel handler context instance. 244 * @param ctx channel handler context instance.
281 * @throws Exception might throws exception 245 * @throws Exception might throws exception
282 */ 246 */
283 - public void processOspfMessage(OspfMessage ospfMessage, ChannelHandlerContext ctx) throws Exception { 247 + public void processOspfMessage(OspfMessage
248 + ospfMessage, ChannelHandlerContext ctx) throws Exception {
284 log.debug("OspfChannelHandler::processOspfMessage...!!!"); 249 log.debug("OspfChannelHandler::processOspfMessage...!!!");
285 - 250 + int interfaceIndex = ospfMessage.interfaceIndex();
286 - if (!validateMessage(ospfMessage)) { 251 + OspfInterface ospfInterface = ospfInterfaceMap.get(interfaceIndex);
287 - return; 252 + if (ospfInterface != null) {
288 - } 253 + ospfInterface.processOspfMessage(ospfMessage, ctx);
289 -
290 - switch (ospfMessage.ospfMessageType().value()) {
291 - case OspfParameters.HELLO:
292 - processHelloMessage(ospfMessage, ctx);
293 - break;
294 - case OspfParameters.DD:
295 - processDdMessage(ospfMessage, ctx);
296 - break;
297 - case OspfParameters.LSREQUEST:
298 - processLsRequestMessage(ospfMessage, ctx);
299 - break;
300 - case OspfParameters.LSUPDATE:
301 - processLsUpdateMessage(ospfMessage, ctx);
302 - break;
303 - case OspfParameters.LSACK:
304 - processLsAckMessage(ospfMessage, ctx);
305 - break;
306 - default:
307 - log.debug("Unknown packet to process...!!!");
308 - break;
309 - }
310 - }
311 -
312 - /**
313 - * Validates the OSPF message received.
314 - *
315 - * @param ospfMessage OSPF message.
316 - * @return true if it is a valid else false.
317 - * @throws Exception might throws exception
318 - */
319 - private boolean validateMessage(OspfMessage ospfMessage) throws Exception {
320 - boolean isValid = true;
321 - OspfPacketHeader header = (OspfPacketHeader) ospfMessage;
322 -
323 - //added the check to eliminate self origin packets also two interfaces on same router.
324 - if (!header.sourceIp().equals(ospfInterface.ipAddress()) && !header.routerId().equals(
325 - ospfArea.routerId())) {
326 - //Verify the checksum
327 - ChecksumCalculator checksum = new ChecksumCalculator();
328 - if (!checksum.isValidOspfCheckSum(ospfMessage, OspfUtil.OSPFPACKET_CHECKSUM_POS1,
329 - OspfUtil.OSPFPACKET_CHECKSUM_POS2)) {
330 - log.debug("Checksum mismatch. Received packet type {} ", ospfMessage.ospfMessageType());
331 - return false;
332 - }
333 - if (((OspfPacketHeader) ospfMessage).ospfVersion() != OspfUtil.OSPF_VERSION_2) {
334 - log.debug("Received osfpMessage Version should match with Interface Version ");
335 - return false;
336 - }
337 - if (!((OspfPacketHeader) ospfMessage).areaId().equals(ospfArea.areaId())) {
338 - log.debug("Received ospf packets are from different area than our Area ID. " +
339 - "Received Area ID {}, Our AreaId {} ",
340 - ((OspfPacketHeader) ospfMessage).areaId(), ospfArea.areaId());
341 - return false;
342 - }
343 -
344 - //According to RFC-2328 (8.2)
345 - /**
346 - * ABR should receive packets from backbone 0.0.0.0 as we are not acting as ABR
347 - * we are rejecting the packet.
348 - */
349 - if (((OspfPacketHeader) ospfMessage).areaId().equals(Ip4Address.valueOf("0.0.0.0"))) {
350 - log.debug("ABR should receive packets from backbone 0.0.0.0 as we are not acting as " +
351 - "ABR we are rejecting the ospf packet");
352 - return false;
353 - }
354 - if (ospfInterface.interfaceType() == OspfInterfaceType.BROADCAST.value() &&
355 - !OspfUtil.sameNetwork(((OspfPacketHeader) ospfMessage).sourceIp(),
356 - ospfInterface.ipAddress(), ospfInterface.ipNetworkMask())) {
357 - log.debug("Received packets from different subnets. Discarding...!!!");
358 - return false;
359 - }
360 - } else {
361 - isValid = false;
362 - }
363 -
364 - return isValid;
365 - }
366 -
367 - /**
368 - * Processes Hello message.
369 - *
370 - * @param ospfMessage OSPF message instance.
371 - * @param ctx context instance.
372 - * @throws Exception might throws exception
373 - */
374 - void processHelloMessage(OspfMessage ospfMessage, ChannelHandlerContext ctx) throws Exception {
375 - log.debug("OspfChannelHandler::processHelloMessage...!!!");
376 - HelloPacket helloPacket = (HelloPacket) ospfMessage;
377 -
378 - // processing of hello packet as per RFC 2328 section 10.5
379 - log.debug("OspfChannelHandler::processHelloMessage::Interface Type {} OSPFInterfaceState {} ",
380 - ospfInterface.interfaceType(), ((OspfInterfaceImpl) ospfInterface).state());
381 -
382 - if (ospfInterface.interfaceType() != OspfInterfaceType.POINT_TO_POINT.value()) {
383 - if (!helloPacket.networkMask().equals(ospfInterface.ipNetworkMask())) {
384 - log.debug("OspfChannelHandler::processHelloMessage::Hello Packet Received does not " +
385 - "match the same network mask as the configure Interface");
386 - return;
387 - }
388 - }
389 - if (helloPacket.helloInterval() != ospfInterface.helloIntervalTime()) {
390 - log.debug("OspfChannelHandler::processHelloMessage::Hello Packet Received have the same " +
391 - "hello interval as configured Interface");
392 - return;
393 - }
394 - if (helloPacket.routerDeadInterval() != ospfInterface.routerDeadIntervalTime()) {
395 - log.debug("OspfChannelHandler::processHelloMessage::Hello Packet Received have the same " +
396 - "Router Dead interval as configured Interface");
397 - return;
398 - }
399 -
400 - if (ospfInterface.interfaceType() == OspfInterfaceType.POINT_TO_POINT.value()) {
401 - // to verify if the neighbor which sent the hello is present in the OSPF Interface neighboring list .
402 - OspfNbr nbr;
403 - if (!ospfInterface.isNeighborInList(helloPacket.routerId().toString())) {
404 - nbr = new OspfNbrImpl(ospfArea, ospfInterface, helloPacket.sourceIp(),
405 - helloPacket.routerId(), helloPacket.options(), this, topologyForDeviceAndLink);
406 - ospfInterface.addNeighbouringRouter(nbr);
407 - } else {
408 - nbr = ospfInterface.neighbouringRouter(helloPacket.routerId().toString());
409 - nbr.setRouterPriority(helloPacket.routerPriority());
410 - }
411 - if (!helloPacket.containsNeighbour(ospfArea.routerId())) {
412 - ((OspfNbrImpl) nbr).oneWayReceived(helloPacket, channel);
413 - } else {
414 - ((OspfNbrImpl) nbr).twoWayReceived(helloPacket, ctx.getChannel());
415 - }
416 - } else if (ospfInterface.interfaceType() == OspfInterfaceType.BROADCAST.value()) {
417 -
418 - if (((OspfInterfaceImpl) ospfInterface).state() == OspfInterfaceState.WAITING) {
419 - if ((!helloPacket.dr().equals(Ip4Address.valueOf("0.0.0.0"))) &&
420 - (!helloPacket.bdr().equals(Ip4Address.valueOf("0.0.0.0")))) {
421 - stopWaitTimer();
422 - ospfInterface.setDr(helloPacket.dr());
423 - ospfInterface.setBdr(helloPacket.bdr());
424 - if (helloPacket.dr().equals(ospfInterface.ipAddress())) {
425 - ((OspfInterfaceImpl) ospfInterface).setState(OspfInterfaceState.DR);
426 - //refresh router Lsa
427 - ospfArea.refreshArea(ospfInterface);
428 - } else if (helloPacket.bdr().equals(ospfInterface.ipAddress())) {
429 - ((OspfInterfaceImpl) ospfInterface).setState(OspfInterfaceState.BDR);
430 - //refresh router Lsa
431 - ospfArea.refreshArea(ospfInterface);
432 - } else {
433 - ((OspfInterfaceImpl) ospfInterface).setState(OspfInterfaceState.DROTHER);
434 - ospfArea.refreshArea(ospfInterface);
435 - }
436 -
437 - } else if (!helloPacket.dr().equals(Ip4Address.valueOf("0.0.0.0")) ||
438 - !helloPacket.bdr().equals(Ip4Address.valueOf("0.0.0.0"))) {
439 - ospfInterface.setDr(helloPacket.dr());
440 - ospfInterface.setBdr(helloPacket.bdr());
441 - }
442 - Ip4Address sourceIp = helloPacket.sourceIp();
443 - OspfNbr nbr;
444 - if (!ospfInterface.isNeighborInList(helloPacket.routerId().toString())) {
445 - nbr = new OspfNbrImpl(ospfArea, ospfInterface, sourceIp, helloPacket.routerId(),
446 - helloPacket.options(), this, topologyForDeviceAndLink);
447 - nbr.setNeighborId(helloPacket.routerId());
448 - nbr.setNeighborBdr(helloPacket.bdr());
449 - nbr.setNeighborDr(helloPacket.dr());
450 - nbr.setRouterPriority(helloPacket.routerPriority());
451 - ospfInterface.addNeighbouringRouter(nbr);
452 - } else {
453 - nbr = ospfInterface.neighbouringRouter(helloPacket.routerId().toString());
454 - nbr.setRouterPriority(helloPacket.routerPriority());
455 - }
456 - if (!helloPacket.containsNeighbour(ospfArea.routerId())) {
457 - ((OspfNbrImpl) nbr).oneWayReceived(helloPacket, channel);
458 - } else {
459 - ((OspfNbrImpl) nbr).twoWayReceived(helloPacket, ctx.getChannel());
460 - }
461 -
462 - if (helloPacket.dr().equals(sourceIp)) {
463 - if (helloPacket.bdr().equals(Ip4Address.valueOf("0.0.0.0"))) {
464 - // call backup seen
465 - stopWaitTimer();
466 - backupSeen(ctx.getChannel());
467 - }
468 - }
469 -
470 - if (helloPacket.bdr().equals(sourceIp)) {
471 - // call backup seen
472 - stopWaitTimer();
473 - backupSeen(ctx.getChannel());
474 - }
475 - } else {
476 -
477 - if ((!helloPacket.dr().equals(Ip4Address.valueOf("0.0.0.0")) ||
478 - !helloPacket.bdr().equals(Ip4Address.valueOf("0.0.0.0")))
479 - && ospfInterface.routerPriority() == 0) {
480 - ospfInterface.setDr(helloPacket.dr());
481 - ospfInterface.setBdr(helloPacket.bdr());
482 - }
483 - //To verify if the neighbor which sent the hello is present in the OSPF Interface neighboring list .
484 - Ip4Address sourceIp = helloPacket.sourceIp();
485 - OspfNbr nbr;
486 - if (!ospfInterface.isNeighborInList(helloPacket.routerId().toString())) {
487 - nbr = new OspfNbrImpl(ospfArea, ospfInterface, sourceIp, helloPacket.routerId(),
488 - helloPacket.options(), this, topologyForDeviceAndLink);
489 - nbr.setNeighborId(helloPacket.routerId());
490 - nbr.setNeighborBdr(helloPacket.bdr());
491 - nbr.setNeighborDr(helloPacket.dr());
492 - nbr.setRouterPriority(helloPacket.routerPriority());
493 - ospfInterface.addNeighbouringRouter(nbr);
494 - ((OspfNbrImpl) nbr).oneWayReceived(helloPacket, channel);
495 - } else {
496 - log.debug("OspfChannelHandler::NeighborInList::helloPacket.bdr(): {}, " +
497 - "helloPacket.dr(): {}", helloPacket.bdr(), helloPacket.dr());
498 - nbr = ospfInterface.neighbouringRouter(helloPacket.routerId().toString());
499 - nbr.setRouterPriority(helloPacket.routerPriority());
500 - if (!helloPacket.containsNeighbour(ospfArea.routerId())) {
501 - ((OspfNbrImpl) nbr).oneWayReceived(helloPacket, channel);
502 - } else {
503 - ((OspfNbrImpl) nbr).twoWayReceived(helloPacket, ctx.getChannel());
504 - }
505 - if (nbr.routerPriority() != helloPacket.routerPriority()) {
506 - nbr.setNeighborBdr(helloPacket.bdr());
507 - nbr.setNeighborDr(helloPacket.dr());
508 - neighborChange();
509 - }
510 -
511 -
512 - if (nbr.neighborIpAddr().equals(helloPacket.dr()) &&
513 - !(nbr.neighborIpAddr().equals(nbr.neighborDr()))) {
514 - nbr.setNeighborBdr(helloPacket.bdr());
515 - nbr.setNeighborDr(helloPacket.dr());
516 - neighborChange();
517 - }
518 -
519 - if (!(nbr.neighborIpAddr().equals(helloPacket.dr())) &&
520 - (nbr.neighborIpAddr().equals(nbr.neighborDr()))) {
521 - nbr.setNeighborBdr(helloPacket.bdr());
522 - nbr.setNeighborDr(helloPacket.dr());
523 - neighborChange();
524 - }
525 -
526 - if (nbr.neighborIpAddr().equals(helloPacket.bdr()) &&
527 - !(nbr.neighborIpAddr().equals(nbr.neighborBdr()))) {
528 - nbr.setNeighborBdr(helloPacket.bdr());
529 - nbr.setNeighborDr(helloPacket.dr());
530 - neighborChange();
531 - }
532 -
533 - if (!(nbr.neighborIpAddr().equals(helloPacket.bdr())) &&
534 - (nbr.neighborIpAddr().equals(nbr.neighborBdr()))) {
535 - nbr.setNeighborBdr(helloPacket.bdr());
536 - nbr.setNeighborDr(helloPacket.dr());
537 - neighborChange();
538 - }
539 -
540 - nbr.setNeighborBdr(helloPacket.bdr());
541 - nbr.setNeighborDr(helloPacket.dr());
542 - }
543 -
544 - }
545 } 254 }
546 } 255 }
547 256
548 /** 257 /**
549 - * process the DD message which received. 258 + * Sends the interface configuration packet to server.
550 * 259 *
551 - * @param ospfMessage OSPF message instance. 260 + * @param configPacket interface configuration
552 - * @param ctx channel handler context instance
553 - * @throws Exception might throws exception
554 */ 261 */
555 - void processDdMessage(OspfMessage ospfMessage, ChannelHandlerContext ctx) throws Exception { 262 + public void sentConfigPacket(byte[] configPacket) {
556 - log.debug("OspfChannelHandler::processDdMessage...!!!"); 263 + if (channel != null) {
557 - 264 + channel.write(configPacket);
558 - DdPacket ddPacket = (DdPacket) ospfMessage; 265 + log.debug("OspfChannelHandler sentConfigPacket packet sent..!!!");
559 - log.debug("Got DD packet from {}", ddPacket.sourceIp());
560 - //check it is present in listOfNeighbors
561 - Ip4Address neighbourId = ddPacket.routerId();
562 - OspfNbr nbr = ospfInterface.neighbouringRouter(neighbourId.toString());
563 -
564 - if (nbr != null) {
565 - log.debug("OspfChannelHandler::processDdMessage:: OSPFNeighborState {}", nbr.getState());
566 - // set options for the NBR
567 - nbr.setIsOpaqueCapable(ddPacket.isOpaqueCapable());
568 - if (ddPacket.imtu() > ospfInterface.mtu()) {
569 - log.debug("the MTU size is greater than the interface MTU");
570 - return;
571 - }
572 - if (nbr.getState() == OspfNeighborState.DOWN) {
573 - return;
574 - }
575 - if (nbr.getState() == OspfNeighborState.ATTEMPT) {
576 - return;
577 - }
578 - if (nbr.getState() == OspfNeighborState.TWOWAY) {
579 - nbr.adjOk(channel);
580 - return;
581 - }
582 - //if init is the state call twoWayReceived
583 - if (nbr.getState() == OspfNeighborState.INIT) {
584 - ((OspfNbrImpl) nbr).twoWayReceived(ddPacket, ctx.getChannel());
585 - } else if (nbr.getState() == OspfNeighborState.EXSTART) {
586 - //get I,M,MS Bits
587 - int initialize = ddPacket.isInitialize();
588 - int more = ddPacket.isMore();
589 - int masterOrSlave = ddPacket.isMaster();
590 - int options = ddPacket.options();
591 - nbr.setOptions(options);
592 -
593 - if (initialize == OspfUtil.INITIALIZE_SET && more == OspfUtil.MORE_SET &&
594 - masterOrSlave == OspfUtil.IS_MASTER) {
595 - if (ddPacket.getLsaHeaderList().isEmpty()) {
596 - if (OspfUtil.ipAddressToLong(ddPacket.routerId().toString()) >
597 - OspfUtil.ipAddressToLong(ospfArea.routerId().toString())) {
598 - nbr.setIsMaster(OspfUtil.IS_MASTER);
599 - ((OspfNbrImpl) nbr).setLastDdPacket(ddPacket);
600 - nbr.setDdSeqNum(ddPacket.sequenceNo());
601 - nbr.setOptions(ddPacket.options());
602 - ((OspfNbrImpl) nbr).negotiationDone(ddPacket, true, ddPacket.getLsaHeaderList(),
603 - ctx.getChannel());
604 - }
605 - }
606 - }
607 - if (initialize == OspfUtil.INITIALIZE_NOTSET && masterOrSlave == OspfUtil.NOT_MASTER) {
608 - if (nbr.ddSeqNum() == ddPacket.sequenceNo()) {
609 - if (OspfUtil.ipAddressToLong(ddPacket.routerId().toString()) <
610 - OspfUtil.ipAddressToLong(ospfArea.routerId().toString())) {
611 - ((OspfNbrImpl) nbr).setLastDdPacket(ddPacket);
612 - nbr.setOptions(ddPacket.options());
613 - nbr.setDdSeqNum(nbr.ddSeqNum() + 1);
614 - ((OspfNbrImpl) nbr).negotiationDone(ddPacket, false, ddPacket.getLsaHeaderList(),
615 - ctx.getChannel());
616 - }
617 - }
618 - }
619 -
620 - } else if (nbr.getState() == OspfNeighborState.EXCHANGE) {
621 - //get I,M,MS Bits
622 - log.debug("Neighbor state:: EXCHANGE");
623 - boolean isDuplicateDDPacket = compareDdPackets(ddPacket, ((OspfNbrImpl) nbr).lastDdPacket());
624 - int initialize = ddPacket.isInitialize();
625 - int more = ddPacket.isMore();
626 - int masterOrSlave = ddPacket.isMaster();
627 - int options = ddPacket.options();
628 -
629 - if (!isDuplicateDDPacket) {
630 - //if dd packet is not duplicate then continue
631 - if (nbr.isMaster() != masterOrSlave) {
632 - DdPacket newResPacket =
633 - (DdPacket) ((OspfNbrImpl) nbr).seqNumMismatch("Master/Slave Inconsistency");
634 - newResPacket.setDestinationIp(ddPacket.sourceIp());
635 - log.debug("Sending back DDPacket to {}", ddPacket.sourceIp());
636 - ctx.getChannel().write(newResPacket);
637 - } else if (initialize == 1) {
638 - DdPacket newResPacket =
639 - (DdPacket) ((OspfNbrImpl) nbr).seqNumMismatch("Initialize bit inconsistency");
640 - newResPacket.setDestinationIp(ddPacket.sourceIp());
641 - log.debug("Sending back DDPacket to {}", ddPacket.sourceIp());
642 - ctx.getChannel().write(newResPacket);
643 - } else {
644 -
645 - if (masterOrSlave == OspfUtil.NOT_MASTER) {
646 - if (ddPacket.sequenceNo() == nbr.ddSeqNum()) {
647 - //Process the DD Packet
648 - ((OspfNbrImpl) nbr).processDdPacket(false, ddPacket, ctx.getChannel());
649 - log.debug("Received DD Packet");
650 - } else {
651 - DdPacket newResPacket =
652 - (DdPacket) ((OspfNbrImpl) nbr).seqNumMismatch("Sequence Number Mismatch");
653 - newResPacket.setDestinationIp(ddPacket.sourceIp());
654 - log.debug("Sending back DDPacket to {}", ddPacket.sourceIp());
655 - ctx.getChannel().write(newResPacket);
656 - }
657 - } else {
658 - //we are the slave
659 - if (ddPacket.sequenceNo() == (nbr.ddSeqNum() + 1)) {
660 - ((OspfNbrImpl) nbr).setLastDdPacket(ddPacket);
661 - ((OspfNbrImpl) nbr).processDdPacket(true, ddPacket, ctx.getChannel());
662 - log.debug("Process DD Packet");
663 - } else {
664 - DdPacket newResPacket =
665 - (DdPacket) ((OspfNbrImpl) nbr).seqNumMismatch("options inconsistency");
666 - newResPacket.setDestinationIp(ddPacket.sourceIp());
667 - log.debug("Sending back DDPacket to {}", ddPacket.sourceIp());
668 - ctx.getChannel().write(newResPacket);
669 - }
670 - }
671 - }
672 } else { 266 } else {
673 - if (masterOrSlave == OspfUtil.NOT_MASTER) { 267 + log.debug("OspfChannelHandler sentConfigPacket channel not connected - re try..!!!");
674 - return; 268 + this.configPacket = configPacket;
675 - } else {
676 - DdPacket newResPacket = ((OspfNbrImpl) nbr).lastSentDdPacket();
677 - log.debug("Sending back DDPacket to {}", ddPacket.sourceIp());
678 - ctx.getChannel().write(newResPacket);
679 - }
680 - }
681 - } else if (nbr.getState() == OspfNeighborState.LOADING || nbr.getState() == OspfNeighborState.FULL) {
682 - //In case if we are slave then we have to send the last received DD Packet
683 - int options = ddPacket.options();
684 - if (nbr.options() != options) {
685 - OspfMessage newResPacket = ((OspfNbrImpl) nbr).seqNumMismatch("Initialize bit inconsistency");
686 - newResPacket.setDestinationIp(ddPacket.sourceIp());
687 - ctx.getChannel().write(newResPacket);
688 - } else if (ddPacket.isInitialize() == OspfUtil.INITIALIZE_SET) {
689 - OspfMessage newResPacket = ((OspfNbrImpl) nbr).seqNumMismatch("Initialize bit inconsistency");
690 - newResPacket.setDestinationIp(ddPacket.sourceIp());
691 - ctx.getChannel().write(newResPacket);
692 - }
693 - boolean isDuplicate = compareDdPackets(ddPacket, ((OspfNbrImpl) nbr).lastDdPacket());
694 - //we are master
695 - if (nbr.isMaster() != OspfUtil.IS_MASTER) {
696 - // check if the packet is duplicate, duplicates should be discarded by the master
697 - if (isDuplicate) {
698 - log.debug("received a duplicate DD packet");
699 - }
700 - } else {
701 - //The slave must respond to duplicates by repeating the last Database Description packet
702 - //that it had sent.
703 - if (isDuplicate) {
704 - ddPacket.setDestinationIp(ddPacket.sourceIp());
705 - ctx.getChannel().write(((OspfNbrImpl) nbr).lastSentDdPacket());
706 - log.debug("Sending back the duplicate packet ");
707 - }
708 - }
709 - }
710 - }
711 - }
712 -
713 - /**
714 - * Process the Ls Request message.
715 - *
716 - * @param ospfMessage OSPF message instance.
717 - * @param ctx channel handler context instance.
718 - * @throws Exception might throws exception
719 - */
720 - void processLsRequestMessage(OspfMessage ospfMessage, ChannelHandlerContext ctx) throws Exception {
721 - log.debug("OspfChannelHandler::processLsRequestMessage...!!!");
722 - LsRequest lsrPacket = (LsRequest) ospfMessage;
723 - OspfNbr nbr = ospfInterface.neighbouringRouter(lsrPacket.routerId().toString());
724 -
725 - if (nbr.getState() == OspfNeighborState.EXCHANGE || nbr.getState() == OspfNeighborState.LOADING ||
726 - nbr.getState() == OspfNeighborState.FULL) {
727 -
728 - LsRequest reqMsg = (LsRequest) ospfMessage;
729 - if (reqMsg.getLinkStateRequests().isEmpty()) {
730 - log.debug("Received Link State Request Vector is Empty ");
731 - return;
732 - } else {
733 - //Send the LsUpdate back
734 - ListIterator<LsRequestPacket> listItr = reqMsg.getLinkStateRequests().listIterator();
735 - while (listItr.hasNext()) {
736 - LsUpdate lsupdate = new LsUpdate();
737 - lsupdate.setOspfVer(OspfUtil.OSPF_VERSION);
738 - lsupdate.setOspftype(OspfPacketType.LSUPDATE.value());
739 - lsupdate.setRouterId(ospfArea.routerId());
740 - lsupdate.setAreaId(ospfArea.areaId());
741 - lsupdate.setAuthType(OspfUtil.NOT_ASSIGNED);
742 - lsupdate.setAuthentication(OspfUtil.NOT_ASSIGNED);
743 - lsupdate.setOspfPacLength(OspfUtil.NOT_ASSIGNED); // to calculate packet length
744 - lsupdate.setChecksum(OspfUtil.NOT_ASSIGNED);
745 -
746 - //limit to mtu
747 - int currentLength = OspfUtil.OSPF_HEADER_LENGTH + OspfUtil.FOUR_BYTES;
748 - int maxSize = ospfInterface.mtu() -
749 - OspfUtil.LSA_HEADER_LENGTH; // subtract a normal IP header.
750 - int noLsa = 0;
751 - while (listItr.hasNext()) {
752 - LsRequestPacket lsRequest = (LsRequestPacket) listItr.next();
753 - // to verify length of the LSA
754 - LsaWrapper wrapper = ospfArea.getLsa(lsRequest.lsType(), lsRequest.linkStateId(),
755 - lsRequest.ownRouterId());
756 - OspfLsa ospflsa = wrapper.ospfLsa();
757 - if ((currentLength + ((LsaWrapperImpl) wrapper).lsaHeader().lsPacketLen()) >= maxSize) {
758 - listItr.previous();
759 - break;
760 - }
761 - if (ospflsa != null) {
762 - lsupdate.addLsa(ospflsa);
763 - noLsa++;
764 -
765 - currentLength = currentLength + ((LsaWrapperImpl) wrapper).lsaHeader().lsPacketLen();
766 - } else {
767 - nbr.badLSReq(channel);
768 - }
769 - }
770 - lsupdate.setNumberOfLsa(noLsa);
771 - //set the destination
772 - if (((OspfInterfaceImpl) ospfInterface).state() == OspfInterfaceState.DR ||
773 - ((OspfInterfaceImpl) ospfInterface).state() == OspfInterfaceState.BDR ||
774 - ((OspfInterfaceImpl) ospfInterface).state() == OspfInterfaceState.POINT2POINT) {
775 - lsupdate.setDestinationIp(OspfUtil.ALL_SPF_ROUTERS);
776 - } else if (((OspfInterfaceImpl) ospfInterface).state() == OspfInterfaceState.DROTHER) {
777 - lsupdate.setDestinationIp(OspfUtil.ALL_DROUTERS);
778 - }
779 - ctx.getChannel().write(lsupdate);
780 - }
781 - }
782 - }
783 - }
784 -
785 - /**
786 - * Process the ls update message.
787 - *
788 - * @param ospfMessage OSPF message instance.
789 - * @param ctx channel handler context instance.
790 - * @throws Exception might throws exception
791 - */
792 - void processLsUpdateMessage(OspfMessage ospfMessage, ChannelHandlerContext ctx) throws Exception {
793 - log.debug("OspfChannelHandler::processLsUpdateMessage");
794 - LsUpdate lsUpdate = (LsUpdate) ospfMessage;
795 - String neighbourId = lsUpdate.routerId().toString();
796 - //LSUpdate packet has been associated with a particular neighbor.
797 - //Neighbor should not be in lesser state than Exchange.
798 - if (ospfInterface.isNeighborInList(neighbourId)) {
799 - OspfNbrImpl nbr = (OspfNbrImpl) ospfInterface.neighbouringRouter(neighbourId);
800 - if (nbr.getState() == OspfNeighborState.EXCHANGE ||
801 - nbr.getState() == OspfNeighborState.LOADING) {
802 - nbr.processLsUpdate(lsUpdate, ctx.getChannel());
803 - } else if (nbr.getState() == OspfNeighborState.FULL) {
804 - if (lsUpdate.noLsa() != 0) {
805 - List<OspfLsa> list = lsUpdate.getLsaList();
806 - Iterator itr = list.iterator();
807 - while (itr.hasNext()) {
808 - LsaHeader lsa = (LsaHeader) itr.next();
809 - nbr.processReceivedLsa(lsa, true, ctx.getChannel(), lsUpdate.sourceIp());
810 - }
811 - } else {
812 - return;
813 - }
814 - }
815 - }
816 - }
817 -
818 - /**
819 - * Process the ls acknowledge message.
820 - *
821 - * @param ospfMessage OSPF message instance.
822 - * @param ctx channel handler context instance.
823 - * @throws Exception might throws exception
824 - */
825 - void processLsAckMessage(OspfMessage ospfMessage, ChannelHandlerContext ctx) throws Exception {
826 - log.debug("OspfChannelHandler::processLsAckMessage");
827 - LsAcknowledge lsAckPacket = (LsAcknowledge) ospfMessage;
828 - //check it is present in listOfNeighbors
829 - OspfNbrImpl nbr = (OspfNbrImpl) ospfInterface.neighbouringRouter(lsAckPacket.routerId().toString());
830 - if (nbr != null) {
831 - if (nbr.getState().getValue() < OspfNeighborState.EXCHANGE.getValue()) {
832 - // discard the packet.
833 - return;
834 - } else {
835 - // process ls acknowledgements
836 - Iterator itr = lsAckPacket.getLinkStateHeaders().iterator();
837 - while (itr.hasNext()) {
838 - LsaHeader lsRequest = (LsaHeader) itr.next();
839 -
840 - OspfLsa ospfLsa =
841 - (OspfLsa) nbr.getPendingReTxList().get(((OspfAreaImpl) ospfArea).getLsaKey(lsRequest));
842 - if (lsRequest != null && ospfLsa != null) {
843 - String isSame = ((OspfLsdbImpl) ospfArea.database()).isNewerOrSameLsa(
844 - lsRequest, (LsaHeader) ospfLsa);
845 - if (isSame.equals("same")) {
846 - nbr.getPendingReTxList().remove(((OspfAreaImpl) ospfArea).getLsaKey(lsRequest));
847 - }
848 - }
849 - }
850 - }
851 - }
852 - }
853 -
854 - /**
855 - * Compares two Dd Packets to check whether its duplicate or not.
856 - *
857 - * @param receivedDPacket received DD packet from network.
858 - * @param lastDdPacket Last DdPacket which we sent.
859 - * @return true if it is a duplicate packet else false.
860 - */
861 - public boolean compareDdPackets(DdPacket receivedDPacket, DdPacket lastDdPacket) {
862 - if (receivedDPacket.isInitialize() == lastDdPacket.isInitialize()) {
863 - if (receivedDPacket.isMaster() == lastDdPacket.isMaster()) {
864 - if (receivedDPacket.isMore() == lastDdPacket.isMore()) {
865 - if (receivedDPacket.options() == lastDdPacket.options()) {
866 - if (receivedDPacket.sequenceNo() == lastDdPacket.sequenceNo()) {
867 - return true;
868 - }
869 - }
870 - }
871 - }
872 - }
873 - return false;
874 - }
875 -
876 - /**
877 - * Closes the Netty channel.
878 - *
879 - * @param ctx the Channel Handler Context
880 - */
881 - void closeChannel(ChannelHandlerContext ctx) {
882 - log.debug("OspfChannelHandler::closeChannel");
883 - isClosed = true;
884 - ctx.getChannel().close();
885 - }
886 -
887 - /**
888 - * Starts the hello timer which sends hello packet every configured seconds.
889 - *
890 - * @param period the interval to run task
891 - */
892 - private void startHelloTimer(long period) {
893 - log.debug("OSPFInterfaceChannelHandler::startHelloTimer");
894 - exServiceHello = Executors.newSingleThreadScheduledExecutor();
895 - helloTimerTask = new InternalHelloTimer();
896 - final ScheduledFuture<?> helloHandle =
897 - exServiceHello.scheduleAtFixedRate(helloTimerTask, delay, period, TimeUnit.SECONDS);
898 - }
899 -
900 - /**
901 - * Stops the hello timer.
902 - */
903 - private void stopHelloTimer() {
904 - log.debug("OSPFInterfaceChannelHandler::stopHelloTimer ");
905 - exServiceHello.shutdown();
906 - }
907 -
908 - /**
909 - * Starts the wait timer.
910 - */
911 - private void startWaitTimer() {
912 - log.debug("OSPFNbr::startWaitTimer");
913 - exServiceWait = Executors.newSingleThreadScheduledExecutor();
914 - waitTimerTask = new InternalWaitTimer();
915 - final ScheduledFuture<?> waitTimerHandle =
916 - exServiceWait.schedule(waitTimerTask, ospfInterface.routerDeadIntervalTime(),
917 - TimeUnit.SECONDS);
918 - }
919 -
920 - /**
921 - * Stops the wait timer.
922 - */
923 - private void stopWaitTimer() {
924 - log.debug("OSPFNbr::stopWaitTimer ");
925 - exServiceWait.shutdown();
926 - }
927 -
928 - /**
929 - * Starts the timer which waits for configured seconds and sends Delayed Ack Packet.
930 - */
931 - private void startDelayedAckTimer() {
932 - if (!isDelayedAckTimerScheduled) {
933 - log.debug("Started DelayedAckTimer...!!!");
934 - exServiceDelayedAck = Executors.newSingleThreadScheduledExecutor();
935 - delayedAckTimerTask = new InternalDelayedAckTimer();
936 - final ScheduledFuture<?> delayAckHandle =
937 - exServiceDelayedAck.scheduleAtFixedRate(delayedAckTimerTask, delayedAckTimerInterval,
938 - delayedAckTimerInterval, TimeUnit.MILLISECONDS);
939 - isDelayedAckTimerScheduled = true;
940 - }
941 - }
942 -
943 - /**
944 - * Stops the delayed acknowledge timer.
945 - */
946 - private void stopDelayedAckTimer() {
947 - if (isDelayedAckTimerScheduled) {
948 - log.debug("Stopped DelayedAckTimer...!!!");
949 - isDelayedAckTimerScheduled = false;
950 - exServiceDelayedAck.shutdown();
951 - }
952 - }
953 -
954 - /**
955 - * Performs DR election.
956 - *
957 - * @param ch Netty Channel instance.
958 - * @throws Exception might throws exception
959 - */
960 - public void electRouter(Channel ch) throws Exception {
961 -
962 - Ip4Address currentDr = ospfInterface.dr();
963 - Ip4Address currentBdr = ospfInterface.bdr();
964 - OspfInterfaceState oldState = ((OspfInterfaceImpl) ospfInterface).state();
965 - OspfInterfaceState newState;
966 -
967 - log.debug("OSPFInterfaceChannelHandler::electRouter -> currentDr: {}, currentBdr: {}",
968 - currentDr, currentBdr);
969 - List<OspfEligibleRouter> eligibleRouters = calculateListOfEligibleRouters(new OspfEligibleRouter());
970 -
971 - log.debug("OSPFInterfaceChannelHandler::electRouter -> eligibleRouters: {}", eligibleRouters);
972 - OspfEligibleRouter electedBdr = electBdr(eligibleRouters);
973 - OspfEligibleRouter electedDr = electDr(eligibleRouters, electedBdr);
974 -
975 - ospfInterface.setBdr(electedBdr.getIpAddress());
976 - ospfInterface.setDr(electedDr.getIpAddress());
977 -
978 - if (electedBdr.getIpAddress().equals(ospfInterface.ipAddress()) &&
979 - !electedBdr.getIpAddress().equals(currentBdr)) {
980 - ((OspfInterfaceImpl) ospfInterface).setState(OspfInterfaceState.BDR);
981 - }
982 -
983 - if (electedDr.getIpAddress().equals(ospfInterface.ipAddress()) &&
984 - !electedDr.getIpAddress().equals(currentDr)) {
985 - ((OspfInterfaceImpl) ospfInterface).setState(OspfInterfaceState.DR);
986 - }
987 -
988 - if (((OspfInterfaceImpl) ospfInterface).state() != oldState &&
989 - !(((OspfInterfaceImpl) ospfInterface).state() == OspfInterfaceState.DROTHER &&
990 - oldState.value() < OspfInterfaceState.DROTHER.value())) {
991 - log.debug("Recalculating as the State is changed ");
992 - log.debug("OSPFInterfaceChannelHandler::electRouter -> currentDr: {}, currentBdr: {}",
993 - currentDr, currentBdr);
994 - eligibleRouters = calculateListOfEligibleRouters(new OspfEligibleRouter());
995 -
996 - log.debug("OSPFInterfaceChannelHandler::electRouter -> eligibleRouters: {}", eligibleRouters);
997 - electedBdr = electBdr(eligibleRouters);
998 - electedDr = electDr(eligibleRouters, electedBdr);
999 -
1000 - ospfInterface.setBdr(electedBdr.getIpAddress());
1001 - ospfInterface.setDr(electedDr.getIpAddress());
1002 - }
1003 -
1004 - if (electedBdr.getIpAddress().equals(ospfInterface.ipAddress()) &&
1005 - !electedBdr.getIpAddress().equals(currentBdr)) {
1006 - ((OspfInterfaceImpl) ospfInterface).setState(OspfInterfaceState.BDR);
1007 - ospfArea.refreshArea(ospfInterface);
1008 - }
1009 -
1010 - if (electedDr.getIpAddress().equals(ospfInterface.ipAddress()) &&
1011 - !electedDr.getIpAddress().equals(currentDr)) {
1012 - ((OspfInterfaceImpl) ospfInterface).setState(OspfInterfaceState.DR);
1013 - //Refresh Router Lsa & Network Lsa
1014 - ospfArea.refreshArea(ospfInterface);
1015 - }
1016 -
1017 - if (currentDr != electedDr.getIpAddress() || currentBdr != electedBdr.getIpAddress()) {
1018 - Set<String> negibhorIdList;
1019 - negibhorIdList = ospfInterface.listOfNeighbors().keySet();
1020 - for (String routerid : negibhorIdList) {
1021 - OspfNbrImpl nbr = (OspfNbrImpl) ospfInterface.neighbouringRouter(routerid);
1022 - if (nbr.getState().getValue() >= OspfNeighborState.TWOWAY.getValue()) {
1023 - nbr.adjOk(ch);
1024 - }
1025 - }
1026 - }
1027 -
1028 - log.debug("OSPFInterfaceChannelHandler::electRouter -> ElectedDR: {}, ElectedBDR: {}",
1029 - electedDr.getIpAddress(), electedBdr.getIpAddress());
1030 - }
1031 -
1032 -
1033 - /**
1034 - * BDR Election process. Find the list of eligible router to participate in the process.
1035 - *
1036 - * @param electedDr router elected as DR.
1037 - * @return list of eligible routers
1038 - */
1039 - public List<OspfEligibleRouter> calculateListOfEligibleRouters(OspfEligibleRouter electedDr) {
1040 - log.debug("OSPFNbr::calculateListOfEligibleRouters ");
1041 - Set<String> neighborIdList;
1042 - List<OspfEligibleRouter> eligibleRouters = new ArrayList<>();
1043 -
1044 - neighborIdList = ospfInterface.listOfNeighbors().keySet();
1045 - for (String routerId : neighborIdList) {
1046 - OspfNbrImpl nbr = (OspfNbrImpl) ospfInterface.neighbouringRouter(routerId);
1047 - if (nbr.getState().getValue() >= OspfNeighborState.TWOWAY.getValue() &&
1048 - nbr.routerPriority() > 0) {
1049 - OspfEligibleRouter router = new OspfEligibleRouter();
1050 - router.setIpAddress(nbr.neighborIpAddr());
1051 - router.setRouterId(nbr.neighborId());
1052 - router.setRouterPriority(nbr.routerPriority());
1053 - if (nbr.neighborDr().equals(nbr.neighborIpAddr()) ||
1054 - electedDr.getIpAddress().equals(nbr.neighborIpAddr())) {
1055 - router.setIsDr(true);
1056 - } else if (nbr.neighborBdr().equals(nbr.neighborIpAddr())) {
1057 - router.setIsBdr(true);
1058 - }
1059 - eligibleRouters.add(router);
1060 - }
1061 - }
1062 - // interface does not have states like two and all
1063 - if (ospfInterface.routerPriority() > 0) {
1064 - OspfEligibleRouter router = new OspfEligibleRouter();
1065 - router.setIpAddress(ospfInterface.ipAddress());
1066 - router.setRouterId(ospfArea.routerId());
1067 - router.setRouterPriority(ospfInterface.routerPriority());
1068 - if (ospfInterface.dr().equals(ospfInterface.ipAddress()) ||
1069 - electedDr.getIpAddress().equals(ospfInterface.ipAddress())) {
1070 - router.setIsDr(true);
1071 - } else if (ospfInterface.bdr().equals(ospfInterface.ipAddress()) &&
1072 - !ospfInterface.dr().equals(ospfInterface.ipAddress())) {
1073 - router.setIsBdr(true);
1074 - }
1075 -
1076 - eligibleRouters.add(router);
1077 - }
1078 -
1079 - return eligibleRouters;
1080 - }
1081 -
1082 - /**
1083 - * Based on router priority assigns BDR.
1084 - *
1085 - * @param eligibleRouters list of routers to participate in bdr election.
1086 - * @return OSPF Eligible router instance.
1087 - */
1088 - public OspfEligibleRouter electBdr(List<OspfEligibleRouter> eligibleRouters) {
1089 - log.debug("OSPFInterfaceChannelHandler::electBdr -> eligibleRouters: {}", eligibleRouters);
1090 - List<OspfEligibleRouter> declaredAsBdr = new ArrayList<>();
1091 - List<OspfEligibleRouter> notDrAndBdr = new ArrayList<>();
1092 - for (OspfEligibleRouter router : eligibleRouters) {
1093 - if (router.isBdr()) {
1094 - declaredAsBdr.add(router);
1095 - }
1096 - if (!router.isBdr() && !router.isDr()) {
1097 - notDrAndBdr.add(router);
1098 - }
1099 - }
1100 -
1101 - OspfEligibleRouter electedBdr = new OspfEligibleRouter();
1102 - if (!declaredAsBdr.isEmpty()) {
1103 - if (declaredAsBdr.size() == 1) {
1104 - electedBdr = declaredAsBdr.get(0);
1105 - } else if (declaredAsBdr.size() > 1) {
1106 - electedBdr = selectRouterBasedOnPriority(declaredAsBdr);
1107 - }
1108 - } else {
1109 - if (notDrAndBdr.size() == 1) {
1110 - electedBdr = notDrAndBdr.get(0);
1111 - } else if (notDrAndBdr.size() > 1) {
1112 - electedBdr = selectRouterBasedOnPriority(notDrAndBdr);
1113 - }
1114 - }
1115 -
1116 - electedBdr.setIsBdr(true);
1117 - electedBdr.setIsDr(false);
1118 -
1119 - return electedBdr;
1120 - }
1121 -
1122 - /**
1123 - * DR Election process.
1124 - *
1125 - * @param eligibleRouters list of eligible routers.
1126 - * @param electedBdr Elected Bdr, OSPF eligible router instance.
1127 - * @return OSPF eligible router instance.
1128 - */
1129 - public OspfEligibleRouter electDr(List<OspfEligibleRouter> eligibleRouters,
1130 - OspfEligibleRouter electedBdr) {
1131 -
1132 - List<OspfEligibleRouter> declaredAsDr = new ArrayList<>();
1133 - for (OspfEligibleRouter router : eligibleRouters) {
1134 - if (router.isDr()) {
1135 - declaredAsDr.add(router);
1136 - }
1137 - }
1138 -
1139 - OspfEligibleRouter electedDr = new OspfEligibleRouter();
1140 - if (!declaredAsDr.isEmpty()) {
1141 - if (declaredAsDr.size() == 1) {
1142 - electedDr = declaredAsDr.get(0);
1143 - } else if (eligibleRouters.size() > 1) {
1144 - electedDr = selectRouterBasedOnPriority(declaredAsDr);
1145 - }
1146 - } else {
1147 - electedDr = electedBdr;
1148 - electedDr.setIsDr(true);
1149 - electedDr.setIsBdr(false);
1150 - }
1151 -
1152 - return electedDr;
1153 - }
1154 -
1155 - /**
1156 - * DR election process.
1157 - *
1158 - * @param routersList list of eligible routers.
1159 - * @return OSPF eligible router instance.
1160 - */
1161 - public OspfEligibleRouter selectRouterBasedOnPriority(List<OspfEligibleRouter> routersList) {
1162 -
1163 - OspfEligibleRouter initialRouter = routersList.get(0);
1164 -
1165 - for (int i = 1; i < routersList.size(); i++) {
1166 - OspfEligibleRouter router = routersList.get(i);
1167 - if (router.getRouterPriority() > initialRouter.getRouterPriority()) {
1168 - initialRouter = router;
1169 - } else if (router.getRouterPriority() == initialRouter.getRouterPriority()) {
1170 - try {
1171 - //if (router.getIpAddress().toInt() > initialRouter.getIpAddress().toInt()) {
1172 - if (OspfUtil.ipAddressToLong(router.getIpAddress().toString()) >
1173 - OspfUtil.ipAddressToLong(initialRouter.getIpAddress().toString())) {
1174 - initialRouter = router;
1175 - }
1176 - } catch (Exception e) {
1177 - log.debug("OSPFInterfaceChannelHandler::selectRouterBasedOnPriority ->" +
1178 - " eligibleRouters: {}", initialRouter);
1179 - }
1180 - }
1181 - }
1182 -
1183 - return initialRouter;
1184 - }
1185 -
1186 - /**
1187 - * Adds device information.
1188 - *
1189 - * @param ospfRouter OSPF router instance
1190 - */
1191 - public void addDeviceInformation(OspfRouter ospfRouter) {
1192 - controller.addDeviceDetails(ospfRouter);
1193 - }
1194 -
1195 - /**
1196 - * removes device information.
1197 - *
1198 - * @param ospfRouter OSPF neighbor instance
1199 - */
1200 - public void removeDeviceInformation(OspfRouter ospfRouter) {
1201 - controller.removeDeviceDetails(ospfRouter);
1202 - }
1203 -
1204 - /**
1205 - * Adds link information.
1206 - *
1207 - * @param ospfRouter OSPF router instance
1208 - * @param ospfLinkTed list link ted instances
1209 - */
1210 - public void addLinkInformation(OspfRouter ospfRouter, OspfLinkTed ospfLinkTed) {
1211 - controller.addLinkDetails(ospfRouter, ospfLinkTed);
1212 - }
1213 -
1214 - /**
1215 - * Removes link information.
1216 - *
1217 - * @param ospfNbr OSPF neighbor instance
1218 - */
1219 - public void removeLinkInformation(OspfNbr ospfNbr) {
1220 - controller.removeLinkDetails(buildOspfRouterDetails(ospfNbr));
1221 - }
1222 -
1223 - /**
1224 - * Builds router details.
1225 - *
1226 - * @param ospfNbr OSPF neighbor instance
1227 - * @return OSPF router instance
1228 - */
1229 - private OspfRouter buildOspfRouterDetails(OspfNbr ospfNbr) {
1230 - OspfRouter ospfRouter = new OspfRouterImpl();
1231 - ospfRouter.setRouterIp(ospfNbr.neighborId());
1232 - ospfRouter.setInterfaceId(ospfInterface.ipAddress());
1233 - ospfRouter.setAreaIdOfInterface(ospfArea.areaId());
1234 -
1235 - ospfRouter.setDeviceTed(new OspfDeviceTedImpl());
1236 -
1237 - return ospfRouter;
1238 - }
1239 -
1240 - /**
1241 - * Represents a Hello task which sent a hello message every configured time interval.
1242 - */
1243 - private class InternalHelloTimer implements Runnable {
1244 -
1245 - /**
1246 - * Creates an instance of Hello Timer.
1247 - */
1248 - InternalHelloTimer() {
1249 - }
1250 -
1251 - @Override
1252 - public void run() {
1253 - if (!isClosed && channel != null && channel.isOpen() && channel.isConnected()) {
1254 -
1255 - HelloPacket hellopacket = new HelloPacket();
1256 - //Headers
1257 - hellopacket.setOspfVer(OspfUtil.OSPF_VERSION);
1258 - hellopacket.setOspftype(OspfPacketType.HELLO.value());
1259 - hellopacket.setOspfPacLength(0); //will be modified while encoding
1260 - hellopacket.setRouterId(ospfArea.routerId());
1261 - hellopacket.setAreaId(ospfArea.areaId());
1262 - hellopacket.setChecksum(0); //will be modified while encoding
1263 - hellopacket.setAuthType(Integer.parseInt(ospfInterface.authType()));
1264 - hellopacket.setAuthentication(Integer.parseInt(ospfInterface.authKey()));
1265 - //Body
1266 - hellopacket.setNetworkMask(ospfInterface.ipNetworkMask());
1267 - hellopacket.setOptions(ospfArea.options());
1268 - hellopacket.setHelloInterval(ospfInterface.helloIntervalTime());
1269 - hellopacket.setRouterPriority(ospfInterface.routerPriority());
1270 - hellopacket.setRouterDeadInterval(ospfInterface.routerDeadIntervalTime());
1271 - hellopacket.setDr(ospfInterface.dr());
1272 - hellopacket.setBdr(ospfInterface.bdr());
1273 -
1274 - HashMap<String, OspfNbr> listOfNeighbors = ospfInterface.listOfNeighbors();
1275 - Set<String> keys = listOfNeighbors.keySet();
1276 - Iterator itr = keys.iterator();
1277 - while (itr.hasNext()) {
1278 - String nbrKey = (String) itr.next();
1279 - OspfNbrImpl nbr = (OspfNbrImpl) listOfNeighbors.get(nbrKey);
1280 - if (nbr.getState() != OspfNeighborState.DOWN) {
1281 - hellopacket.addNeighbor(Ip4Address.valueOf(nbrKey));
1282 - }
1283 - }
1284 - // build a hello Packet
1285 - if (channel == null || !channel.isOpen() || !channel.isConnected()) {
1286 - log.debug("Hello Packet not sent !!.. Channel Issue...");
1287 - return;
1288 - }
1289 -
1290 - hellopacket.setDestinationIp(OspfUtil.ALL_SPF_ROUTERS);
1291 - ChannelFuture future = channel.write(hellopacket);
1292 - if (future.isSuccess()) {
1293 - log.debug("Hello Packet successfully sent !!");
1294 - } else {
1295 - future.awaitUninterruptibly();
1296 - }
1297 -
1298 - }
1299 - }
1300 - }
1301 -
1302 - /**
1303 - * Represents a Wait Timer task which waits the interface state to become WAITING.
1304 - * It initiates DR election process.
1305 - */
1306 - private class InternalWaitTimer implements Runnable {
1307 - Channel ch;
1308 -
1309 - /**
1310 - * Creates an instance of Wait Timer.
1311 - */
1312 - InternalWaitTimer() {
1313 - this.ch = channel;
1314 - }
1315 -
1316 - @Override
1317 - public void run() {
1318 - log.debug("Wait timer expires...");
1319 - if (ch != null && ch.isConnected()) {
1320 - try {
1321 - waitTimer(ch);
1322 - } catch (Exception e) {
1323 - log.debug("Exception at wait timer ...!!!");
1324 - }
1325 -
1326 - }
1327 - }
1328 - }
1329 -
1330 - /**
1331 - * Represents a task which sent a LS Acknowledge from the link state headers list.
1332 - */
1333 - private class InternalDelayedAckTimer implements Runnable {
1334 - Channel ch;
1335 -
1336 - /**
1337 - * Creates an instance of Delayed acknowledge timer.
1338 - */
1339 - InternalDelayedAckTimer() {
1340 - this.ch = channel;
1341 - }
1342 -
1343 - @Override
1344 - public void run() {
1345 - if (!((OspfInterfaceImpl) ospfInterface).linkStateHeaders().isEmpty()) {
1346 - isDelayedAckTimerScheduled = true;
1347 - if (ch != null && ch.isConnected()) {
1348 -
1349 - List<LsaHeader> listOfLsaHeadersAcknowledged = new ArrayList<>();
1350 - List<LsaHeader> listOfLsaHeaders = ((OspfInterfaceImpl) ospfInterface).linkStateHeaders();
1351 - log.debug("Delayed Ack, Number of Lsa's to Ack {}", listOfLsaHeaders.size());
1352 - Iterator itr = listOfLsaHeaders.iterator();
1353 - while (itr.hasNext()) {
1354 - LsAcknowledge ackContent = new LsAcknowledge();
1355 - //Setting OSPF Header
1356 - ackContent.setOspfVer(OspfUtil.OSPF_VERSION);
1357 - ackContent.setOspftype(OspfPacketType.LSAACK.value());
1358 - ackContent.setRouterId(ospfArea.routerId());
1359 - ackContent.setAreaId(ospfArea.areaId());
1360 - ackContent.setAuthType(OspfUtil.NOT_ASSIGNED);
1361 - ackContent.setAuthentication(OspfUtil.NOT_ASSIGNED);
1362 - ackContent.setOspfPacLength(OspfUtil.NOT_ASSIGNED);
1363 - ackContent.setChecksum(OspfUtil.NOT_ASSIGNED);
1364 - //limit to mtu
1365 - int currentLength = OspfUtil.OSPF_HEADER_LENGTH;
1366 - int maxSize = ospfInterface.mtu() -
1367 - OspfUtil.LSA_HEADER_LENGTH; // subtract a normal IP header.
1368 - while (itr.hasNext()) {
1369 - if ((currentLength + OspfUtil.LSA_HEADER_LENGTH) >= maxSize) {
1370 - break;
1371 - }
1372 - LsaHeader lsaHeader = (LsaHeader) itr.next();
1373 - ackContent.addLinkStateHeader(lsaHeader);
1374 - currentLength = currentLength + OspfUtil.LSA_HEADER_LENGTH;
1375 - listOfLsaHeadersAcknowledged.add(lsaHeader);
1376 - log.debug("Delayed Ack, Added Lsa's to Ack {}", lsaHeader);
1377 - }
1378 -
1379 - log.debug("Delayed Ack, Number of Lsa's in LsAck packet {}",
1380 - ackContent.getLinkStateHeaders().size());
1381 -
1382 - //set the destination
1383 - if (((OspfInterfaceImpl) ospfInterface).state() == OspfInterfaceState.DR ||
1384 - ((OspfInterfaceImpl) ospfInterface).state() == OspfInterfaceState.BDR
1385 - || ((OspfInterfaceImpl) ospfInterface).state() == OspfInterfaceState.POINT2POINT) {
1386 - ackContent.setDestinationIp(OspfUtil.ALL_SPF_ROUTERS);
1387 - } else if (((OspfInterfaceImpl) ospfInterface).state() == OspfInterfaceState.DROTHER) {
1388 - ackContent.setDestinationIp(OspfUtil.ALL_DROUTERS);
1389 - }
1390 - ch.write(ackContent);
1391 - for (LsaHeader lsa : listOfLsaHeadersAcknowledged) {
1392 - ((OspfInterfaceImpl) ospfInterface).linkStateHeaders().remove(lsa);
1393 - ospfInterface.removeLsaFromNeighborMap(((OspfAreaImpl) ospfArea).getLsaKey(lsa));
1394 - }
1395 - }
1396 - }
1397 - }
1398 } 269 }
1399 } 270 }
1400 } 271 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -19,8 +19,10 @@ import org.jboss.netty.buffer.ChannelBuffer; ...@@ -19,8 +19,10 @@ import org.jboss.netty.buffer.ChannelBuffer;
19 import org.jboss.netty.channel.Channel; 19 import org.jboss.netty.channel.Channel;
20 import org.jboss.netty.channel.ChannelHandlerContext; 20 import org.jboss.netty.channel.ChannelHandlerContext;
21 import org.jboss.netty.handler.codec.frame.FrameDecoder; 21 import org.jboss.netty.handler.codec.frame.FrameDecoder;
22 -import org.onosproject.ospf.protocol.ospfpacket.OspfMessage; 22 +import org.onlab.packet.Ip4Address;
23 +import org.onosproject.ospf.controller.OspfMessage;
23 import org.onosproject.ospf.protocol.ospfpacket.OspfMessageReader; 24 import org.onosproject.ospf.protocol.ospfpacket.OspfMessageReader;
25 +import org.onosproject.ospf.protocol.util.OspfUtil;
24 import org.slf4j.Logger; 26 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory; 27 import org.slf4j.LoggerFactory;
26 28
...@@ -35,24 +37,35 @@ public class OspfMessageDecoder extends FrameDecoder { ...@@ -35,24 +37,35 @@ public class OspfMessageDecoder extends FrameDecoder {
35 private static final Logger log = LoggerFactory.getLogger(OspfMessageDecoder.class); 37 private static final Logger log = LoggerFactory.getLogger(OspfMessageDecoder.class);
36 38
37 @Override 39 @Override
38 - protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer channelBuffer) throws Exception { 40 + protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception {
39 - log.debug("OspfMessageDecoder::Message received <:> length {}", channelBuffer.readableBytes()); 41 + log.debug("OspfMessageDecoder::Message received <:> length {}", buffer.readableBytes());
40 - log.debug("channelBuffer.readableBytes - decode {}", channelBuffer.readableBytes());
41 if (!channel.isConnected()) { 42 if (!channel.isConnected()) {
42 log.info("Channel is not connected."); 43 log.info("Channel is not connected.");
43 return null; 44 return null;
44 } 45 }
45 -
46 OspfMessageReader messageReader = new OspfMessageReader(); 46 OspfMessageReader messageReader = new OspfMessageReader();
47 List<OspfMessage> ospfMessageList = new LinkedList<>(); 47 List<OspfMessage> ospfMessageList = new LinkedList<>();
48 - 48 + while (buffer.readableBytes() >= OspfUtil.MINIMUM_FRAME_LEN) {
49 - while (channelBuffer.readableBytes() > 0) { 49 + ChannelBuffer ospfDataBuffer = buffer.readBytes(OspfUtil.MINIMUM_FRAME_LEN);
50 - OspfMessage message = messageReader.readFromBuffer(channelBuffer); 50 + int readableBytes = ospfDataBuffer.readableBytes();
51 + OspfMessage message = messageReader.readFromBuffer(ospfDataBuffer);
51 if (message != null) { 52 if (message != null) {
53 + if (ospfDataBuffer.readableBytes() >= OspfUtil.METADATA_LEN) {
54 + ospfDataBuffer.readerIndex(readableBytes - OspfUtil.METADATA_LEN);
55 + log.debug("IsisMessageDecoder::Reading metadata <:> length {}", ospfDataBuffer.readableBytes());
56 +
57 +
58 + int interfaceIndex = ospfDataBuffer.readByte();
59 + byte[] sourceIpBytes = new byte[OspfUtil.FOUR_BYTES];
60 + ospfDataBuffer.readBytes(sourceIpBytes, 0, OspfUtil.FOUR_BYTES);
61 + Ip4Address sourceIP = Ip4Address.valueOf(sourceIpBytes);
62 +
63 + message.setSourceIp(sourceIP);
64 + message.setInterfaceIndex(interfaceIndex);
65 + }
52 ospfMessageList.add(message); 66 ospfMessageList.add(message);
53 } 67 }
54 } 68 }
55 - 69 + return (ospfMessageList.size() > 0) ? ospfMessageList : null;
56 - return ospfMessageList;
57 } 70 }
58 } 71 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -17,15 +17,10 @@ ...@@ -17,15 +17,10 @@
17 package org.onosproject.ospf.controller.impl; 17 package org.onosproject.ospf.controller.impl;
18 18
19 import org.jboss.netty.buffer.ChannelBuffer; 19 import org.jboss.netty.buffer.ChannelBuffer;
20 +import org.jboss.netty.buffer.ChannelBuffers;
20 import org.jboss.netty.channel.Channel; 21 import org.jboss.netty.channel.Channel;
21 import org.jboss.netty.channel.ChannelHandlerContext; 22 import org.jboss.netty.channel.ChannelHandlerContext;
22 import org.jboss.netty.handler.codec.oneone.OneToOneEncoder; 23 import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
23 -import org.onosproject.ospf.controller.OspfInterface;
24 -import org.onosproject.ospf.controller.area.OspfInterfaceImpl;
25 -import org.onosproject.ospf.protocol.ospfpacket.OspfMessage;
26 -import org.onosproject.ospf.protocol.ospfpacket.OspfMessageWriter;
27 -import org.onosproject.ospf.protocol.util.OspfInterfaceState;
28 -import org.onosproject.ospf.protocol.util.OspfUtil;
29 import org.slf4j.Logger; 24 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory; 25 import org.slf4j.LoggerFactory;
31 26
...@@ -35,46 +30,15 @@ import org.slf4j.LoggerFactory; ...@@ -35,46 +30,15 @@ import org.slf4j.LoggerFactory;
35 public class OspfMessageEncoder extends OneToOneEncoder { 30 public class OspfMessageEncoder extends OneToOneEncoder {
36 31
37 private static final Logger log = LoggerFactory.getLogger(OspfMessageEncoder.class); 32 private static final Logger log = LoggerFactory.getLogger(OspfMessageEncoder.class);
38 - private OspfInterface ospfInterface;
39 -
40 -
41 - /**
42 - * Creates an instance of OSPF message encoder.
43 - */
44 - OspfMessageEncoder() {
45 - }
46 -
47 - /**
48 - * Creates an instance of OSPF message encoder.
49 - *
50 - * @param ospfInterface OSPF interface instance
51 - */
52 - OspfMessageEncoder(OspfInterface ospfInterface) {
53 - this.ospfInterface = ospfInterface;
54 - }
55 33
56 @Override 34 @Override
57 protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { 35 protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
58 36
59 - log.debug("Encoding ospfMessage...!!!"); 37 + byte[] byteMsg = (byte[]) msg;
60 - if (!(msg instanceof OspfMessage)) { 38 + log.debug("Encoding ospfMessage of length {}", byteMsg.length);
61 - log.debug("Invalid msg."); 39 + ChannelBuffer channelBuffer = ChannelBuffers.buffer(byteMsg.length);
62 - return msg; 40 + channelBuffer.writeBytes(byteMsg);
63 - }
64 -
65 - OspfMessage ospfMessage = (OspfMessage) msg;
66 - OspfMessageWriter messageWriter = new OspfMessageWriter();
67 - if (((OspfInterfaceImpl) ospfInterface).state().equals(OspfInterfaceState.POINT2POINT)) {
68 - ospfMessage.setDestinationIp(OspfUtil.ALL_SPF_ROUTERS);
69 - }
70 - ChannelBuffer buf = messageWriter.writeToBuffer(ospfMessage,
71 - ((OspfInterfaceImpl) ospfInterface).state().value(),
72 - ospfInterface.interfaceType());
73 - log.info("OspfMessageEncoder sending packet of lenght {}", buf.readableBytes());
74 - log.debug("OspfMessageEncoder sending packet of lenght {}", buf.readableBytes());
75 - log.debug("Sending {} Message to {}, Length :: {}, <=> {}", ospfMessage.ospfMessageType(),
76 - ospfMessage.destinationIp(), buf.readableBytes(), buf.array());
77 41
78 - return buf; 42 + return channelBuffer;
79 } 43 }
80 } 44 }
......
...@@ -28,8 +28,10 @@ import org.onosproject.ospf.controller.OspfLinkTed; ...@@ -28,8 +28,10 @@ import org.onosproject.ospf.controller.OspfLinkTed;
28 import org.onosproject.ospf.controller.OspfLsa; 28 import org.onosproject.ospf.controller.OspfLsa;
29 import org.onosproject.ospf.controller.OspfLsaType; 29 import org.onosproject.ospf.controller.OspfLsaType;
30 import org.onosproject.ospf.controller.OspfLsdb; 30 import org.onosproject.ospf.controller.OspfLsdb;
31 +import org.onosproject.ospf.controller.OspfMessage;
31 import org.onosproject.ospf.controller.OspfNbr; 32 import org.onosproject.ospf.controller.OspfNbr;
32 import org.onosproject.ospf.controller.OspfNeighborState; 33 import org.onosproject.ospf.controller.OspfNeighborState;
34 +import org.onosproject.ospf.controller.OspfPacketType;
33 import org.onosproject.ospf.controller.OspfRouter; 35 import org.onosproject.ospf.controller.OspfRouter;
34 import org.onosproject.ospf.controller.TopologyForDeviceAndLink; 36 import org.onosproject.ospf.controller.TopologyForDeviceAndLink;
35 import org.onosproject.ospf.controller.area.OspfAreaImpl; 37 import org.onosproject.ospf.controller.area.OspfAreaImpl;
...@@ -40,7 +42,7 @@ import org.onosproject.ospf.protocol.lsa.LsaHeader; ...@@ -40,7 +42,7 @@ import org.onosproject.ospf.protocol.lsa.LsaHeader;
40 import org.onosproject.ospf.protocol.lsa.OpaqueLsaHeader; 42 import org.onosproject.ospf.protocol.lsa.OpaqueLsaHeader;
41 import org.onosproject.ospf.protocol.lsa.types.OpaqueLsa10; 43 import org.onosproject.ospf.protocol.lsa.types.OpaqueLsa10;
42 import org.onosproject.ospf.protocol.lsa.types.TopLevelTlv; 44 import org.onosproject.ospf.protocol.lsa.types.TopLevelTlv;
43 -import org.onosproject.ospf.protocol.ospfpacket.OspfMessage; 45 +import org.onosproject.ospf.protocol.ospfpacket.OspfMessageWriter;
44 import org.onosproject.ospf.protocol.ospfpacket.OspfPacketHeader; 46 import org.onosproject.ospf.protocol.ospfpacket.OspfPacketHeader;
45 import org.onosproject.ospf.protocol.ospfpacket.subtype.LsRequestPacket; 47 import org.onosproject.ospf.protocol.ospfpacket.subtype.LsRequestPacket;
46 import org.onosproject.ospf.protocol.ospfpacket.types.DdPacket; 48 import org.onosproject.ospf.protocol.ospfpacket.types.DdPacket;
...@@ -49,7 +51,6 @@ import org.onosproject.ospf.protocol.ospfpacket.types.LsRequest; ...@@ -49,7 +51,6 @@ import org.onosproject.ospf.protocol.ospfpacket.types.LsRequest;
49 import org.onosproject.ospf.protocol.ospfpacket.types.LsUpdate; 51 import org.onosproject.ospf.protocol.ospfpacket.types.LsUpdate;
50 import org.onosproject.ospf.protocol.util.ChecksumCalculator; 52 import org.onosproject.ospf.protocol.util.ChecksumCalculator;
51 import org.onosproject.ospf.protocol.util.OspfInterfaceState; 53 import org.onosproject.ospf.protocol.util.OspfInterfaceState;
52 -import org.onosproject.ospf.protocol.util.OspfPacketType;
53 import org.onosproject.ospf.protocol.util.OspfParameters; 54 import org.onosproject.ospf.protocol.util.OspfParameters;
54 import org.onosproject.ospf.protocol.util.OspfUtil; 55 import org.onosproject.ospf.protocol.util.OspfUtil;
55 import org.slf4j.Logger; 56 import org.slf4j.Logger;
...@@ -181,7 +182,6 @@ public class OspfNbrImpl implements OspfNbr { ...@@ -181,7 +182,6 @@ public class OspfNbrImpl implements OspfNbr {
181 * A link to the OSPF-Area this Neighbor Data Structure belongs to. 182 * A link to the OSPF-Area this Neighbor Data Structure belongs to.
182 */ 183 */
183 private OspfArea ospfArea; 184 private OspfArea ospfArea;
184 - private OspfInterfaceChannelHandler handler;
185 private List<TopLevelTlv> topLevelTlvs = new ArrayList<>(); 185 private List<TopLevelTlv> topLevelTlvs = new ArrayList<>();
186 private List<DeviceInformation> deviceInformationList = new ArrayList<>(); 186 private List<DeviceInformation> deviceInformationList = new ArrayList<>();
187 187
...@@ -195,12 +195,11 @@ public class OspfNbrImpl implements OspfNbr { ...@@ -195,12 +195,11 @@ public class OspfNbrImpl implements OspfNbr {
195 * @param ipAddr IP address 195 * @param ipAddr IP address
196 * @param routerId router id 196 * @param routerId router id
197 * @param options options 197 * @param options options
198 - * @param handler channel handler instance
199 * @param topologyForDeviceAndLinkCommon topology for device and link instance 198 * @param topologyForDeviceAndLinkCommon topology for device and link instance
200 */ 199 */
201 public OspfNbrImpl(OspfArea paramOspfArea, OspfInterface paramOspfInterface, 200 public OspfNbrImpl(OspfArea paramOspfArea, OspfInterface paramOspfInterface,
202 Ip4Address ipAddr, Ip4Address routerId, int options, 201 Ip4Address ipAddr, Ip4Address routerId, int options,
203 - OspfInterfaceChannelHandler handler, TopologyForDeviceAndLink topologyForDeviceAndLinkCommon) { 202 + TopologyForDeviceAndLink topologyForDeviceAndLinkCommon) {
204 this.ospfArea = paramOspfArea; 203 this.ospfArea = paramOspfArea;
205 this.ospfInterface = paramOspfInterface; 204 this.ospfInterface = paramOspfInterface;
206 state = OspfNeighborState.DOWN; 205 state = OspfNeighborState.DOWN;
...@@ -211,7 +210,6 @@ public class OspfNbrImpl implements OspfNbr { ...@@ -211,7 +210,6 @@ public class OspfNbrImpl implements OspfNbr {
211 this.options = options; 210 this.options = options;
212 lastDdPacket = new DdPacket(); 211 lastDdPacket = new DdPacket();
213 routerDeadInterval = paramOspfInterface.routerDeadIntervalTime(); 212 routerDeadInterval = paramOspfInterface.routerDeadIntervalTime();
214 - this.handler = handler;
215 this.topologyForDeviceAndLink = topologyForDeviceAndLinkCommon; 213 this.topologyForDeviceAndLink = topologyForDeviceAndLinkCommon;
216 } 214 }
217 215
...@@ -243,6 +241,15 @@ public class OspfNbrImpl implements OspfNbr { ...@@ -243,6 +241,15 @@ public class OspfNbrImpl implements OspfNbr {
243 } 241 }
244 242
245 /** 243 /**
244 + * Sets router dead interval.
245 + *
246 + * @param routerDeadInterval router dead interval
247 + */
248 + public void setRouterDeadInterval(int routerDeadInterval) {
249 + this.routerDeadInterval = routerDeadInterval;
250 + }
251 +
252 + /**
246 * Have seen a Neighbor, but the Neighbor doesn't know about me. 253 * Have seen a Neighbor, but the Neighbor doesn't know about me.
247 * 254 *
248 * @param ospfHello Hello Packet instance 255 * @param ospfHello Hello Packet instance
...@@ -313,7 +320,8 @@ public class OspfNbrImpl implements OspfNbr { ...@@ -313,7 +320,8 @@ public class OspfNbrImpl implements OspfNbr {
313 startRxMtDdTimer(channel); 320 startRxMtDdTimer(channel);
314 //setting destination ip 321 //setting destination ip
315 ddPacket.setDestinationIp(packet.sourceIp()); 322 ddPacket.setDestinationIp(packet.sourceIp());
316 - channel.write(ddPacket); 323 + byte[] messageToWrite = getMessage(ddPacket);
324 + channel.write(messageToWrite);
317 } else { 325 } else {
318 state = OspfNeighborState.TWOWAY; 326 state = OspfNeighborState.TWOWAY;
319 } 327 }
...@@ -409,7 +417,8 @@ public class OspfNbrImpl implements OspfNbr { ...@@ -409,7 +417,8 @@ public class OspfNbrImpl implements OspfNbr {
409 setLastSentDdPacket(ddPacket); 417 setLastSentDdPacket(ddPacket);
410 getIsMoreBit(); 418 getIsMoreBit();
411 419
412 - ch.write(lastSentDdPacket()); 420 + byte[] messageToWrite = getMessage(lastSentDdPacket);
421 + ch.write(messageToWrite);
413 } else { 422 } else {
414 // process LSA Vector's List, Add it to LSRequestList. 423 // process LSA Vector's List, Add it to LSRequestList.
415 processLsas(payload); 424 processLsas(payload);
...@@ -437,7 +446,8 @@ public class OspfNbrImpl implements OspfNbr { ...@@ -437,7 +446,8 @@ public class OspfNbrImpl implements OspfNbr {
437 setLastSentDdPacket(ddPacket); 446 setLastSentDdPacket(ddPacket);
438 getIsMoreBit(); 447 getIsMoreBit();
439 ddPacket.setDestinationIp(packet.sourceIp()); 448 ddPacket.setDestinationIp(packet.sourceIp());
440 - ch.write(lastSentDdPacket()); 449 + byte[] messageToWrite = getMessage(lastSentDdPacket);
450 + ch.write(messageToWrite);
441 startRxMtDdTimer(ch); 451 startRxMtDdTimer(ch);
442 } 452 }
443 } 453 }
...@@ -594,7 +604,8 @@ public class OspfNbrImpl implements OspfNbr { ...@@ -594,7 +604,8 @@ public class OspfNbrImpl implements OspfNbr {
594 //setting destination ip 604 //setting destination ip
595 ddPacket.setDestinationIp(neighborIpAddr()); 605 ddPacket.setDestinationIp(neighborIpAddr());
596 setLastSentDdPacket(ddPacket); 606 setLastSentDdPacket(ddPacket);
597 - ch.write(ddPacket); 607 + byte[] messageToWrite = getMessage(ddPacket);
608 + ch.write(messageToWrite);
598 } 609 }
599 } 610 }
600 611
...@@ -651,7 +662,8 @@ public class OspfNbrImpl implements OspfNbr { ...@@ -651,7 +662,8 @@ public class OspfNbrImpl implements OspfNbr {
651 getIsMoreBit(); 662 getIsMoreBit();
652 //Set the destination IP Address 663 //Set the destination IP Address
653 ddPacket.setDestinationIp(dataDescPkt.sourceIp()); 664 ddPacket.setDestinationIp(dataDescPkt.sourceIp());
654 - ch.write(lastSentDdPacket()); 665 + byte[] messageToWrite = getMessage(lastSentDdPacket());
666 + ch.write(messageToWrite);
655 667
656 startRxMtDdTimer(ch); 668 startRxMtDdTimer(ch);
657 } 669 }
...@@ -692,7 +704,8 @@ public class OspfNbrImpl implements OspfNbr { ...@@ -692,7 +704,8 @@ public class OspfNbrImpl implements OspfNbr {
692 } 704 }
693 705
694 ddPacket.setDestinationIp(dataDescPkt.sourceIp()); 706 ddPacket.setDestinationIp(dataDescPkt.sourceIp());
695 - ch.write(ddPacket); 707 + byte[] messageToWrite = getMessage(ddPacket);
708 + ch.write(messageToWrite);
696 } 709 }
697 } 710 }
698 711
...@@ -753,7 +766,8 @@ public class OspfNbrImpl implements OspfNbr { ...@@ -753,7 +766,8 @@ public class OspfNbrImpl implements OspfNbr {
753 LsRequest lsRequest = buildLsRequest(); 766 LsRequest lsRequest = buildLsRequest();
754 //Setting the destination address 767 //Setting the destination address
755 lsRequest.setDestinationIp(header.sourceIp()); 768 lsRequest.setDestinationIp(header.sourceIp());
756 - ch.write(lsRequest); 769 + byte[] messageToWrite = getMessage(lsRequest);
770 + ch.write(messageToWrite);
757 771
758 setLastSentLsrPacket(lsRequest); 772 setLastSentLsrPacket(lsRequest);
759 startRxMtLsrTimer(ch); 773 startRxMtLsrTimer(ch);
...@@ -859,7 +873,8 @@ public class OspfNbrImpl implements OspfNbr { ...@@ -859,7 +873,8 @@ public class OspfNbrImpl implements OspfNbr {
859 //setting destination ip 873 //setting destination ip
860 ddPacket.setDestinationIp(neighborIpAddr()); 874 ddPacket.setDestinationIp(neighborIpAddr());
861 setLastSentDdPacket(ddPacket); 875 setLastSentDdPacket(ddPacket);
862 - ch.write(ddPacket); 876 + byte[] messageToWrite = getMessage(ddPacket);
877 + ch.write(messageToWrite);
863 } 878 }
864 } else if (state.getValue() >= OspfNeighborState.EXSTART.getValue()) { 879 } else if (state.getValue() >= OspfNeighborState.EXSTART.getValue()) {
865 if (!formAdjacencyOrNot()) { 880 if (!formAdjacencyOrNot()) {
...@@ -942,9 +957,16 @@ public class OspfNbrImpl implements OspfNbr { ...@@ -942,9 +957,16 @@ public class OspfNbrImpl implements OspfNbr {
942 */ 957 */
943 private void callDeviceAndLinkAdding(TopologyForDeviceAndLink topologyForDeviceAndLink) { 958 private void callDeviceAndLinkAdding(TopologyForDeviceAndLink topologyForDeviceAndLink) {
944 Map<String, DeviceInformation> deviceInformationMap = topologyForDeviceAndLink.deviceInformationMap(); 959 Map<String, DeviceInformation> deviceInformationMap = topologyForDeviceAndLink.deviceInformationMap();
960 + Map<String, DeviceInformation> deviceInformationMapForPointToPoint =
961 + topologyForDeviceAndLink.deviceInformationMapForPointToPoint();
962 + Map<String, DeviceInformation> deviceInformationMapToDelete =
963 + topologyForDeviceAndLink.deviceInformationMapToDelete();
945 Map<String, LinkInformation> linkInformationMap = topologyForDeviceAndLink.linkInformationMap(); 964 Map<String, LinkInformation> linkInformationMap = topologyForDeviceAndLink.linkInformationMap();
965 + Map<String, LinkInformation> linkInformationMapForPointToPoint =
966 + topologyForDeviceAndLink.linkInformationMapForPointToPoint();
946 OspfRouter ospfRouter = new OspfRouterImpl(); 967 OspfRouter ospfRouter = new OspfRouterImpl();
947 - log.debug("Device Information in list format along with size {}", deviceInformationMap.size()); 968 +
969 + if (deviceInformationMap.size() != 0) {
948 for (String key : deviceInformationMap.keySet()) { 970 for (String key : deviceInformationMap.keySet()) {
949 DeviceInformation value = deviceInformationMap.get(key); 971 DeviceInformation value = deviceInformationMap.get(key);
950 ospfRouter.setRouterIp(value.routerId()); 972 ospfRouter.setRouterIp(value.routerId());
...@@ -964,17 +986,26 @@ public class OspfNbrImpl implements OspfNbr { ...@@ -964,17 +986,26 @@ public class OspfNbrImpl implements OspfNbr {
964 for (int i = 0; i < size; i++) { 986 for (int i = 0; i < size; i++) {
965 ospfRouter.setInterfaceId(value.interfaceId().get(i)); 987 ospfRouter.setInterfaceId(value.interfaceId().get(i));
966 } 988 }
967 - if (value.isAlreadyCreated()) { 989 + ((OspfInterfaceImpl) ospfInterface).addDeviceInformation(ospfRouter);
968 - removeDeviceDetails(value.routerId()); 990 + }
969 - OspfRouter ospfRouter1 = new OspfRouterImpl(); 991 + }
970 - ospfRouter1.setRouterIp(value.routerId()); 992 + if (deviceInformationMapForPointToPoint.size() != 0) {
971 - ospfRouter1.setInterfaceId(ospfInterface.ipAddress()); 993 + for (String key : deviceInformationMapForPointToPoint.keySet()) {
972 - ospfRouter1.setAreaIdOfInterface(ospfArea.areaId()); 994 + DeviceInformation value = deviceInformationMapForPointToPoint.get(key);
973 - ospfRouter1.setDeviceTed(new OspfDeviceTedImpl()); 995 + ospfRouter.setRouterIp(value.routerId());
974 - topologyForDeviceAndLink.removeLinks(value.routerId()); 996 + ospfRouter.setAreaIdOfInterface(ospfArea.areaId());
975 - handler.removeDeviceInformation(ospfRouter1); 997 + ospfRouter.setNeighborRouterId(value.deviceId());
998 + OspfDeviceTed ospfDeviceTed = new OspfDeviceTedImpl();
999 + List<Ip4Address> ip4Addresses = value.interfaceId();
1000 + ospfDeviceTed.setIpv4RouterIds(ip4Addresses);
1001 + ospfRouter.setDeviceTed(ospfDeviceTed);
1002 + ospfRouter.setOpaque(value.isDr());
1003 + int size = value.interfaceId().size();
1004 + for (int i = 0; i < size; i++) {
1005 + ospfRouter.setInterfaceId(value.interfaceId().get(i));
1006 + }
1007 + ((OspfInterfaceImpl) ospfInterface).addDeviceInformation(ospfRouter);
976 } 1008 }
977 - handler.addDeviceInformation(ospfRouter);
978 } 1009 }
979 for (Map.Entry<String, LinkInformation> entry : linkInformationMap.entrySet()) { 1010 for (Map.Entry<String, LinkInformation> entry : linkInformationMap.entrySet()) {
980 String key = entry.getKey(); 1011 String key = entry.getKey();
...@@ -983,8 +1014,8 @@ public class OspfNbrImpl implements OspfNbr { ...@@ -983,8 +1014,8 @@ public class OspfNbrImpl implements OspfNbr {
983 ospfRouterForLink.setInterfaceId(value.interfaceIp()); 1014 ospfRouterForLink.setInterfaceId(value.interfaceIp());
984 ospfRouterForLink.setAreaIdOfInterface(ospfArea.areaId()); 1015 ospfRouterForLink.setAreaIdOfInterface(ospfArea.areaId());
985 ospfRouterForLink.setOpaque(ospfArea.isOpaqueEnabled()); 1016 ospfRouterForLink.setOpaque(ospfArea.isOpaqueEnabled());
986 - OspfLinkTed ospfLinkTed = 1017 + OspfLinkTed ospfLinkTed = topologyForDeviceAndLink.getOspfLinkTedHashMap(
987 - topologyForDeviceAndLink.getOspfLinkTedHashMap(value.linkDestinationId().toString()); 1018 + value.linkDestinationId().toString());
988 if (ospfLinkTed == null) { 1019 if (ospfLinkTed == null) {
989 ospfLinkTed = new OspfLinkTedImpl(); 1020 ospfLinkTed = new OspfLinkTedImpl();
990 ospfLinkTed.setMaximumLink(Bandwidth.bps(0)); 1021 ospfLinkTed.setMaximumLink(Bandwidth.bps(0));
...@@ -996,13 +1027,9 @@ public class OspfNbrImpl implements OspfNbr { ...@@ -996,13 +1027,9 @@ public class OspfNbrImpl implements OspfNbr {
996 ospfRouterForLink.setRouterIp(value.linkSourceId()); 1027 ospfRouterForLink.setRouterIp(value.linkSourceId());
997 ospfRouterForLink.setNeighborRouterId(value.linkDestinationId()); 1028 ospfRouterForLink.setNeighborRouterId(value.linkDestinationId());
998 try { 1029 try {
999 - handler.addLinkInformation(ospfRouterForLink, ospfLinkTed); 1030 + ((OspfInterfaceImpl) ospfInterface).addLinkInformation(ospfRouterForLink, ospfLinkTed);
1000 - log.debug("LinkId, LinkSrc , LinkDest , LinkInterface values are : "
1001 - + value.linkId() + " , " + value.linkSourceId() + " , "
1002 - + value.linkDestinationId() + " , "
1003 - + value.interfaceIp());
1004 } catch (Exception e) { 1031 } catch (Exception e) {
1005 - log.debug("Got Exception : {}", e.getMessage()); 1032 + log.debug("Exception addLinkInformation: " + e.getMessage());
1006 } 1033 }
1007 } 1034 }
1008 } 1035 }
...@@ -1178,11 +1205,31 @@ public class OspfNbrImpl implements OspfNbr { ...@@ -1178,11 +1205,31 @@ public class OspfNbrImpl implements OspfNbr {
1178 } 1205 }
1179 } 1206 }
1180 } 1207 }
1208 +
1209 + constructDeviceInformationFromDb();
1181 callDeviceAndLinkAdding(topologyForDeviceAndLink); 1210 callDeviceAndLinkAdding(topologyForDeviceAndLink);
1211 +
1182 return true; 1212 return true;
1183 } 1213 }
1184 1214
1185 /** 1215 /**
1216 + * Constructs device and link information from link state database.
1217 + */
1218 + private void constructDeviceInformationFromDb() {
1219 + OspfLsdb database = ospfArea.database();
1220 + List lsas = database.getAllLsaHeaders(true, true);
1221 + Iterator iterator = lsas.iterator();
1222 + while (iterator.hasNext()) {
1223 + OspfLsa ospfLsa = (OspfLsa) iterator.next();
1224 + if (ospfLsa.getOspfLsaType().value() == OspfLsaType.ROUTER.value()) {
1225 + topologyForDeviceAndLink.addLocalDevice(ospfLsa, ospfInterface, ospfArea);
1226 + } else if (ospfLsa.getOspfLsaType().value() == OspfLsaType.NETWORK.value()) {
1227 + topologyForDeviceAndLink.addLocalDevice(ospfLsa, ospfInterface, ospfArea);
1228 + }
1229 + }
1230 + }
1231 +
1232 + /**
1186 * Checks Link State ID is equal to one of the router's own IP interface addresses. 1233 * Checks Link State ID is equal to one of the router's own IP interface addresses.
1187 * 1234 *
1188 * @param linkStateId link state id 1235 * @param linkStateId link state id
...@@ -1190,7 +1237,7 @@ public class OspfNbrImpl implements OspfNbr { ...@@ -1190,7 +1237,7 @@ public class OspfNbrImpl implements OspfNbr {
1190 */ 1237 */
1191 private boolean isLinkStateMatchesOwnRouterId(String linkStateId) { 1238 private boolean isLinkStateMatchesOwnRouterId(String linkStateId) {
1192 boolean isLinkStateMatches = false; 1239 boolean isLinkStateMatches = false;
1193 - List<OspfInterface> interfaceLst = ospfArea.getInterfacesLst(); 1240 + List<OspfInterface> interfaceLst = ospfArea.ospfInterfaceList();
1194 for (OspfInterface ospfInterface : interfaceLst) { 1241 for (OspfInterface ospfInterface : interfaceLst) {
1195 if (ospfInterface.ipAddress().toString().equals(linkStateId)) { 1242 if (ospfInterface.ipAddress().toString().equals(linkStateId)) {
1196 isLinkStateMatches = true; 1243 isLinkStateMatches = true;
...@@ -1262,7 +1309,8 @@ public class OspfNbrImpl implements OspfNbr { ...@@ -1262,7 +1309,8 @@ public class OspfNbrImpl implements OspfNbr {
1262 1309
1263 //setting the destination. 1310 //setting the destination.
1264 responseLsUpdate.setDestinationIp(destination); 1311 responseLsUpdate.setDestinationIp(destination);
1265 - ch.write(responseLsUpdate); 1312 + byte[] messageToWrite = getMessage(responseLsUpdate);
1313 + ch.write(messageToWrite);
1266 } 1314 }
1267 1315
1268 /** 1316 /**
...@@ -1288,7 +1336,8 @@ public class OspfNbrImpl implements OspfNbr { ...@@ -1288,7 +1336,8 @@ public class OspfNbrImpl implements OspfNbr {
1288 ackContent.addLinkStateHeader(ackLsa); 1336 ackContent.addLinkStateHeader(ackLsa);
1289 //setting the destination IP 1337 //setting the destination IP
1290 ackContent.setDestinationIp(sourceIp); 1338 ackContent.setDestinationIp(sourceIp);
1291 - ch.write(ackContent); 1339 + byte[] messageToWrite = getMessage(ackContent);
1340 + ch.write(messageToWrite);
1292 } 1341 }
1293 1342
1294 /** 1343 /**
...@@ -1314,7 +1363,7 @@ public class OspfNbrImpl implements OspfNbr { ...@@ -1314,7 +1363,7 @@ public class OspfNbrImpl implements OspfNbr {
1314 ddSummaryList.clear(); 1363 ddSummaryList.clear();
1315 if (neighborIpAddr.equals(neighborBdr) || 1364 if (neighborIpAddr.equals(neighborBdr) ||
1316 neighborIpAddr.equals(neighborDr)) { 1365 neighborIpAddr.equals(neighborDr)) {
1317 - handler.neighborChange(); 1366 + ((OspfInterfaceImpl) ospfInterface).neighborChange();
1318 } 1367 }
1319 log.debug("Neighbor Went Down : " 1368 log.debug("Neighbor Went Down : "
1320 + this.neighborIpAddr + " , " + this.neighborId); 1369 + this.neighborIpAddr + " , " + this.neighborId);
...@@ -1324,16 +1373,14 @@ public class OspfNbrImpl implements OspfNbr { ...@@ -1324,16 +1373,14 @@ public class OspfNbrImpl implements OspfNbr {
1324 ospfRouter.setInterfaceId(ospfInterface.ipAddress()); 1373 ospfRouter.setInterfaceId(ospfInterface.ipAddress());
1325 ospfRouter.setAreaIdOfInterface(ospfArea.areaId()); 1374 ospfRouter.setAreaIdOfInterface(ospfArea.areaId());
1326 ospfRouter.setDeviceTed(new OspfDeviceTedImpl()); 1375 ospfRouter.setDeviceTed(new OspfDeviceTedImpl());
1327 - handler.removeDeviceInformation(ospfRouter); 1376 + ((OspfInterfaceImpl) ospfInterface).removeDeviceInformation(ospfRouter);
1328 removeDeviceDetails(this.neighborIpAddr); 1377 removeDeviceDetails(this.neighborIpAddr);
1329 OspfRouter ospfRouter1 = new OspfRouterImpl(); 1378 OspfRouter ospfRouter1 = new OspfRouterImpl();
1330 ospfRouter1.setRouterIp(this.neighborIpAddr); 1379 ospfRouter1.setRouterIp(this.neighborIpAddr);
1331 ospfRouter1.setInterfaceId(ospfInterface.ipAddress()); 1380 ospfRouter1.setInterfaceId(ospfInterface.ipAddress());
1332 ospfRouter1.setAreaIdOfInterface(ospfArea.areaId()); 1381 ospfRouter1.setAreaIdOfInterface(ospfArea.areaId());
1333 ospfRouter1.setDeviceTed(new OspfDeviceTedImpl()); 1382 ospfRouter1.setDeviceTed(new OspfDeviceTedImpl());
1334 - handler.removeDeviceInformation(ospfRouter1); 1383 + ((OspfInterfaceImpl) ospfInterface).removeDeviceInformation(ospfRouter1);
1335 - handler.removeLinkInformation(this);
1336 - callDeviceAndLinkAdding(topologyForDeviceAndLink);
1337 } 1384 }
1338 1385
1339 /** 1386 /**
...@@ -1344,13 +1391,12 @@ public class OspfNbrImpl implements OspfNbr { ...@@ -1344,13 +1391,12 @@ public class OspfNbrImpl implements OspfNbr {
1344 private void removeDeviceDetails(Ip4Address routerId) { 1391 private void removeDeviceDetails(Ip4Address routerId) {
1345 String key = "device:" + routerId; 1392 String key = "device:" + routerId;
1346 topologyForDeviceAndLink.removeDeviceInformationMap(key); 1393 topologyForDeviceAndLink.removeDeviceInformationMap(key);
1347 - topologyForDeviceAndLink.removeLinks(routerId);
1348 } 1394 }
1349 1395
1350 /** 1396 /**
1351 * Starts the inactivity timer. 1397 * Starts the inactivity timer.
1352 */ 1398 */
1353 - private void startInactivityTimeCheck() { 1399 + public void startInactivityTimeCheck() {
1354 if (!inActivityTimerScheduled) { 1400 if (!inActivityTimerScheduled) {
1355 log.debug("OSPFNbr::startInactivityTimeCheck"); 1401 log.debug("OSPFNbr::startInactivityTimeCheck");
1356 inActivityTimeCheckTask = new InternalInactivityTimeCheck(); 1402 inActivityTimeCheckTask = new InternalInactivityTimeCheck();
...@@ -1364,7 +1410,7 @@ public class OspfNbrImpl implements OspfNbr { ...@@ -1364,7 +1410,7 @@ public class OspfNbrImpl implements OspfNbr {
1364 /** 1410 /**
1365 * Stops the inactivity timer. 1411 * Stops the inactivity timer.
1366 */ 1412 */
1367 - private void stopInactivityTimeCheck() { 1413 + public void stopInactivityTimeCheck() {
1368 if (inActivityTimerScheduled) { 1414 if (inActivityTimerScheduled) {
1369 log.debug("OSPFNbr::stopInactivityTimeCheck "); 1415 log.debug("OSPFNbr::stopInactivityTimeCheck ");
1370 exServiceInActivity.shutdown(); 1416 exServiceInActivity.shutdown();
...@@ -1393,7 +1439,7 @@ public class OspfNbrImpl implements OspfNbr { ...@@ -1393,7 +1439,7 @@ public class OspfNbrImpl implements OspfNbr {
1393 /** 1439 /**
1394 * Stops the flooding timer. 1440 * Stops the flooding timer.
1395 */ 1441 */
1396 - private void stopFloodingTimer() { 1442 + public void stopFloodingTimer() {
1397 if (floodingTimerScheduled) { 1443 if (floodingTimerScheduled) {
1398 log.debug("OSPFNbr::stopFloodingTimer "); 1444 log.debug("OSPFNbr::stopFloodingTimer ");
1399 exServiceFlooding.shutdown(); 1445 exServiceFlooding.shutdown();
...@@ -1420,7 +1466,7 @@ public class OspfNbrImpl implements OspfNbr { ...@@ -1420,7 +1466,7 @@ public class OspfNbrImpl implements OspfNbr {
1420 /** 1466 /**
1421 * Stops the Dd Retransmission executor task. 1467 * Stops the Dd Retransmission executor task.
1422 */ 1468 */
1423 - private void stopRxMtDdTimer() { 1469 + public void stopRxMtDdTimer() {
1424 if (rxmtDdPacketTimerScheduled) { 1470 if (rxmtDdPacketTimerScheduled) {
1425 exServiceRxmtDDPacket.shutdown(); 1471 exServiceRxmtDDPacket.shutdown();
1426 rxmtDdPacketTimerScheduled = false; 1472 rxmtDdPacketTimerScheduled = false;
...@@ -1447,7 +1493,7 @@ public class OspfNbrImpl implements OspfNbr { ...@@ -1447,7 +1493,7 @@ public class OspfNbrImpl implements OspfNbr {
1447 /** 1493 /**
1448 * Stops Ls request retransmission executor task. 1494 * Stops Ls request retransmission executor task.
1449 */ 1495 */
1450 - private void stopRxMtLsrTimer() { 1496 + public void stopRxMtLsrTimer() {
1451 if (rxmtLsrTimerScheduled) { 1497 if (rxmtLsrTimerScheduled) {
1452 exServiceRxmtLsr.shutdown(); 1498 exServiceRxmtLsr.shutdown();
1453 rxmtLsrTimerScheduled = false; 1499 rxmtLsrTimerScheduled = false;
...@@ -1679,6 +1725,21 @@ public class OspfNbrImpl implements OspfNbr { ...@@ -1679,6 +1725,21 @@ public class OspfNbrImpl implements OspfNbr {
1679 return pendingReTxList; 1725 return pendingReTxList;
1680 } 1726 }
1681 1727
1728 + /**
1729 + * Gets message as bytes.
1730 + *
1731 + * @param ospfMessage OSPF message
1732 + * @return OSPF message
1733 + */
1734 + private byte[] getMessage(OspfMessage ospfMessage) {
1735 + OspfMessageWriter messageWriter = new OspfMessageWriter();
1736 + if (((OspfInterfaceImpl) ospfInterface).state().equals(OspfInterfaceState.POINT2POINT)) {
1737 + ospfMessage.setDestinationIp(OspfUtil.ALL_SPF_ROUTERS);
1738 + }
1739 + return (messageWriter.getMessage(ospfMessage, ospfInterface.interfaceIndex(),
1740 + ((OspfInterfaceImpl) ospfInterface).state().value()));
1741 + }
1742 +
1682 1743
1683 /** 1744 /**
1684 * Represents a Task which will do an inactivity time check. 1745 * Represents a Task which will do an inactivity time check.
...@@ -1720,7 +1781,8 @@ public class OspfNbrImpl implements OspfNbr { ...@@ -1720,7 +1781,8 @@ public class OspfNbrImpl implements OspfNbr {
1720 public void run() { 1781 public void run() {
1721 if ((ch != null) && ch.isConnected()) { 1782 if ((ch != null) && ch.isConnected()) {
1722 DdPacket ddPacket = lastSentDdPacket(); 1783 DdPacket ddPacket = lastSentDdPacket();
1723 - ch.write(ddPacket); 1784 + byte[] messageToWrite = getMessage(ddPacket);
1785 + ch.write(messageToWrite);
1724 log.debug("Re-Transmit DD Packet ."); 1786 log.debug("Re-Transmit DD Packet .");
1725 } else { 1787 } else {
1726 log.debug( 1788 log.debug(
...@@ -1748,7 +1810,8 @@ public class OspfNbrImpl implements OspfNbr { ...@@ -1748,7 +1810,8 @@ public class OspfNbrImpl implements OspfNbr {
1748 public void run() { 1810 public void run() {
1749 if ((ch != null) && ch.isConnected()) { 1811 if ((ch != null) && ch.isConnected()) {
1750 LsRequest lsrPacket = getLastSentLsrPacket(); 1812 LsRequest lsrPacket = getLastSentLsrPacket();
1751 - ch.write(lsrPacket); 1813 + byte[] messageToWrite = getMessage(lsrPacket);
1814 + ch.write(messageToWrite);
1752 log.debug("Re-Transmit LSRequest Packet ."); 1815 log.debug("Re-Transmit LSRequest Packet .");
1753 } else { 1816 } else {
1754 log.debug( 1817 log.debug(
...@@ -1783,7 +1846,8 @@ public class OspfNbrImpl implements OspfNbr { ...@@ -1783,7 +1846,8 @@ public class OspfNbrImpl implements OspfNbr {
1783 for (LsUpdate lsupdate : lsUpdateList) { 1846 for (LsUpdate lsupdate : lsUpdateList) {
1784 //Pending for acknowledge directly sent it to neighbor 1847 //Pending for acknowledge directly sent it to neighbor
1785 lsupdate.setDestinationIp(neighborIpAddr); 1848 lsupdate.setDestinationIp(neighborIpAddr);
1786 - channel.write(lsupdate); 1849 + byte[] messageToWrite = getMessage(lsupdate);
1850 + channel.write(messageToWrite);
1787 } 1851 }
1788 } 1852 }
1789 1853
...@@ -1799,7 +1863,8 @@ public class OspfNbrImpl implements OspfNbr { ...@@ -1799,7 +1863,8 @@ public class OspfNbrImpl implements OspfNbr {
1799 (((OspfInterfaceImpl) ospfInterface).state() == OspfInterfaceState.BDR)) { 1863 (((OspfInterfaceImpl) ospfInterface).state() == OspfInterfaceState.BDR)) {
1800 lsupdate.setDestinationIp(neighborDr); 1864 lsupdate.setDestinationIp(neighborDr);
1801 } 1865 }
1802 - channel.write(lsupdate); 1866 + byte[] messageToWrite = getMessage(lsupdate);
1867 + channel.write(messageToWrite);
1803 } 1868 }
1804 } 1869 }
1805 } 1870 }
......
...@@ -18,57 +18,29 @@ package org.onosproject.ospf.controller.impl; ...@@ -18,57 +18,29 @@ package org.onosproject.ospf.controller.impl;
18 import org.jboss.netty.channel.ChannelPipeline; 18 import org.jboss.netty.channel.ChannelPipeline;
19 import org.jboss.netty.channel.ChannelPipelineFactory; 19 import org.jboss.netty.channel.ChannelPipelineFactory;
20 import org.jboss.netty.channel.Channels; 20 import org.jboss.netty.channel.Channels;
21 -import org.jboss.netty.handler.timeout.ReadTimeoutHandler;
22 -import org.jboss.netty.util.ExternalResourceReleasable;
23 -import org.jboss.netty.util.HashedWheelTimer;
24 -import org.jboss.netty.util.Timer;
25 -import org.onosproject.ospf.controller.OspfArea;
26 -import org.onosproject.ospf.controller.OspfInterface;
27 21
28 /** 22 /**
29 - * Creates a ChannelPipeline for a server-side OSPF channel. 23 + * Creates a ChannelPipeline for a client-side OSPF channel.
30 */ 24 */
31 -public class OspfPipelineFactory implements ChannelPipelineFactory, ExternalResourceReleasable { 25 +public class OspfPipelineFactory implements ChannelPipelineFactory {
32 - 26 + private OspfInterfaceChannelHandler ospfChannelHandler;
33 - private static final Timer TIMER = new HashedWheelTimer();
34 - private Controller controller;
35 - private ReadTimeoutHandler readTimeoutHandler;
36 - private OspfArea ospfArea;
37 - private OspfInterface ospfInterface;
38 - private int holdTime = 120 * 1000;
39 27
40 /** 28 /**
41 - * Creates an instance of OSPF pipeline factory. 29 + * Creates an instance of OSPF channel pipeline factory.
42 * 30 *
43 - * @param controller controller instance. 31 + * @param ospfChannelHandler OSPF channel handler instance
44 - * @param ospfArea OSPF area instance.
45 - * @param ospfInterface OSPF interface instance.
46 */ 32 */
47 - public OspfPipelineFactory(Controller controller, OspfArea ospfArea, OspfInterface ospfInterface) { 33 + public OspfPipelineFactory(OspfInterfaceChannelHandler ospfChannelHandler) {
48 - super(); 34 + this.ospfChannelHandler = ospfChannelHandler;
49 - this.controller = controller;
50 - this.ospfArea = ospfArea;
51 - this.ospfInterface = ospfInterface;
52 - readTimeoutHandler = new ReadTimeoutHandler(TIMER, holdTime);
53 } 35 }
54 36
55 @Override 37 @Override
56 public ChannelPipeline getPipeline() throws Exception { 38 public ChannelPipeline getPipeline() throws Exception {
57 - OspfInterfaceChannelHandler interfaceHandler = new OspfInterfaceChannelHandler(
58 - controller, ospfArea, ospfInterface);
59 -
60 ChannelPipeline pipeline = Channels.pipeline(); 39 ChannelPipeline pipeline = Channels.pipeline();
61 - pipeline.addLast("encoder", new OspfMessageEncoder(ospfInterface)); 40 + pipeline.addLast("encoder", new OspfMessageDecoder());
62 - pipeline.addLast("decoder", new OspfMessageDecoder()); 41 + pipeline.addLast("decoder", new OspfMessageEncoder());
63 - pipeline.addLast("holdTime", readTimeoutHandler); 42 + pipeline.addLast("handler", ospfChannelHandler);
64 - pipeline.addLast("interfacehandler", interfaceHandler);
65 43
66 return pipeline; 44 return pipeline;
67 } 45 }
68 -
69 - @Override
70 - public void releaseExternalResources() {
71 - TIMER.stop();
72 - }
73 -
74 } 46 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -38,6 +38,7 @@ import org.onosproject.ospf.protocol.lsa.types.NetworkLsa; ...@@ -38,6 +38,7 @@ import org.onosproject.ospf.protocol.lsa.types.NetworkLsa;
38 import org.onosproject.ospf.protocol.lsa.types.OpaqueLsa10; 38 import org.onosproject.ospf.protocol.lsa.types.OpaqueLsa10;
39 import org.onosproject.ospf.protocol.lsa.types.RouterLsa; 39 import org.onosproject.ospf.protocol.lsa.types.RouterLsa;
40 import org.onosproject.ospf.protocol.lsa.types.TopLevelTlv; 40 import org.onosproject.ospf.protocol.lsa.types.TopLevelTlv;
41 +import org.onosproject.ospf.protocol.util.OspfUtil;
41 import org.slf4j.Logger; 42 import org.slf4j.Logger;
42 import org.slf4j.LoggerFactory; 43 import org.slf4j.LoggerFactory;
43 44
...@@ -49,6 +50,7 @@ import java.util.LinkedHashMap; ...@@ -49,6 +50,7 @@ import java.util.LinkedHashMap;
49 import java.util.List; 50 import java.util.List;
50 import java.util.Map; 51 import java.util.Map;
51 import java.util.Set; 52 import java.util.Set;
53 +import java.util.TreeSet;
52 54
53 /** 55 /**
54 * Represents device and link topology information. 56 * Represents device and link topology information.
...@@ -56,7 +58,11 @@ import java.util.Set; ...@@ -56,7 +58,11 @@ import java.util.Set;
56 public class TopologyForDeviceAndLinkImpl implements TopologyForDeviceAndLink { 58 public class TopologyForDeviceAndLinkImpl implements TopologyForDeviceAndLink {
57 59
58 private static final Logger log = LoggerFactory.getLogger(TopologyForDeviceAndLinkImpl.class); 60 private static final Logger log = LoggerFactory.getLogger(TopologyForDeviceAndLinkImpl.class);
61 + Set<Ip4Address> routerSet = new TreeSet<Ip4Address>();
62 + Ip4Address firstValue = Ip4Address.valueOf("0.0.0.0");
59 private Map<String, DeviceInformation> deviceInformationMap = new LinkedHashMap(); 63 private Map<String, DeviceInformation> deviceInformationMap = new LinkedHashMap();
64 + private Map<Ip4Address, List<Ip4Address>> networkLsaMap = new LinkedHashMap();
65 + private Map<String, DeviceInformation> deviceInformationMapForPointToPoint = new LinkedHashMap();
60 private Map<String, DeviceInformation> deviceInformationMapToDelete = new LinkedHashMap(); 66 private Map<String, DeviceInformation> deviceInformationMapToDelete = new LinkedHashMap();
61 private HashMap<String, Set<OspfLsaLink>> deviceAndLinkInformation = new HashMap(); 67 private HashMap<String, Set<OspfLsaLink>> deviceAndLinkInformation = new HashMap();
62 private HashMap<String, OspfLinkTed> ospfLinkTedHashMap = new LinkedHashMap(); 68 private HashMap<String, OspfLinkTed> ospfLinkTedHashMap = new LinkedHashMap();
...@@ -64,6 +70,7 @@ public class TopologyForDeviceAndLinkImpl implements TopologyForDeviceAndLink { ...@@ -64,6 +70,7 @@ public class TopologyForDeviceAndLinkImpl implements TopologyForDeviceAndLink {
64 private Ip4Address drRouterOld = Ip4Address.valueOf("0.0.0.0"); 70 private Ip4Address drRouterOld = Ip4Address.valueOf("0.0.0.0");
65 private Ip4Address adRouterId = Ip4Address.valueOf("0.0.0.0"); 71 private Ip4Address adRouterId = Ip4Address.valueOf("0.0.0.0");
66 private Map<String, LinkInformation> linkInformationMap = new LinkedHashMap(); 72 private Map<String, LinkInformation> linkInformationMap = new LinkedHashMap();
73 + private Map<String, LinkInformation> linkInformationMapForPointToPoint = new LinkedHashMap();
67 private List<String> toRemove = new ArrayList<>(); 74 private List<String> toRemove = new ArrayList<>();
68 75
69 /** 76 /**
...@@ -89,9 +96,31 @@ public class TopologyForDeviceAndLinkImpl implements TopologyForDeviceAndLink { ...@@ -89,9 +96,31 @@ public class TopologyForDeviceAndLinkImpl implements TopologyForDeviceAndLink {
89 } 96 }
90 97
91 /** 98 /**
92 - * Gets device information. 99 + * Gets deviceInformation as map for Point-To-Point.
100 + *
101 + * @return deviceInformationMap
102 + */
103 + public Map<String, DeviceInformation> deviceInformationMapForPointToPoint() {
104 + return deviceInformationMapForPointToPoint;
105 + }
106 +
107 + /**
108 + * Sets deviceInformation as map for Point-To-Point..
109 + *
110 + * @param key key to store device information
111 + * @param deviceInformationMap device information instance
112 + */
113 + public void setDeviceInformationMapForPointToPoint(String key, DeviceInformation deviceInformationMap) {
114 + if (deviceInformationMap != null) {
115 + this.deviceInformationMapForPointToPoint.put(key, deviceInformationMap);
116 + }
117 +
118 + }
119 +
120 + /**
121 + * Gets deviceInformation as map.
93 * 122 *
94 - * @return device information to delete from core 123 + * @return deviceInformationMap to delete from core
95 */ 124 */
96 public Map<String, DeviceInformation> deviceInformationMapToDelete() { 125 public Map<String, DeviceInformation> deviceInformationMapToDelete() {
97 return deviceInformationMapToDelete; 126 return deviceInformationMapToDelete;
...@@ -103,8 +132,7 @@ public class TopologyForDeviceAndLinkImpl implements TopologyForDeviceAndLink { ...@@ -103,8 +132,7 @@ public class TopologyForDeviceAndLinkImpl implements TopologyForDeviceAndLink {
103 * @param key ket used to add in map 132 * @param key ket used to add in map
104 * @param deviceInformationMapToDelete map from device information to remove 133 * @param deviceInformationMapToDelete map from device information to remove
105 */ 134 */
106 - public void setDeviceInformationMapToDelete(String key, 135 + public void setDeviceInformationMapToDelete(String key, DeviceInformation deviceInformationMapToDelete) {
107 - DeviceInformation deviceInformationMapToDelete) {
108 if (deviceInformationMapToDelete != null) { 136 if (deviceInformationMapToDelete != null) {
109 this.deviceInformationMapToDelete.put(key, deviceInformationMapToDelete); 137 this.deviceInformationMapToDelete.put(key, deviceInformationMapToDelete);
110 } 138 }
...@@ -153,6 +181,11 @@ public class TopologyForDeviceAndLinkImpl implements TopologyForDeviceAndLink { ...@@ -153,6 +181,11 @@ public class TopologyForDeviceAndLinkImpl implements TopologyForDeviceAndLink {
153 return linkInformationMap; 181 return linkInformationMap;
154 } 182 }
155 183
184 + private LinkInformation getLinkInformation(String key) {
185 + LinkInformation linkInformation = this.linkInformationMap.get(key);
186 + return linkInformation;
187 + }
188 +
156 /** 189 /**
157 * Sets link information in map. 190 * Sets link information in map.
158 * 191 *
...@@ -166,9 +199,30 @@ public class TopologyForDeviceAndLinkImpl implements TopologyForDeviceAndLink { ...@@ -166,9 +199,30 @@ public class TopologyForDeviceAndLinkImpl implements TopologyForDeviceAndLink {
166 } 199 }
167 200
168 /** 201 /**
169 - * Removes Link Information from map. 202 + * Gets linkInformation as map for PointToPoint.
170 * 203 *
171 - * @param key key used to remove from map 204 + * @return linkInformationMap
205 + */
206 + public Map<String, LinkInformation> linkInformationMapForPointToPoint() {
207 + return linkInformationMap;
208 + }
209 +
210 + /**
211 + * Sets linkInformation as map for PointToPoint.
212 + *
213 + * @param key key to store link information
214 + * @param linkInformationMap link information instance
215 + */
216 + public void setLinkInformationMapForPointToPoint(String key, LinkInformation linkInformationMap) {
217 + if (!this.linkInformationMap.containsKey(key)) {
218 + this.linkInformationMap.put(key, linkInformationMap);
219 + }
220 + }
221 +
222 + /**
223 + * Removes Link Information from linkInformationMap.
224 + *
225 + * @param key key to remove link information
172 */ 226 */
173 public void removeLinkInformationMap(String key) { 227 public void removeLinkInformationMap(String key) {
174 if (this.linkInformationMap.containsKey(key)) { 228 if (this.linkInformationMap.containsKey(key)) {
...@@ -242,108 +296,136 @@ public class TopologyForDeviceAndLinkImpl implements TopologyForDeviceAndLink { ...@@ -242,108 +296,136 @@ public class TopologyForDeviceAndLinkImpl implements TopologyForDeviceAndLink {
242 List<OspfLsaLink> ospfLsaLinkList = routerLsa.routerLink(); 296 List<OspfLsaLink> ospfLsaLinkList = routerLsa.routerLink();
243 Iterator iterator = ospfLsaLinkList.iterator(); 297 Iterator iterator = ospfLsaLinkList.iterator();
244 Ip4Address advertisingRouterId = routerLsa.advertisingRouter(); 298 Ip4Address advertisingRouterId = routerLsa.advertisingRouter();
245 - adRouterId = advertisingRouterId;
246 while (iterator.hasNext()) { 299 while (iterator.hasNext()) {
247 OspfLsaLink ospfLsaLink = (OspfLsaLink) iterator.next(); 300 OspfLsaLink ospfLsaLink = (OspfLsaLink) iterator.next();
248 Ip4Address linkId = Ip4Address.valueOf(ospfLsaLink.linkId()); 301 Ip4Address linkId = Ip4Address.valueOf(ospfLsaLink.linkId());
249 Ip4Address linkData = Ip4Address.valueOf(ospfLsaLink.linkData()); 302 Ip4Address linkData = Ip4Address.valueOf(ospfLsaLink.linkData());
250 if (ospfLsaLink.linkType() == 1) { 303 if (ospfLsaLink.linkType() == 1) {
251 if ((advertisingRouterId.equals(ospfArea.routerId())) || (linkId.equals(ospfArea.routerId()))) { 304 if ((advertisingRouterId.equals(ospfArea.routerId())) || (linkId.equals(ospfArea.routerId()))) {
252 - System.out.println("OspfInterface information will not display in web "); 305 + if (!advertisingRouterId.equals(ospfArea.routerId())) {
253 - } else {
254 - removeDevice(advertisingRouterId);
255 - removeLinks(advertisingRouterId);
256 DeviceInformation deviceInformationPointToPoint = 306 DeviceInformation deviceInformationPointToPoint =
257 createDeviceInformation(false, linkId, linkId, advertisingRouterId, linkData, 307 createDeviceInformation(false, linkId, linkId, advertisingRouterId, linkData,
258 ospfArea.areaId(), false); 308 ospfArea.areaId(), false);
259 String key = "device:" + advertisingRouterId; 309 String key = "device:" + advertisingRouterId;
260 - setDeviceInformationMap(key, deviceInformationPointToPoint); 310 + setDeviceInformationMapForPointToPoint(key, deviceInformationPointToPoint);
261 - String linkIdKey = "linkId:" + advertisingRouterId + "-" + linkId;
262 - addLocalLink(linkIdKey, linkData, advertisingRouterId, linkId, true, false);
263 } 311 }
264 - } else if (ospfLsaLink.linkType() == 2) {
265 -
266 - if ((advertisingRouterId.equals(ospfArea.routerId())) || (linkId.equals(ospfArea.routerId()))) {
267 - log.debug("OspfInterface information will not display in web ");
268 - } else {
269 - if (linkId.equals(linkData)) {
270 - if (drRouter.equals(Ip4Address.valueOf("0.0.0.0"))) {
271 - log.debug("drRouter not elected {} ", drRouter.toString());
272 } else { 312 } else {
273 - if (drRouterOld.equals(linkId)) { 313 + DeviceInformation deviceInformationPointToPoint =
274 - log.debug("drRouterOld same as link id {} ", drRouterOld.toString());
275 - } else {
276 - String key = "device:" + drRouterOld;
277 - DeviceInformation deviceInformation1 = deviceInformation(key);
278 - if (deviceInformation1 != null) {
279 - deviceInformation1.setAlreadyCreated(true);
280 - setDeviceInformationMapToDelete(key, deviceInformation1);
281 - String linkIdKey = "linkId:" + linkId + "-" + deviceInformation1.neighborId();
282 - addLocalLink(linkIdKey, linkData, linkId, deviceInformation1.neighborId(),
283 - true, false);
284 - String linkIdKey1 = "linkId:" + linkId + "-" + advertisingRouterId;
285 - addLocalLink(linkIdKey1, linkData, linkId, advertisingRouterId, true, false);
286 - } else {
287 - DeviceInformation deviceInformationToDelete =
288 - createDeviceInformation(true, drRouterOld, drRouterOld,
289 - drRouterOld, drRouterOld,
290 - drRouterOld, true);
291 - setDeviceInformationMapToDelete(key, deviceInformationToDelete);
292 - String linkIdKey1 = "linkId:" + linkId + "-" + advertisingRouterId;
293 - addLocalLink(linkIdKey1, linkData, linkId, advertisingRouterId, true, false);
294 - }
295 - }
296 - }
297 - drRouter = linkId;
298 - drRouterOld = linkId;
299 - DeviceInformation deviceInformationForDr =
300 - createDeviceInformation(false, linkId, advertisingRouterId, linkId, linkData,
301 - ospfArea.areaId(), true);
302 - String key = "device:" + linkId;
303 - setDeviceInformationMap(key, deviceInformationForDr);
304 - DeviceInformation deviceInformationForAdvertisingRouter =
305 - createDeviceInformation(false, linkId, advertisingRouterId, advertisingRouterId,
306 - linkData, ospfArea.areaId(), false);
307 - String key1 = "device:" + advertisingRouterId;
308 - setDeviceInformationMap(key1, deviceInformationForAdvertisingRouter);
309 - if (drRouter.equals(Ip4Address.valueOf("0.0.0.0"))) {
310 - System.out.println("Link will not get create since dr is not valid");
311 - //Need to analysis since this place will not get Dr information
312 - String linkIdKey = "linkId:" + linkId + "-" + advertisingRouterId;
313 - addLocalLink(linkIdKey, linkData, linkId, advertisingRouterId, true, false);
314 - } else {
315 - String linkIdKey = "linkId:" + drRouter + "-" + advertisingRouterId;
316 - addLocalLink(linkIdKey, linkData, drRouter, advertisingRouterId, true, false);
317 - }
318 - } else {
319 - DeviceInformation deviceInformationDrOther =
320 createDeviceInformation(false, linkId, linkId, advertisingRouterId, 314 createDeviceInformation(false, linkId, linkId, advertisingRouterId,
321 linkData, ospfArea.areaId(), false); 315 linkData, ospfArea.areaId(), false);
322 String key = "device:" + advertisingRouterId; 316 String key = "device:" + advertisingRouterId;
323 - setDeviceInformationMap(key, deviceInformationDrOther); 317 + setDeviceInformationMapForPointToPoint(key, deviceInformationPointToPoint);
324 - if (drRouter.equals(Ip4Address.valueOf("0.0.0.0"))) { 318 + String linkIdKey = "linkId:" + advertisingRouterId + "-" + linkId;
325 - String linkIdKey = "linkId:" + linkId + "-" + advertisingRouterId; 319 + addLocalLinkForPointToPoint(linkIdKey, linkData, advertisingRouterId, linkId, true, false);
326 - addLocalLink(linkIdKey, linkData, linkId, advertisingRouterId, true, false);
327 - } else {
328 - String linkIdKey = "linkId:" + drRouter + "-" + advertisingRouterId;
329 - addLocalLink(linkIdKey, linkData, drRouter, advertisingRouterId, true, false);
330 - }
331 - }
332 } 320 }
333 } 321 }
334 } 322 }
335 } 323 }
336 324
337 /** 325 /**
338 - * Creates Device and Link instance from the NetworkLsa parameters. 326 + * Creates device and link instance from the network LSA parameters.
339 * 327 *
340 * @param ospfLsa OSPF LSA instance 328 * @param ospfLsa OSPF LSA instance
341 * @param ospfArea OSPF area instance 329 * @param ospfArea OSPF area instance
342 */ 330 */
343 private void createDeviceAndLinkFromNetworkLsa(OspfLsa ospfLsa, OspfArea ospfArea) { 331 private void createDeviceAndLinkFromNetworkLsa(OspfLsa ospfLsa, OspfArea ospfArea) {
344 NetworkLsa networkLsa = (NetworkLsa) ospfLsa; 332 NetworkLsa networkLsa = (NetworkLsa) ospfLsa;
345 - Ip4Address advertisingRouterId = networkLsa.networkMask(); 333 + Ip4Address linkStateId = Ip4Address.valueOf(networkLsa.linkStateId());
346 - System.out.println("AdvertisingRouterId is : " + advertisingRouterId); 334 + Set<Ip4Address> drList = networkLsaMap.keySet();
335 + try {
336 + Ip4Address drToReplace = null;
337 + for (Ip4Address drIp : drList) {
338 + if (!drIp.equals(linkStateId)) {
339 + if (OspfUtil.sameNetwork(drIp, linkStateId, networkLsa.networkMask())) {
340 + drToReplace = drIp;
341 + String key = "device:" + drToReplace;
342 + DeviceInformation deleteDr = deviceInformation(key);
343 + if (deleteDr != null) {
344 + deleteDr.setAlreadyCreated(true);
345 + setDeviceInformationMapToDelete(key, deleteDr);
346 + }
347 +
348 + networkLsaMap.remove(drToReplace);
349 + break;
350 + }
351 + }
352 + }
353 + networkLsaMap.put(linkStateId, networkLsa.attachedRouters());
354 +
355 + } catch (Exception e) {
356 + log.debug("Error::TopologyForDeviceAndLinkImpl:: {}", e.getMessage());
357 + }
358 + constructDeviceForBroadCastTopology(ospfArea);
359 + disp();
360 +
361 + }
362 +
363 + private void constructDeviceForBroadCastTopology(OspfArea ospfArea) {
364 +
365 + for (Map.Entry<Ip4Address, List<Ip4Address>> entry : networkLsaMap.entrySet()) {
366 + Ip4Address key = entry.getKey();
367 + DeviceInformation deviceInformationForDr = createDeviceInformation(false, key, key, key,
368 + key, ospfArea.areaId(), true);
369 + String dr = "device:" + key;
370 + setDeviceInformationMap(dr, deviceInformationForDr);
371 + List<Ip4Address> value = entry.getValue();
372 + for (Ip4Address connectedRouter : value) {
373 + if (!connectedRouter.equals(ospfArea.routerId())) {
374 + DeviceInformation deviceInformationAttachedRouters =
375 + createDeviceInformation(false, connectedRouter, key, connectedRouter,
376 + key, ospfArea.areaId(), false);
377 + String attachedRouters = "device:" + connectedRouter;
378 + setDeviceInformationMap(attachedRouters, deviceInformationAttachedRouters);
379 + String linkIdKey = "linkId:" + key + "-" + connectedRouter;
380 + addLocalLink(linkIdKey, key, key, connectedRouter, true, false);
381 + }
382 + }
383 + }
384 +
385 + }
386 +
387 + private void disp() {
388 + for (String key : deviceInformationMap.keySet()) {
389 + DeviceInformation deviceInformation = deviceInformationMap.get(key);
390 + log.debug("************************************************************************");
391 + log.debug("DeviceInfoList RouterId is : {} and neighbour is {} and linkdata {}",
392 + deviceInformation.routerId(), deviceInformation.neighborId(), deviceInformation.interfaceId());
393 + }
394 +
395 + for (Map.Entry<String, LinkInformation> entry : linkInformationMap.entrySet()) {
396 + String linkDetail = entry.getKey();
397 + log.debug("Link From and to is " + linkDetail);
398 + }
399 + log.debug("Devices Needs to delete from Core are : " + deviceInformationMapToDelete.size());
400 + for (String key : deviceInformationMapToDelete.keySet()) {
401 + DeviceInformation value = deviceInformationMapToDelete.get(key);
402 + if (value.isAlreadyCreated()) {
403 + log.debug("Device is deleted from list " + value.routerId());
404 + }
405 + }
406 + }
407 +
408 + private void getLinksToDelete(Set<Ip4Address> list, Ip4Address value, OspfArea ospfArea) {
409 +
410 + Iterator iterator = list.iterator();
411 +
412 + while (iterator.hasNext()) {
413 + Ip4Address secondValue = (Ip4Address) iterator.next();
414 + if (!value.equals("0.0.0.0")) {
415 + if ((!value.equals(secondValue))) {
416 + if ((!secondValue.equals(ospfArea.routerId()))) {
417 + String key = "link:" + value.toString() + "-" + secondValue.toString();
418 + String key1 = "link:" + secondValue.toString() + "-" + value.toString();
419 + LinkInformation linkDetails = getLinkInformation(key);
420 + LinkInformation linkDetailsOther = getLinkInformation(key1);
421 + linkInformationMapForPointToPoint.put(key, linkDetails);
422 + linkInformationMapForPointToPoint.put(key1, linkDetailsOther);
423 + }
424 + }
425 + }
426 +
427 + }
428 +
347 } 429 }
348 430
349 /** 431 /**
...@@ -444,13 +526,40 @@ public class TopologyForDeviceAndLinkImpl implements TopologyForDeviceAndLink { ...@@ -444,13 +526,40 @@ public class TopologyForDeviceAndLinkImpl implements TopologyForDeviceAndLink {
444 } 526 }
445 527
446 /** 528 /**
529 + * Adds link information to LinkInformationMap for PointToPoint.
530 + *
531 + * @param advertisingRouter advertising router
532 + * @param linkData link data
533 + * @param linkSrc link source
534 + * @param linkDest link destination
535 + * @param opaqueEnabled whether opaque is enabled or not
536 + * @param linkSrcIdNotRouterId whether link is source id or router id
537 + */
538 + public void addLocalLinkForPointToPoint(String advertisingRouter, Ip4Address linkData, Ip4Address linkSrc,
539 + Ip4Address linkDest, boolean opaqueEnabled, boolean linkSrcIdNotRouterId) {
540 + String linkKey = "link:";
541 + LinkInformation linkInformation = new LinkInformationImpl();
542 + linkInformation.setLinkId(advertisingRouter);
543 + linkInformation.setLinkSourceId(linkSrc);
544 + linkInformation.setLinkDestinationId(linkDest);
545 + linkInformation.setAlreadyCreated(false);
546 + linkInformation.setLinkSrcIdNotRouterId(linkSrcIdNotRouterId);
547 + linkInformation.setInterfaceIp(linkData);
548 + if (linkDest != null) {
549 + linkInformation.setLinkSrcIdNotRouterId(false);
550 + }
551 + linkKey = linkKey + "-" + linkSrc + "-" + linkDest;
552 + setLinkInformationMapForPointToPoint(linkKey, linkInformation);
553 + }
554 +
555 + /**
447 * Removes links from LinkInformationMap. 556 * Removes links from LinkInformationMap.
448 * 557 *
449 * @param routerId router id 558 * @param routerId router id
450 */ 559 */
451 public void removeLinks(Ip4Address routerId) { 560 public void removeLinks(Ip4Address routerId) {
452 - Map<String, LinkInformation> linkInformationMaplocal = linkInformationMap; 561 + Map<String, LinkInformation> linkInformationMapLocal = linkInformationMap;
453 - if (linkInformationMaplocal != null) { 562 + if (linkInformationMapLocal != null) {
454 for (Map.Entry<String, LinkInformation> entry : linkInformationMap.entrySet()) { 563 for (Map.Entry<String, LinkInformation> entry : linkInformationMap.entrySet()) {
455 String key = entry.getKey(); 564 String key = entry.getKey();
456 boolean check = key.contains(routerId.toString()); 565 boolean check = key.contains(routerId.toString());
......
...@@ -49,6 +49,15 @@ public class LsaWrapperImpl implements LsaWrapper { ...@@ -49,6 +49,15 @@ public class LsaWrapperImpl implements LsaWrapper {
49 private int binNumber = -1; 49 private int binNumber = -1;
50 private OspfInterface ospfInterface; 50 private OspfInterface ospfInterface;
51 private LsdbAge lsdbAge; 51 private LsdbAge lsdbAge;
52 + private int ageCounterRollOverWhenAdded;
53 +
54 + public int getAgeCounterRollOverWhenAdded() {
55 + return ageCounterRollOverWhenAdded;
56 + }
57 +
58 + public void setAgeCounterRollOverWhenAdded(int ageCounterRollOverWhenAdded) {
59 + this.ageCounterRollOverWhenAdded = ageCounterRollOverWhenAdded;
60 + }
52 61
53 /** 62 /**
54 * Gets the LSA type. 63 * Gets the LSA type.
...@@ -318,6 +327,8 @@ public class LsaWrapperImpl implements LsaWrapper { ...@@ -318,6 +327,8 @@ public class LsaWrapperImpl implements LsaWrapper {
318 327
319 if (currentAge >= OspfParameters.MAXAGE) { 328 if (currentAge >= OspfParameters.MAXAGE) {
320 return OspfParameters.MAXAGE; 329 return OspfParameters.MAXAGE;
330 + } else if ((currentAge == lsaAgeReceived) && ageCounterRollOverWhenAdded != lsdbAge.getAgeCounterRollOver()) {
331 + return OspfParameters.MAXAGE;
321 } 332 }
322 333
323 return currentAge; 334 return currentAge;
......
...@@ -41,7 +41,7 @@ public class LsdbAgeImpl implements LsdbAge { ...@@ -41,7 +41,7 @@ public class LsdbAgeImpl implements LsdbAge {
41 41
42 private static final Logger log = 42 private static final Logger log =
43 LoggerFactory.getLogger(LsdbAgeImpl.class); 43 LoggerFactory.getLogger(LsdbAgeImpl.class);
44 - protected int ageCounter = 0; 44 + protected static int ageCounter = 0;
45 private InternalAgeTimer dbAgeTimer; 45 private InternalAgeTimer dbAgeTimer;
46 private ScheduledExecutorService exServiceage; 46 private ScheduledExecutorService exServiceage;
47 // creating age bins of MAXAGE 47 // creating age bins of MAXAGE
......
...@@ -267,6 +267,7 @@ public class OspfLsdbImpl implements OspfLsdb { ...@@ -267,6 +267,7 @@ public class OspfLsdbImpl implements OspfLsdb {
267 lsaWrapper.setLsaHeader(newLsa); 267 lsaWrapper.setLsaHeader(newLsa);
268 lsaWrapper.setLsaAgeReceived(newLsa.age()); 268 lsaWrapper.setLsaAgeReceived(newLsa.age());
269 lsaWrapper.setAgeCounterWhenReceived(lsdbAge.getAgeCounter()); 269 lsaWrapper.setAgeCounterWhenReceived(lsdbAge.getAgeCounter());
270 + lsaWrapper.setAgeCounterRollOverWhenAdded(lsdbAge.getAgeCounterRollOver());
270 lsaWrapper.setIsSelfOriginated(isSelfOriginated); 271 lsaWrapper.setIsSelfOriginated(isSelfOriginated);
271 lsaWrapper.setIsSelfOriginated(isSelfOriginated); 272 lsaWrapper.setIsSelfOriginated(isSelfOriginated);
272 lsaWrapper.setOspfInterface(ospfInterface); 273 lsaWrapper.setOspfInterface(ospfInterface);
......
...@@ -15,29 +15,25 @@ ...@@ -15,29 +15,25 @@
15 */ 15 */
16 package org.onosproject.ospf.controller.area; 16 package org.onosproject.ospf.controller.area;
17 17
18 -import org.easymock.EasyMock;
19 import org.junit.After; 18 import org.junit.After;
20 import org.junit.Before; 19 import org.junit.Before;
21 import org.junit.Test; 20 import org.junit.Test;
22 import org.onlab.packet.Ip4Address; 21 import org.onlab.packet.Ip4Address;
23 -import org.onosproject.ospf.controller.OspfArea;
24 -import org.onosproject.ospf.controller.OspfAreaAddressRange;
25 import org.onosproject.ospf.controller.OspfInterface; 22 import org.onosproject.ospf.controller.OspfInterface;
26 -import org.onosproject.ospf.controller.OspfNbr;
27 import org.onosproject.ospf.controller.OspfNeighborState; 23 import org.onosproject.ospf.controller.OspfNeighborState;
28 import org.onosproject.ospf.controller.TopologyForDeviceAndLink; 24 import org.onosproject.ospf.controller.TopologyForDeviceAndLink;
29 -import org.onosproject.ospf.controller.impl.Controller;
30 -import org.onosproject.ospf.controller.impl.OspfInterfaceChannelHandler;
31 import org.onosproject.ospf.controller.impl.OspfNbrImpl; 25 import org.onosproject.ospf.controller.impl.OspfNbrImpl;
32 import org.onosproject.ospf.controller.impl.TopologyForDeviceAndLinkImpl; 26 import org.onosproject.ospf.controller.impl.TopologyForDeviceAndLinkImpl;
33 import org.onosproject.ospf.controller.lsdb.LsaWrapperImpl; 27 import org.onosproject.ospf.controller.lsdb.LsaWrapperImpl;
34 import org.onosproject.ospf.protocol.lsa.LsaHeader; 28 import org.onosproject.ospf.protocol.lsa.LsaHeader;
29 +import org.onosproject.ospf.protocol.lsa.OpaqueLsaHeader;
35 import org.onosproject.ospf.protocol.lsa.types.NetworkLsa; 30 import org.onosproject.ospf.protocol.lsa.types.NetworkLsa;
31 +import org.onosproject.ospf.protocol.lsa.types.OpaqueLsa10;
36 import org.onosproject.ospf.protocol.lsa.types.RouterLsa; 32 import org.onosproject.ospf.protocol.lsa.types.RouterLsa;
37 import org.onosproject.ospf.protocol.util.OspfInterfaceState; 33 import org.onosproject.ospf.protocol.util.OspfInterfaceState;
34 +import org.onosproject.ospf.protocol.util.OspfParameters;
38 35
39 import java.util.ArrayList; 36 import java.util.ArrayList;
40 -import java.util.HashMap;
41 import java.util.List; 37 import java.util.List;
42 38
43 import static org.hamcrest.MatcherAssert.assertThat; 39 import static org.hamcrest.MatcherAssert.assertThat;
...@@ -50,66 +46,66 @@ public class OspfAreaImplTest { ...@@ -50,66 +46,66 @@ public class OspfAreaImplTest {
50 46
51 private OspfAreaImpl ospfArea; 47 private OspfAreaImpl ospfArea;
52 private int result; 48 private int result;
53 - private OspfInterfaceImpl ospfInterface; 49 + private List<OspfInterface> ospfInterfaces = new ArrayList<>();
54 - private HashMap<String, OspfNbr> ospfNbrList;
55 - private List<OspfInterface> ospfInterfaces;
56 private OspfInterfaceImpl ospfInterface1; 50 private OspfInterfaceImpl ospfInterface1;
57 private OspfInterfaceImpl ospfInterface2; 51 private OspfInterfaceImpl ospfInterface2;
58 private OspfInterfaceImpl ospfInterface3; 52 private OspfInterfaceImpl ospfInterface3;
59 - private OspfInterfaceImpl ospfInterface4;
60 - private OspfInterfaceImpl ospfInterface5;
61 - private OspfInterfaceImpl ospfInterface6;
62 - private NetworkLsa networkLsa;
63 private OspfNbrImpl ospfNbr; 53 private OspfNbrImpl ospfNbr;
64 - private RouterLsa routerLsa; 54 + private OspfNbrImpl ospfNbr1;
65 - private List<OspfAreaAddressRange> ospfAreaAddressRanges; 55 + private NetworkLsa networkLsa;
66 private LsaHeader lsaHeader; 56 private LsaHeader lsaHeader;
57 + private Ip4Address ip4Address = Ip4Address.valueOf("10.10.10.10");
58 + private Ip4Address ip4Address1 = Ip4Address.valueOf("11.11.11.11");
59 + private Ip4Address networkAddress = Ip4Address.valueOf("255.255.255.255");
67 private TopologyForDeviceAndLink topologyForDeviceAndLink; 60 private TopologyForDeviceAndLink topologyForDeviceAndLink;
61 + private RouterLsa routerLsa;
62 + private OpaqueLsaHeader opaqueLsaHeader;
63 + private OpaqueLsa10 opaqueLsa10;
68 64
69 @Before 65 @Before
70 public void setUp() throws Exception { 66 public void setUp() throws Exception {
67 + lsaHeader = new LsaHeader();
68 + opaqueLsaHeader = new OpaqueLsaHeader();
69 + opaqueLsaHeader.setAdvertisingRouter(ip4Address);
70 + lsaHeader.setAdvertisingRouter(ip4Address);
71 + routerLsa = new RouterLsa(lsaHeader);
72 + routerLsa.setAdvertisingRouter(ip4Address);
73 + opaqueLsa10 = new OpaqueLsa10(opaqueLsaHeader);
71 ospfArea = new OspfAreaImpl(); 74 ospfArea = new OspfAreaImpl();
75 + ospfInterface1 = new OspfInterfaceImpl();
72 topologyForDeviceAndLink = new TopologyForDeviceAndLinkImpl(); 76 topologyForDeviceAndLink = new TopologyForDeviceAndLinkImpl();
77 + ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface1, ip4Address, ip4Address1,
78 + 2, topologyForDeviceAndLink);
79 + ospfNbr.setState(OspfNeighborState.EXCHANGE);
80 + ospfNbr1 = new OspfNbrImpl(ospfArea, ospfInterface1, ip4Address, ip4Address1,
81 + 2, topologyForDeviceAndLink);
82 + ospfNbr1.setState(OspfNeighborState.FULL);
83 + ospfNbr1.setNeighborId(ip4Address);
84 + ospfNbr.setNeighborId(ip4Address);
85 + ospfNbr.setIsOpaqueCapable(true);
86 + ospfInterface1.addNeighbouringRouter(ospfNbr);
87 + ospfInterface1.addNeighbouringRouter(ospfNbr1);
88 + ospfInterface2 = new OspfInterfaceImpl();
89 + ospfInterface2.setIpAddress(ip4Address);
90 + ospfInterface2.setIpNetworkMask(networkAddress);
91 + ospfInterface2.setState(OspfInterfaceState.LOOPBACK);
92 + ospfInterface2.addNeighbouringRouter(ospfNbr);
93 + ospfInterface2.addNeighbouringRouter(ospfNbr1);
94 + ospfInterfaces.add(ospfInterface2);
73 } 95 }
74 96
75 @After 97 @After
76 public void tearDown() throws Exception { 98 public void tearDown() throws Exception {
77 ospfArea = null; 99 ospfArea = null;
78 - ospfInterface = null;
79 - ospfNbrList = null;
80 ospfInterfaces = null; 100 ospfInterfaces = null;
81 - ospfAreaAddressRanges = null;
82 lsaHeader = null; 101 lsaHeader = null;
83 - routerLsa = null;
84 - ospfNbr = null;
85 networkLsa = null; 102 networkLsa = null;
86 ospfInterface1 = null; 103 ospfInterface1 = null;
87 ospfInterface2 = null; 104 ospfInterface2 = null;
88 ospfInterface3 = null; 105 ospfInterface3 = null;
89 - ospfInterface4 = null;
90 - ospfInterface5 = null;
91 - ospfInterface6 = null;
92 106
93 } 107 }
94 108
95 - /**
96 - * Tests equals() method.
97 - */
98 - @Test
99 - public void testEquals() throws Exception {
100 - ospfArea = new OspfAreaImpl();
101 - ospfInterface = new OspfInterfaceImpl();
102 - ospfArea.setTransitCapability(true);
103 - ospfArea.setExternalRoutingCapability(true);
104 - ospfArea.setStubCost(100);
105 - ospfArea.initializeDb();
106 - ospfArea.setAddressRanges(ospfAreaAddressRanges);
107 - assertThat(ospfArea.equals(ospfArea), is(true));
108 - ospfArea = EasyMock.createMock(OspfAreaImpl.class);
109 - assertThat(ospfArea.equals(ospfArea), is(true));
110 - OspfArea ospfArea = new OspfAreaImpl();
111 - assertThat(ospfArea.equals(ospfArea), is(true));
112 - }
113 109
114 /** 110 /**
115 * Tests hashCode() method. 111 * Tests hashCode() method.
...@@ -165,66 +161,6 @@ public class OspfAreaImplTest { ...@@ -165,66 +161,6 @@ public class OspfAreaImplTest {
165 assertThat(ospfArea, is(notNullValue())); 161 assertThat(ospfArea, is(notNullValue()));
166 } 162 }
167 163
168 - /**
169 - * Tests refreshArea() method.
170 - */
171 - @Test
172 - public void testRefreshArea() throws Exception {
173 -
174 - ospfInterface = new OspfInterfaceImpl();
175 - ospfInterface.setState(OspfInterfaceState.DR);
176 - ospfNbrList = new HashMap();
177 - ospfNbrList.put("1.1.1.1", new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(),
178 - Ip4Address.valueOf("1.1.1.1"),
179 - Ip4Address.valueOf("2.2.2.2"), 2,
180 - new OspfInterfaceChannelHandler(new Controller(),
181 - new OspfAreaImpl(),
182 - new OspfInterfaceImpl()),
183 - topologyForDeviceAndLink));
184 - ospfNbrList.put("2.2.2.2", new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(),
185 - Ip4Address.valueOf("1.1.1.1"),
186 - Ip4Address.valueOf("2.2.2.2"), 2,
187 - new OspfInterfaceChannelHandler(new Controller(),
188 - new OspfAreaImpl(),
189 - new OspfInterfaceImpl()),
190 - topologyForDeviceAndLink));
191 - ospfNbrList.put("3.3.3.3", new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(),
192 - Ip4Address.valueOf("1.1.1.1"),
193 - Ip4Address.valueOf("2.2.2.2"), 2,
194 - new OspfInterfaceChannelHandler(new Controller(),
195 - new OspfAreaImpl(),
196 - new OspfInterfaceImpl()),
197 - topologyForDeviceAndLink));
198 - ospfNbrList.put("4.4.4.4", new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(),
199 - Ip4Address.valueOf("1.1.1.1"),
200 - Ip4Address.valueOf("2.2.2.2"), 2,
201 - new OspfInterfaceChannelHandler(new Controller(),
202 - new OspfAreaImpl(),
203 - new OspfInterfaceImpl()),
204 - topologyForDeviceAndLink));
205 -
206 - ospfInterface.setListOfNeighbors(ospfNbrList);
207 - ospfInterface.setIpAddress(Ip4Address.valueOf("10.10.10.10"));
208 - ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
209 - ospfInterfaces = new ArrayList();
210 - ospfInterface1 = new OspfInterfaceImpl();
211 - ospfInterface1.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
212 - ospfInterfaces.add(ospfInterface1);
213 - ospfInterface2 = new OspfInterfaceImpl();
214 - ospfInterface2.setIpAddress(Ip4Address.valueOf("2.2.2.2"));
215 - ospfInterfaces.add(ospfInterface2);
216 - ospfInterface3 = new OspfInterfaceImpl();
217 - ospfInterface3.setIpAddress(Ip4Address.valueOf("3.3.3.3"));
218 - ospfInterfaces.add(ospfInterface3);
219 - ospfArea.setInterfacesLst(ospfInterfaces);
220 - ospfArea.setRouterId(Ip4Address.valueOf("111.111.111.111"));
221 - networkLsa = ospfArea.buildNetworkLsa(Ip4Address.valueOf("1.1.1.1"),
222 - Ip4Address.valueOf("255.255.255.255"));
223 - ospfArea.refreshArea(ospfInterface);
224 - assertThat(ospfNbrList.size(), is(4));
225 - assertThat(networkLsa, is(notNullValue()));
226 - assertThat(ospfArea, is(notNullValue()));
227 - }
228 164
229 /** 165 /**
230 * Tests buildNetworkLsa() method. 166 * Tests buildNetworkLsa() method.
...@@ -241,7 +177,7 @@ public class OspfAreaImplTest { ...@@ -241,7 +177,7 @@ public class OspfAreaImplTest {
241 ospfInterface3 = new OspfInterfaceImpl(); 177 ospfInterface3 = new OspfInterfaceImpl();
242 ospfInterface3.setIpAddress(Ip4Address.valueOf("3.3.3.3")); 178 ospfInterface3.setIpAddress(Ip4Address.valueOf("3.3.3.3"));
243 ospfInterfaces.add(ospfInterface3); 179 ospfInterfaces.add(ospfInterface3);
244 - ospfArea.setInterfacesLst(ospfInterfaces); 180 + ospfArea.setOspfInterfaceList(ospfInterfaces);
245 ospfArea.setRouterId(Ip4Address.valueOf("111.111.111.111")); 181 ospfArea.setRouterId(Ip4Address.valueOf("111.111.111.111"));
246 networkLsa = ospfArea.buildNetworkLsa(Ip4Address.valueOf("1.1.1.1"), 182 networkLsa = ospfArea.buildNetworkLsa(Ip4Address.valueOf("1.1.1.1"),
247 Ip4Address.valueOf("255.255.255.255")); 183 Ip4Address.valueOf("255.255.255.255"));
...@@ -250,118 +186,6 @@ public class OspfAreaImplTest { ...@@ -250,118 +186,6 @@ public class OspfAreaImplTest {
250 assertThat(ospfArea, is(notNullValue())); 186 assertThat(ospfArea, is(notNullValue()));
251 } 187 }
252 188
253 - /**
254 - * Tests buildNetworkLsa() method.
255 - */
256 - @Test
257 - public void testBuildNetworkLsa1() throws Exception {
258 - ospfInterfaces = new ArrayList();
259 - ospfInterface1 = new OspfInterfaceImpl();
260 - ospfInterface1.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
261 - ospfInterface1.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
262 - ospfInterface1.setState(OspfInterfaceState.POINT2POINT);
263 - ospfNbr = new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(),
264 - Ip4Address.valueOf("1.1.1.1"),
265 - Ip4Address.valueOf("2.2.2.2"), 2,
266 - new OspfInterfaceChannelHandler(new Controller(),
267 - new OspfAreaImpl(),
268 - new OspfInterfaceImpl()),
269 - topologyForDeviceAndLink);
270 - ospfNbr.setState(OspfNeighborState.FULL);
271 - ospfInterface1.addNeighbouringRouter(ospfNbr);
272 - ospfInterfaces.add(ospfInterface1);
273 - ospfArea.setInterfacesLst(ospfInterfaces);
274 - ospfArea.setRouterId(Ip4Address.valueOf("111.111.111.111"));
275 - networkLsa = ospfArea.buildNetworkLsa(Ip4Address.valueOf("1.1.1.1"),
276 - Ip4Address.valueOf("255.255.255.255"));
277 - assertThat(ospfInterfaces.size(), is(1));
278 - assertThat(networkLsa, is(notNullValue()));
279 - assertThat(ospfArea, is(notNullValue()));
280 - }
281 -
282 - /**
283 - * Tests buildRouterLsa() method.
284 - */
285 - @Test
286 - public void testBuildRouterLsa() throws Exception {
287 - ospfNbrList = new HashMap();
288 - ospfNbr = new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(),
289 - Ip4Address.valueOf("1.1.1.1"),
290 - Ip4Address.valueOf("2.2.2.2"), 2,
291 - new OspfInterfaceChannelHandler(new Controller(),
292 - new OspfAreaImpl(),
293 - new OspfInterfaceImpl()),
294 - topologyForDeviceAndLink);
295 - ospfNbr.setState(OspfNeighborState.FULL);
296 - ospfInterfaces = new ArrayList();
297 - ospfInterface1 = new OspfInterfaceImpl();
298 - ospfInterface1.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
299 - ospfInterface1.setState(OspfInterfaceState.DOWN);
300 - ospfInterface1.addNeighbouringRouter(ospfNbr);
301 - ospfInterfaces.add(ospfInterface1);
302 - ospfInterface2 = new OspfInterfaceImpl();
303 - ospfInterface2.setState(OspfInterfaceState.LOOPBACK);
304 - ospfInterface2.setIpAddress(Ip4Address.valueOf("2.2.2.2"));
305 - ospfInterface2.addNeighbouringRouter(ospfNbr);
306 - ospfInterfaces.add(ospfInterface2);
307 - ospfInterface3 = new OspfInterfaceImpl();
308 - ospfInterface3.setIpAddress(Ip4Address.valueOf("3.3.3.3"));
309 - ospfInterface3.setState(OspfInterfaceState.POINT2POINT);
310 - ospfInterface3.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
311 - ospfInterface3.addNeighbouringRouter(ospfNbr);
312 - ospfInterface3.setListOfNeighbors(ospfNbrList);
313 - ospfInterfaces.add(ospfInterface3);
314 - ospfInterface4 = new OspfInterfaceImpl();
315 - ospfInterface4.setState(OspfInterfaceState.WAITING);
316 - ospfInterface4.setIpAddress(Ip4Address.valueOf("3.3.3.3"));
317 - ospfInterface4.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
318 - ospfInterfaces.add(ospfInterface4);
319 - ospfInterface5 = new OspfInterfaceImpl();
320 - ospfInterface5.setState(OspfInterfaceState.DR);
321 - ospfInterface5.setIpAddress(Ip4Address.valueOf("3.3.3.3"));
322 - ospfInterfaces.add(ospfInterface5);
323 - ospfInterface6 = new OspfInterfaceImpl();
324 - ospfInterface6.setState(OspfInterfaceState.BDR);
325 - ospfInterface6.setIpAddress(Ip4Address.valueOf("3.3.3.3"));
326 - ospfInterface6.setDr(Ip4Address.valueOf("3.3.3.3"));
327 - ospfInterfaces.add(ospfInterface6);
328 - ospfArea.setInterfacesLst(ospfInterfaces);
329 - ospfArea.setRouterId(Ip4Address.valueOf("111.111.111.111"));
330 - assertThat(ospfInterfaces.size(), is(6));
331 - routerLsa = ospfArea.buildRouterLsa(ospfInterface1);
332 - assertThat(routerLsa, is(notNullValue()));
333 - routerLsa = ospfArea.buildRouterLsa(ospfInterface2);
334 - assertThat(routerLsa, is(notNullValue()));
335 - routerLsa = ospfArea.buildRouterLsa(ospfInterface3);
336 - assertThat(routerLsa, is(notNullValue()));
337 - assertThat(ospfArea, is(notNullValue()));
338 - }
339 -
340 - /**
341 - * Tests buildRouterLsa() method.
342 - */
343 - @Test
344 - public void testBuildRouterLsa1() throws Exception {
345 - ospfInterfaces = new ArrayList();
346 - ospfInterface1 = new OspfInterfaceImpl();
347 - ospfInterface1.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
348 - ospfInterface1.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
349 - ospfInterface1.setState(OspfInterfaceState.POINT2POINT);
350 - ospfNbr = new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(),
351 - Ip4Address.valueOf("1.1.1.1"),
352 - Ip4Address.valueOf("2.2.2.2"), 2,
353 - new OspfInterfaceChannelHandler(new Controller(),
354 - new OspfAreaImpl(),
355 - new OspfInterfaceImpl()),
356 - topologyForDeviceAndLink);
357 - ospfNbr.setState(OspfNeighborState.FULL);
358 - ospfInterface1.addNeighbouringRouter(ospfNbr);
359 - ospfInterfaces.add(ospfInterface1);
360 - ospfArea.setInterfacesLst(ospfInterfaces);
361 - ospfArea.setRouterId(Ip4Address.valueOf("111.111.111.111"));
362 - routerLsa = ospfArea.buildRouterLsa(ospfInterface1);
363 - assertThat(routerLsa, is(notNullValue()));
364 - }
365 189
366 /** 190 /**
367 * Tests areaId() getter method. 191 * Tests areaId() getter method.
...@@ -381,51 +205,6 @@ public class OspfAreaImplTest { ...@@ -381,51 +205,6 @@ public class OspfAreaImplTest {
381 assertThat(ospfArea.areaId(), is(Ip4Address.valueOf("1.1.1.1"))); 205 assertThat(ospfArea.areaId(), is(Ip4Address.valueOf("1.1.1.1")));
382 } 206 }
383 207
384 - /**
385 - * Tests addressRanges() getter method.
386 - */
387 - @Test
388 - public void testGetAddressRanges() throws Exception {
389 - ospfAreaAddressRanges = new ArrayList();
390 - ospfAreaAddressRanges.add(new OspfAreaAddressRangeImpl());
391 - ospfAreaAddressRanges.add(new OspfAreaAddressRangeImpl());
392 - ospfAreaAddressRanges.add(new OspfAreaAddressRangeImpl());
393 - ospfAreaAddressRanges.add(new OspfAreaAddressRangeImpl());
394 - ospfArea.setAddressRanges(ospfAreaAddressRanges);
395 - assertThat(ospfArea.addressRanges().size(), is(4));
396 - }
397 -
398 - /**
399 - * Tests addressRanges() setter method.
400 - */
401 - @Test
402 - public void testSetAddressRanges() throws Exception {
403 - ospfAreaAddressRanges = new ArrayList();
404 - ospfAreaAddressRanges.add(new OspfAreaAddressRangeImpl());
405 - ospfAreaAddressRanges.add(new OspfAreaAddressRangeImpl());
406 - ospfAreaAddressRanges.add(new OspfAreaAddressRangeImpl());
407 - ospfAreaAddressRanges.add(new OspfAreaAddressRangeImpl());
408 - ospfArea.setAddressRanges(ospfAreaAddressRanges);
409 - assertThat(ospfArea.addressRanges().size(), is(4));
410 - }
411 -
412 - /**
413 - * Tests isTransitCapability() getter method.
414 - */
415 - @Test
416 - public void testIsTransitCapability() throws Exception {
417 - ospfArea.setTransitCapability(true);
418 - assertThat(ospfArea.isTransitCapability(), is(true));
419 - }
420 -
421 - /**
422 - * Tests isTransitCapability() setter method.
423 - */
424 - @Test
425 - public void testSetTransitCapability() throws Exception {
426 - ospfArea.setTransitCapability(true);
427 - assertThat(ospfArea.isTransitCapability(), is(true));
428 - }
429 208
430 /** 209 /**
431 * Tests isExternalRoutingCapability() getter method. 210 * Tests isExternalRoutingCapability() getter method.
...@@ -445,26 +224,9 @@ public class OspfAreaImplTest { ...@@ -445,26 +224,9 @@ public class OspfAreaImplTest {
445 assertThat(ospfArea.isExternalRoutingCapability(), is(true)); 224 assertThat(ospfArea.isExternalRoutingCapability(), is(true));
446 } 225 }
447 226
448 - /**
449 - * Tests stubCost() getter method.
450 - */
451 - @Test
452 - public void testGetStubCost() throws Exception {
453 - ospfArea.setStubCost(100);
454 - assertThat(ospfArea.stubCost(), is(100));
455 - }
456 227
457 /** 228 /**
458 - * Tests stubCost() setter method. 229 + * Tests ospfInterfaceList() getter method.
459 - */
460 - @Test
461 - public void testSetStubCost() throws Exception {
462 - ospfArea.setStubCost(100);
463 - assertThat(ospfArea.stubCost(), is(100));
464 - }
465 -
466 - /**
467 - * Tests getInterfacesLst() getter method.
468 */ 230 */
469 @Test 231 @Test
470 public void testGetInterfacesLst() throws Exception { 232 public void testGetInterfacesLst() throws Exception {
...@@ -478,9 +240,9 @@ public class OspfAreaImplTest { ...@@ -478,9 +240,9 @@ public class OspfAreaImplTest {
478 ospfInterface3 = new OspfInterfaceImpl(); 240 ospfInterface3 = new OspfInterfaceImpl();
479 ospfInterface3.setIpAddress(Ip4Address.valueOf("3.3.3.3")); 241 ospfInterface3.setIpAddress(Ip4Address.valueOf("3.3.3.3"));
480 ospfInterfaces.add(ospfInterface3); 242 ospfInterfaces.add(ospfInterface3);
481 - ospfArea.setInterfacesLst(ospfInterfaces); 243 + ospfArea.setOspfInterfaceList(ospfInterfaces);
482 assertThat(ospfInterfaces.size(), is(3)); 244 assertThat(ospfInterfaces.size(), is(3));
483 - assertThat(ospfArea.getInterfacesLst(), is(notNullValue())); 245 + assertThat(ospfArea.ospfInterfaceList(), is(notNullValue()));
484 } 246 }
485 247
486 /** 248 /**
...@@ -498,32 +260,11 @@ public class OspfAreaImplTest { ...@@ -498,32 +260,11 @@ public class OspfAreaImplTest {
498 ospfInterface3 = new OspfInterfaceImpl(); 260 ospfInterface3 = new OspfInterfaceImpl();
499 ospfInterface3.setIpAddress(Ip4Address.valueOf("3.3.3.3")); 261 ospfInterface3.setIpAddress(Ip4Address.valueOf("3.3.3.3"));
500 ospfInterfaces.add(ospfInterface3); 262 ospfInterfaces.add(ospfInterface3);
501 - ospfArea.setInterfacesLst(ospfInterfaces); 263 + ospfArea.setOspfInterfaceList(ospfInterfaces);
502 assertThat(ospfInterfaces.size(), is(3)); 264 assertThat(ospfInterfaces.size(), is(3));
503 - assertThat(ospfArea.getInterfacesLst(), is(notNullValue())); 265 + assertThat(ospfArea.ospfInterfaceList(), is(notNullValue()));
504 } 266 }
505 267
506 - /**
507 - * Tests noNeighborInLsaExchangeProcess() method.
508 - */
509 - @Test
510 - public void testNoNeighborInLsaExchangeProcess() throws Exception {
511 - ospfInterfaces = new ArrayList();
512 - ospfInterface1 = new OspfInterfaceImpl();
513 - ospfInterface1.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
514 - ospfNbr = new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(),
515 - Ip4Address.valueOf("1.1.1.1"),
516 - Ip4Address.valueOf("2.2.2.2"), 2,
517 - new OspfInterfaceChannelHandler(new Controller(),
518 - new OspfAreaImpl(),
519 - new OspfInterfaceImpl()),
520 - topologyForDeviceAndLink);
521 - ospfNbr.setState(OspfNeighborState.EXCHANGE.EXCHANGE);
522 - ospfInterface1.addNeighbouringRouter(ospfNbr);
523 - ospfInterfaces.add(ospfInterface1);
524 - ospfArea.setInterfacesLst(ospfInterfaces);
525 - assertThat(ospfArea.noNeighborInLsaExchangeProcess(), is(false));
526 - }
527 268
528 /** 269 /**
529 * Tests getLsaHeaders() method. 270 * Tests getLsaHeaders() method.
...@@ -620,27 +361,6 @@ public class OspfAreaImplTest { ...@@ -620,27 +361,6 @@ public class OspfAreaImplTest {
620 assertThat(ospfArea.toString(), is(notNullValue())); 361 assertThat(ospfArea.toString(), is(notNullValue()));
621 } 362 }
622 363
623 - /**
624 - * Tests getNeighborsInFullState() method.
625 - */
626 - @Test
627 - public void testGetNeighborsinFullState() throws Exception {
628 - ospfInterfaces = new ArrayList();
629 - ospfInterface1 = new OspfInterfaceImpl();
630 - ospfInterface1.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
631 - ospfNbr = new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(),
632 - Ip4Address.valueOf("1.1.1.1"),
633 - Ip4Address.valueOf("2.2.2.2"), 2,
634 - new OspfInterfaceChannelHandler(new Controller(),
635 - new OspfAreaImpl(),
636 - new OspfInterfaceImpl()),
637 - topologyForDeviceAndLink);
638 - ospfNbr.setState(OspfNeighborState.FULL);
639 - ospfInterface1.addNeighbouringRouter(ospfNbr);
640 - ospfInterfaces.add(ospfInterface1);
641 - ospfArea.setInterfacesLst(ospfInterfaces);
642 - assertThat(ospfArea.getNeighborsInFullState(ospfInterface1).size(), is(1));
643 - }
644 364
645 /** 365 /**
646 * Tests getLsaKey() method. 366 * Tests getLsaKey() method.
...@@ -652,30 +372,6 @@ public class OspfAreaImplTest { ...@@ -652,30 +372,6 @@ public class OspfAreaImplTest {
652 assertThat(ospfArea.getLsaKey(lsaHeader), is(notNullValue())); 372 assertThat(ospfArea.getLsaKey(lsaHeader), is(notNullValue()));
653 } 373 }
654 374
655 - /**
656 - * Tests addToOtherNeighborLsaTxList() method.
657 - */
658 - @Test
659 - public void testAddToOtherNeighborLsaTxList() throws Exception {
660 - ospfInterfaces = new ArrayList();
661 - ospfInterface1 = new OspfInterfaceImpl();
662 - ospfInterface1.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
663 - ospfNbr = new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(),
664 - Ip4Address.valueOf("1.1.1.1"),
665 - Ip4Address.valueOf("2.2.2.2"), 2,
666 - new OspfInterfaceChannelHandler(new Controller(),
667 - new OspfAreaImpl(),
668 - new OspfInterfaceImpl()),
669 - topologyForDeviceAndLink);
670 - ospfNbr.setState(OspfNeighborState.FULL);
671 - ospfInterface1.addNeighbouringRouter(ospfNbr);
672 - ospfInterfaces.add(ospfInterface1);
673 - ospfArea.setInterfacesLst(ospfInterfaces);
674 - lsaHeader = new LsaHeader();
675 - lsaHeader.setAdvertisingRouter(Ip4Address.valueOf("1.1.1.1"));
676 - ospfArea.addToOtherNeighborLsaTxList(lsaHeader);
677 - assertThat(ospfArea, is(notNullValue()));
678 - }
679 375
680 /** 376 /**
681 * Tests options() getter method. 377 * Tests options() getter method.
...@@ -719,4 +415,54 @@ public class OspfAreaImplTest { ...@@ -719,4 +415,54 @@ public class OspfAreaImplTest {
719 public void testOpaqueEnabledOptionsa() throws Exception { 415 public void testOpaqueEnabledOptionsa() throws Exception {
720 assertThat(ospfArea.opaqueEnabledOptions(), is(66)); 416 assertThat(ospfArea.opaqueEnabledOptions(), is(66));
721 } 417 }
418 +
419 + /**
420 + * Tests noNeighborInLsaExchangeProcess() method.
421 + */
422 + @Test
423 + public void testNoNeighborInLsaExchangeProcess() throws Exception {
424 + ospfArea.setOspfInterfaceList(ospfInterfaces);
425 + ospfArea.noNeighborInLsaExchangeProcess();
426 + assertThat(ospfArea, is(notNullValue()));
427 + }
428 +
429 + /**
430 + * Tests getNeighborsInFullState() method.
431 + */
432 + @Test
433 + public void testGetNeighborsInFullState() throws Exception {
434 + ospfArea.getNeighborsInFullState(ospfInterface1);
435 + assertThat(ospfArea, is(notNullValue()));
436 + }
437 +
438 + /**
439 + * Tests addToOtherNeighborLsaTxList() method.
440 + */
441 + @Test
442 + public void testAddToOtherNeighborLsaTxList() throws Exception {
443 + ospfArea.setOspfInterfaceList(ospfInterfaces);
444 + ospfArea.addToOtherNeighborLsaTxList(routerLsa);
445 + assertThat(ospfArea, is(notNullValue()));
446 +
447 + opaqueLsa10.setLsType(OspfParameters.LINK_LOCAL_OPAQUE_LSA);
448 + ospfArea.addToOtherNeighborLsaTxList(opaqueLsa10);
449 + assertThat(ospfArea, is(notNullValue()));
450 + }
451 +
452 + /**
453 + * Tests buildRouterLsa() method.
454 + */
455 + @Test
456 + public void testBuildRouterLsa() throws Exception {
457 + ospfArea.setRouterId(ip4Address);
458 + ospfArea.setOspfInterfaceList(ospfInterfaces);
459 + ospfInterface1.setState(OspfInterfaceState.POINT2POINT);
460 + ospfInterface1.setIpAddress(ip4Address);
461 + ospfInterface1.setIpNetworkMask(networkAddress);
462 + ospfInterfaces.add(ospfInterface1);
463 + ospfArea.buildRouterLsa(ospfInterface1);
464 + ospfArea.setOspfInterfaceList(ospfInterfaces);
465 + assertThat(ospfArea, is(notNullValue()));
466 +
467 + }
722 } 468 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -15,21 +15,55 @@ ...@@ -15,21 +15,55 @@
15 */ 15 */
16 package org.onosproject.ospf.controller.area; 16 package org.onosproject.ospf.controller.area;
17 17
18 +import org.easymock.EasyMock;
19 +import org.jboss.netty.buffer.ChannelBuffer;
20 +import org.jboss.netty.buffer.ChannelBuffers;
21 +import org.jboss.netty.buffer.HeapChannelBufferFactory;
22 +import org.jboss.netty.channel.Channel;
23 +import org.jboss.netty.channel.ChannelConfig;
24 +import org.jboss.netty.channel.ChannelHandlerContext;
25 +import org.jboss.netty.channel.ChannelStateEvent;
18 import org.junit.After; 26 import org.junit.After;
19 import org.junit.Assert; 27 import org.junit.Assert;
20 import org.junit.Before; 28 import org.junit.Before;
21 import org.junit.Test; 29 import org.junit.Test;
22 import org.onlab.packet.Ip4Address; 30 import org.onlab.packet.Ip4Address;
31 +import org.onosproject.ospf.controller.OspfAreaAddressRange;
32 +import org.onosproject.ospf.controller.OspfInterface;
33 +import org.onosproject.ospf.controller.OspfLsaType;
34 +import org.onosproject.ospf.controller.OspfMessage;
23 import org.onosproject.ospf.controller.OspfNbr; 35 import org.onosproject.ospf.controller.OspfNbr;
36 +import org.onosproject.ospf.controller.OspfNeighborState;
37 +import org.onosproject.ospf.controller.OspfProcess;
24 import org.onosproject.ospf.controller.TopologyForDeviceAndLink; 38 import org.onosproject.ospf.controller.TopologyForDeviceAndLink;
25 import org.onosproject.ospf.controller.impl.Controller; 39 import org.onosproject.ospf.controller.impl.Controller;
26 import org.onosproject.ospf.controller.impl.OspfInterfaceChannelHandler; 40 import org.onosproject.ospf.controller.impl.OspfInterfaceChannelHandler;
41 +import org.onosproject.ospf.controller.impl.OspfLinkTedImpl;
27 import org.onosproject.ospf.controller.impl.OspfNbrImpl; 42 import org.onosproject.ospf.controller.impl.OspfNbrImpl;
43 +import org.onosproject.ospf.controller.impl.OspfRouterImpl;
28 import org.onosproject.ospf.controller.impl.TopologyForDeviceAndLinkImpl; 44 import org.onosproject.ospf.controller.impl.TopologyForDeviceAndLinkImpl;
45 +import org.onosproject.ospf.controller.util.OspfEligibleRouter;
46 +import org.onosproject.ospf.controller.util.OspfInterfaceType;
47 +import org.onosproject.ospf.exceptions.OspfParseException;
48 +import org.onosproject.ospf.protocol.lsa.LsaHeader;
29 import org.onosproject.ospf.protocol.lsa.OpaqueLsaHeader; 49 import org.onosproject.ospf.protocol.lsa.OpaqueLsaHeader;
50 +import org.onosproject.ospf.protocol.lsa.TlvHeader;
51 +import org.onosproject.ospf.protocol.lsa.tlvtypes.RouterTlv;
52 +import org.onosproject.ospf.protocol.lsa.types.OpaqueLsa10;
53 +import org.onosproject.ospf.protocol.lsa.types.RouterLsa;
54 +import org.onosproject.ospf.protocol.ospfpacket.subtype.LsRequestPacket;
55 +import org.onosproject.ospf.protocol.ospfpacket.types.DdPacket;
56 +import org.onosproject.ospf.protocol.ospfpacket.types.HelloPacket;
57 +import org.onosproject.ospf.protocol.ospfpacket.types.LsAcknowledge;
58 +import org.onosproject.ospf.protocol.ospfpacket.types.LsRequest;
59 +import org.onosproject.ospf.protocol.ospfpacket.types.LsUpdate;
60 +import org.onosproject.ospf.protocol.util.ChecksumCalculator;
30 import org.onosproject.ospf.protocol.util.OspfInterfaceState; 61 import org.onosproject.ospf.protocol.util.OspfInterfaceState;
31 62
63 +import java.net.UnknownHostException;
64 +import java.util.ArrayList;
32 import java.util.HashMap; 65 import java.util.HashMap;
66 +import java.util.List;
33 67
34 import static org.hamcrest.MatcherAssert.assertThat; 68 import static org.hamcrest.MatcherAssert.assertThat;
35 import static org.hamcrest.Matchers.is; 69 import static org.hamcrest.Matchers.is;
...@@ -39,18 +73,54 @@ import static org.hamcrest.Matchers.notNullValue; ...@@ -39,18 +73,54 @@ import static org.hamcrest.Matchers.notNullValue;
39 * Unit test class for OspfInterfaceImpl. 73 * Unit test class for OspfInterfaceImpl.
40 */ 74 */
41 public class OspfInterfaceImplTest { 75 public class OspfInterfaceImplTest {
42 - 76 + private List<OspfAreaAddressRange> addressRanges = new ArrayList();
77 + private List<OspfInterface> ospfInterfaces = new ArrayList();
43 private OspfInterfaceImpl ospfInterface; 78 private OspfInterfaceImpl ospfInterface;
44 private OspfNbrImpl ospfNbr; 79 private OspfNbrImpl ospfNbr;
45 private OpaqueLsaHeader opaqueLsaHeader; 80 private OpaqueLsaHeader opaqueLsaHeader;
46 private int result; 81 private int result;
82 + private OspfAreaImpl ospfArea;
47 private HashMap<String, OspfNbr> ospfNbrHashMap; 83 private HashMap<String, OspfNbr> ospfNbrHashMap;
48 private TopologyForDeviceAndLink topologyForDeviceAndLink; 84 private TopologyForDeviceAndLink topologyForDeviceAndLink;
85 + private Channel channel;
86 + private ChannelHandlerContext channelHandlerContext;
87 + private ChannelStateEvent channelStateEvent;
88 + private HelloPacket helloPacket;
89 + private DdPacket ddPacket;
90 + private ChecksumCalculator checksumCalculator;
91 + private byte[] byteArray;
92 + private byte[] checkArray;
93 + private OspfInterfaceChannelHandler ospfInterfaceChannelHandler;
94 + private LsRequest lsRequest;
95 + private ChannelBuffer buf;
96 + private LsUpdate lsUpdate;
97 + private LsAcknowledge lsAck;
98 + private Controller controller;
99 + private List<OspfProcess> ospfProcesses = new ArrayList();
100 + private OspfProcess ospfProcess;
101 + private OspfEligibleRouter ospfEligibleRouter;
49 102
50 @Before 103 @Before
51 public void setUp() throws Exception { 104 public void setUp() throws Exception {
105 + ospfProcess = new OspfProcessImpl();
106 + ospfProcesses.add(ospfProcess);
52 ospfInterface = new OspfInterfaceImpl(); 107 ospfInterface = new OspfInterfaceImpl();
53 topologyForDeviceAndLink = new TopologyForDeviceAndLinkImpl(); 108 topologyForDeviceAndLink = new TopologyForDeviceAndLinkImpl();
109 + channel = EasyMock.createMock(Channel.class);
110 + ospfArea = createOspfArea();
111 + ospfInterface = createOspfInterface();
112 + ospfNbrHashMap = new HashMap();
113 + topologyForDeviceAndLink = new TopologyForDeviceAndLinkImpl();
114 + ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("10.10.10.10"),
115 + Ip4Address.valueOf("2.2.2.2"), 2,
116 + topologyForDeviceAndLink);
117 + ospfNbr.setNeighborId(Ip4Address.valueOf("10.10.10.10"));
118 + ospfNbr.setRouterPriority(0);
119 + ospfNbr.setNeighborDr(Ip4Address.valueOf("13.13.13.13"));
120 + ospfInterface.addNeighbouringRouter(ospfNbr);
121 + controller = new Controller();
122 + ospfInterfaceChannelHandler = new OspfInterfaceChannelHandler(controller, ospfProcesses);
123 +
54 } 124 }
55 125
56 @After 126 @After
...@@ -113,8 +183,6 @@ public class OspfInterfaceImplTest { ...@@ -113,8 +183,6 @@ public class OspfInterfaceImplTest {
113 public void testAddNeighbouringRouter() throws Exception { 183 public void testAddNeighbouringRouter() throws Exception {
114 ospfNbr = new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(), 184 ospfNbr = new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(),
115 Ip4Address.valueOf("1.1.1.1"), Ip4Address.valueOf("2.2.2.2"), 2, 185 Ip4Address.valueOf("1.1.1.1"), Ip4Address.valueOf("2.2.2.2"), 2,
116 - new OspfInterfaceChannelHandler(new Controller(), new OspfAreaImpl(),
117 - new OspfInterfaceImpl()),
118 topologyForDeviceAndLink); 186 topologyForDeviceAndLink);
119 ospfNbr.setNeighborId(Ip4Address.valueOf("111.111.111.111")); 187 ospfNbr.setNeighborId(Ip4Address.valueOf("111.111.111.111"));
120 ospfInterface.addNeighbouringRouter(ospfNbr); 188 ospfInterface.addNeighbouringRouter(ospfNbr);
...@@ -129,8 +197,6 @@ public class OspfInterfaceImplTest { ...@@ -129,8 +197,6 @@ public class OspfInterfaceImplTest {
129 public void testGetNeighbouringRouter() throws Exception { 197 public void testGetNeighbouringRouter() throws Exception {
130 ospfNbr = new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(), 198 ospfNbr = new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(),
131 Ip4Address.valueOf("1.1.1.1"), Ip4Address.valueOf("2.2.2.2"), 2, 199 Ip4Address.valueOf("1.1.1.1"), Ip4Address.valueOf("2.2.2.2"), 2,
132 - new OspfInterfaceChannelHandler(new Controller(), new OspfAreaImpl(),
133 - new OspfInterfaceImpl()),
134 topologyForDeviceAndLink); 200 topologyForDeviceAndLink);
135 ospfNbr.setNeighborId(Ip4Address.valueOf("111.111.111.111")); 201 ospfNbr.setNeighborId(Ip4Address.valueOf("111.111.111.111"));
136 ospfInterface.addNeighbouringRouter(ospfNbr); 202 ospfInterface.addNeighbouringRouter(ospfNbr);
...@@ -164,8 +230,6 @@ public class OspfInterfaceImplTest { ...@@ -164,8 +230,6 @@ public class OspfInterfaceImplTest {
164 public void testIsNeighborinList() throws Exception { 230 public void testIsNeighborinList() throws Exception {
165 ospfNbr = new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(), 231 ospfNbr = new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(),
166 Ip4Address.valueOf("1.1.1.1"), Ip4Address.valueOf("2.2.2.2"), 2, 232 Ip4Address.valueOf("1.1.1.1"), Ip4Address.valueOf("2.2.2.2"), 2,
167 - new OspfInterfaceChannelHandler(new Controller(), new OspfAreaImpl(),
168 - new OspfInterfaceImpl()),
169 topologyForDeviceAndLink); 233 topologyForDeviceAndLink);
170 ospfNbr.setNeighborId(Ip4Address.valueOf("111.111.111.111")); 234 ospfNbr.setNeighborId(Ip4Address.valueOf("111.111.111.111"));
171 ospfInterface.addNeighbouringRouter(ospfNbr); 235 ospfInterface.addNeighbouringRouter(ospfNbr);
...@@ -180,9 +244,6 @@ public class OspfInterfaceImplTest { ...@@ -180,9 +244,6 @@ public class OspfInterfaceImplTest {
180 ospfNbrHashMap = new HashMap(); 244 ospfNbrHashMap = new HashMap();
181 ospfNbr = new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(), 245 ospfNbr = new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(),
182 Ip4Address.valueOf("1.1.1.1"), Ip4Address.valueOf("2.2.2.2"), 2, 246 Ip4Address.valueOf("1.1.1.1"), Ip4Address.valueOf("2.2.2.2"), 2,
183 - new OspfInterfaceChannelHandler(new Controller(),
184 - new OspfAreaImpl(),
185 - new OspfInterfaceImpl()),
186 topologyForDeviceAndLink); 247 topologyForDeviceAndLink);
187 ospfNbr.setNeighborId(Ip4Address.valueOf("111.111.111.111")); 248 ospfNbr.setNeighborId(Ip4Address.valueOf("111.111.111.111"));
188 ospfNbrHashMap.put("111.111.111.111", ospfNbr); 249 ospfNbrHashMap.put("111.111.111.111", ospfNbr);
...@@ -198,8 +259,6 @@ public class OspfInterfaceImplTest { ...@@ -198,8 +259,6 @@ public class OspfInterfaceImplTest {
198 ospfNbrHashMap = new HashMap(); 259 ospfNbrHashMap = new HashMap();
199 ospfNbr = new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(), 260 ospfNbr = new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(),
200 Ip4Address.valueOf("1.1.1.1"), Ip4Address.valueOf("2.2.2.2"), 2, 261 Ip4Address.valueOf("1.1.1.1"), Ip4Address.valueOf("2.2.2.2"), 2,
201 - new OspfInterfaceChannelHandler(new Controller(), new OspfAreaImpl(),
202 - new OspfInterfaceImpl()),
203 topologyForDeviceAndLink); 262 topologyForDeviceAndLink);
204 ospfNbr.setNeighborId(Ip4Address.valueOf("111.111.111.111")); 263 ospfNbr.setNeighborId(Ip4Address.valueOf("111.111.111.111"));
205 ospfNbrHashMap.put("111.111.111.111", ospfNbr); 264 ospfNbrHashMap.put("111.111.111.111", ospfNbr);
...@@ -244,24 +303,6 @@ public class OspfInterfaceImplTest { ...@@ -244,24 +303,6 @@ public class OspfInterfaceImplTest {
244 } 303 }
245 304
246 /** 305 /**
247 - * Tests areaId() getter method.
248 - */
249 - @Test
250 - public void testGetAreaId() throws Exception {
251 - ospfInterface.setAreaId(1);
252 - assertThat(ospfInterface.areaId(), is(1));
253 - }
254 -
255 - /**
256 - * Tests areaId() setter method.
257 - */
258 - @Test
259 - public void testSetAreaId() throws Exception {
260 - ospfInterface.setAreaId(1);
261 - assertThat(ospfInterface.areaId(), is(1));
262 - }
263 -
264 - /**
265 * Tests helloIntervalTime() getter method. 306 * Tests helloIntervalTime() getter method.
266 */ 307 */
267 @Test 308 @Test
...@@ -316,189 +357,1116 @@ public class OspfInterfaceImplTest { ...@@ -316,189 +357,1116 @@ public class OspfInterfaceImplTest {
316 } 357 }
317 358
318 /** 359 /**
319 - * Tests interfaceCost() getter method. 360 + * Tests mtu() getter method.
320 */ 361 */
321 @Test 362 @Test
322 - public void testGetInterfaceCost() throws Exception { 363 + public void testGetMtu() throws Exception {
323 - ospfInterface.setInterfaceCost(100); 364 + ospfInterface.setMtu(100);
324 - assertThat(ospfInterface.interfaceCost(), is(100)); 365 + assertThat(ospfInterface.mtu(), is(100));
325 } 366 }
326 367
327 /** 368 /**
328 - * Tests interfaceCost() setter method. 369 + * Tests mtu() setter method.
329 */ 370 */
330 @Test 371 @Test
331 - public void testSetInterfaceCost() throws Exception { 372 + public void testSetMtu() throws Exception {
332 - ospfInterface.setInterfaceCost(100); 373 + ospfInterface.setMtu(100);
333 - assertThat(ospfInterface.interfaceCost(), is(100)); 374 + assertThat(ospfInterface.mtu(), is(100));
334 } 375 }
335 376
336 /** 377 /**
337 - * Tests authType() getter method. 378 + * Tests reTransmitInterval() getter method.
338 */ 379 */
339 @Test 380 @Test
340 - public void testGetAuthType() throws Exception { 381 + public void testGetReTransmitInterval() throws Exception {
341 - ospfInterface.setAuthType("00"); 382 + ospfInterface.setReTransmitInterval(100);
342 - assertThat(ospfInterface.authType(), is("00")); 383 + assertThat(ospfInterface.reTransmitInterval(), is(100));
343 } 384 }
344 385
345 /** 386 /**
346 - * Tests authType() setter method. 387 + * Tests reTransmitInterval() setter method.
347 */ 388 */
348 @Test 389 @Test
349 - public void testSetAuthType() throws Exception { 390 + public void testSetReTransmitInterval() throws Exception {
350 - ospfInterface.setAuthType("00"); 391 + ospfInterface.setReTransmitInterval(100);
351 - assertThat(ospfInterface.authType(), is("00")); 392 + assertThat(ospfInterface.reTransmitInterval(), is(100));
352 } 393 }
353 394
354 /** 395 /**
355 - * Tests authKey() getter method. 396 + * Tests dr() getter method.
356 */ 397 */
357 @Test 398 @Test
358 - public void testGetAuthKey() throws Exception { 399 + public void testGetDr() throws Exception {
359 - ospfInterface.setAuthKey("00"); 400 + ospfInterface.setDr(Ip4Address.valueOf("1.1.1.1"));
360 - assertThat(ospfInterface.authKey(), is("00")); 401 + assertThat(ospfInterface.dr(), is(Ip4Address.valueOf("1.1.1.1")));
361 } 402 }
362 403
363 /** 404 /**
364 - * Tests authKey() setter method. 405 + * Tests dr() setter method.
365 */ 406 */
366 @Test 407 @Test
367 - public void testSetAuthKey() throws Exception { 408 + public void testSetDr() throws Exception {
368 - ospfInterface.setAuthKey("00"); 409 + ospfInterface.setDr(Ip4Address.valueOf("1.1.1.1"));
369 - assertThat(ospfInterface.authKey(), is("00")); 410 + assertThat(ospfInterface.dr(), is(Ip4Address.valueOf("1.1.1.1")));
370 } 411 }
371 412
372 /** 413 /**
373 - * Tests pollInterval() getter method. 414 + * Tests bdr() getter method.
374 */ 415 */
375 @Test 416 @Test
376 - public void testGetPollInterval() throws Exception { 417 + public void testGetBdr() throws Exception {
377 - ospfInterface.setPollInterval(100); 418 + ospfInterface.setBdr(Ip4Address.valueOf("1.1.1.1"));
378 - assertThat(ospfInterface.pollInterval(), is(100)); 419 + assertThat(ospfInterface.bdr(), is(Ip4Address.valueOf("1.1.1.1")));
379 } 420 }
380 421
381 /** 422 /**
382 - * Tests pollInterval() setter method. 423 + * Tests bdr() setter method.
383 */ 424 */
384 @Test 425 @Test
385 - public void testSetPollInterval() throws Exception { 426 + public void testSetBdr() throws Exception {
386 - ospfInterface.setPollInterval(100); 427 + ospfInterface.setBdr(Ip4Address.valueOf("1.1.1.1"));
387 - assertThat(ospfInterface.pollInterval(), is(100)); 428 + assertThat(ospfInterface.bdr(), is(Ip4Address.valueOf("1.1.1.1")));
388 } 429 }
389 430
390 /** 431 /**
391 - * Tests mtu() getter method. 432 + * Tests equals() method.
392 */ 433 */
393 @Test 434 @Test
394 - public void testGetMtu() throws Exception { 435 + public void testEquals() throws Exception {
395 - ospfInterface.setMtu(100); 436 + assertThat(ospfInterface.equals(new OspfInterfaceImpl()), is(false));
396 - assertThat(ospfInterface.mtu(), is(100));
397 } 437 }
398 438
399 /** 439 /**
400 - * Tests mtu() setter method. 440 + * Tests hashCode() method.
401 */ 441 */
402 @Test 442 @Test
403 - public void testSetMtu() throws Exception { 443 + public void testHashCode() throws Exception {
404 - ospfInterface.setMtu(100); 444 + result = ospfInterface.hashCode();
405 - assertThat(ospfInterface.mtu(), is(100)); 445 + assertThat(result, is(notNullValue()));
406 } 446 }
407 447
408 /** 448 /**
409 - * Tests reTransmitInterval() getter method. 449 + * Tests to string method.
410 */ 450 */
411 @Test 451 @Test
412 - public void testGetReTransmitInterval() throws Exception { 452 + public void testToString() throws Exception {
413 - ospfInterface.setReTransmitInterval(100); 453 + assertThat(ospfInterface.toString(), is(notNullValue()));
414 - assertThat(ospfInterface.reTransmitInterval(), is(100));
415 } 454 }
416 455
417 /** 456 /**
418 - * Tests reTransmitInterval() setter method. 457 + * Tests to interfaceUp() method.
458 + */
459 + @Test(expected = Exception.class)
460 + public void testInterfaceUp() throws Exception {
461 + ospfInterface.setInterfaceType(OspfInterfaceType.POINT_TO_POINT.value());
462 + ospfInterface.interfaceUp();
463 + assertThat(ospfInterface, is(notNullValue()));
464 + }
465 +
466 + /**
467 + * Tests to interfaceUp() method.
468 + */
469 + @Test(expected = Exception.class)
470 + public void testInterfaceUp1() throws Exception {
471 +
472 + ospfInterface.setInterfaceType(OspfInterfaceType.BROADCAST.value());
473 + ospfInterface.interfaceUp();
474 + assertThat(ospfInterface, is(notNullValue()));
475 + }
476 +
477 + /**
478 + * Tests to interfaceUp() method.
479 + */
480 + @Test(expected = Exception.class)
481 + public void testInterfaceUp2() throws Exception {
482 +
483 + ospfInterface.setRouterPriority(1);
484 + ospfInterface.setInterfaceType(OspfInterfaceType.BROADCAST.value());
485 + ospfInterface.interfaceUp();
486 + assertThat(ospfInterface, is(notNullValue()));
487 + }
488 +
489 + /**
490 + * Tests to backupSeen() method.
419 */ 491 */
420 @Test 492 @Test
421 - public void testSetReTransmitInterval() throws Exception { 493 + public void testBackupSeen() throws Exception {
422 - ospfInterface.setReTransmitInterval(100); 494 + ospfInterface.setOspfArea(ospfArea);
423 - assertThat(ospfInterface.reTransmitInterval(), is(100)); 495 + ospfInterface.setState(OspfInterfaceState.WAITING);
496 + ospfInterface.backupSeen(channel);
497 + assertThat(ospfInterface, is(notNullValue()));
424 } 498 }
425 499
426 /** 500 /**
427 - * Tests dr() getter method. 501 + * Tests to waitTimer() method.
428 */ 502 */
429 @Test 503 @Test
430 - public void testGetDr() throws Exception { 504 + public void testWaitTimer() throws Exception {
431 - ospfInterface.setDr(Ip4Address.valueOf("1.1.1.1")); 505 + ospfInterface.setOspfArea(ospfArea);
432 - assertThat(ospfInterface.dr(), is(Ip4Address.valueOf("1.1.1.1"))); 506 + ospfInterface.setState(OspfInterfaceState.WAITING);
507 + ospfInterface.waitTimer(channel);
508 + assertThat(ospfInterface, is(notNullValue()));
433 } 509 }
434 510
435 /** 511 /**
436 - * Tests dr() setter method. 512 + * Tests to callDrElection() method.
437 */ 513 */
438 @Test 514 @Test
439 - public void testSetDr() throws Exception { 515 + public void testCallDrElection() throws Exception {
440 - ospfInterface.setDr(Ip4Address.valueOf("1.1.1.1")); 516 + ospfInterface.setOspfArea(ospfArea);
441 - assertThat(ospfInterface.dr(), is(Ip4Address.valueOf("1.1.1.1"))); 517 + ospfInterface.setState(OspfInterfaceState.WAITING);
518 + ospfInterface.callDrElection(channel);
519 + assertThat(ospfInterface, is(notNullValue()));
442 } 520 }
443 521
444 /** 522 /**
445 - * Tests bdr() getter method. 523 + * Tests to neighborChange() method.
446 */ 524 */
447 @Test 525 @Test
448 - public void testGetBdr() throws Exception { 526 + public void testNeighborChange() throws Exception {
449 - ospfInterface.setBdr(Ip4Address.valueOf("1.1.1.1")); 527 + ospfInterface.setOspfArea(ospfArea);
450 - assertThat(ospfInterface.bdr(), is(Ip4Address.valueOf("1.1.1.1"))); 528 + ospfInterface.setState(OspfInterfaceState.DR);
529 + ospfInterface.neighborChange();
530 + assertThat(ospfInterface, is(notNullValue()));
451 } 531 }
452 532
453 /** 533 /**
454 - * Tests bdr() setter method. 534 + * Tests to interfaceDown() method.
535 + */
536 + @Test(expected = Exception.class)
537 + public void testInterfaceDown() throws Exception {
538 + ospfInterface.interfaceDown();
539 + assertThat(ospfInterface, is(notNullValue()));
540 + }
541 +
542 + /**
543 + * Tests processOspfMessage() method.
455 */ 544 */
456 @Test 545 @Test
457 - public void testSetBdr() throws Exception { 546 + public void testProcessOspfMessage() throws Exception {
458 - ospfInterface.setBdr(Ip4Address.valueOf("1.1.1.1")); 547 + ospfInterface.setOspfArea(ospfArea);
459 - assertThat(ospfInterface.bdr(), is(Ip4Address.valueOf("1.1.1.1"))); 548 + ospfInterface.setInterfaceType(OspfInterfaceType.POINT_TO_POINT.value());
549 + ospfInterface.setIpNetworkMask(Ip4Address.valueOf("0.0.0.0"));
550 + ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11"));
551 + ospfInterface.setInterfaceType(2);
552 + ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12"));
553 + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
554 + OspfMessage message;
555 + helloPacket = new HelloPacket();
556 + helloPacket.setSourceIp(Ip4Address.valueOf("1.1.0.1"));
557 + helloPacket.setRouterId(Ip4Address.valueOf("10.10.10.10"));
558 + helloPacket.setOspfVer(2);
559 + helloPacket.setAreaId(Ip4Address.valueOf("12.12.12.12"));
560 + helloPacket.setOptions(2);
561 + helloPacket.setNetworkMask(Ip4Address.valueOf("3.3.3.3"));
562 + helloPacket.setOspftype(1);
563 + helloPacket.setAuthType(0);
564 + helloPacket.setHelloInterval(60);
565 + helloPacket.setRouterDeadInterval(60);
566 + helloPacket.setAuthentication(0);
567 + helloPacket.setNetworkMask(Ip4Address.valueOf("1.1.1.1"));
568 + checksumCalculator = new ChecksumCalculator();
569 + byteArray = helloPacket.asBytes();
570 + helloPacket.setOspfPacLength(byteArray.length);
571 + checkArray = checksumCalculator.calculateOspfCheckSum(byteArray, 12, 13);
572 + checkArray[0] = -51;
573 + checkArray[1] = 52;
574 + buf = ChannelBuffers.copiedBuffer(checkArray);
575 + helloPacket.setChecksum(buf.readUnsignedShort());
576 + message = helloPacket;
577 + ospfInterface.processOspfMessage(message, channelHandlerContext);
578 + ddPacket = new DdPacket();
579 + ddPacket.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
580 + ddPacket.setRouterId(Ip4Address.valueOf("10.10.10.10"));
581 + ddPacket.setOspfVer(2);
582 + ddPacket.setAreaId(Ip4Address.valueOf("12.12.12.12"));
583 + ddPacket.setOptions(2);
584 + ddPacket.setOspftype(2);
585 + ddPacket.setAuthType(0);
586 + ddPacket.setAuthentication(0);
587 + checksumCalculator = new ChecksumCalculator();
588 + byteArray = ddPacket.asBytes();
589 + ddPacket.setOspfPacLength(byteArray.length);
590 + checkArray = checksumCalculator.calculateOspfCheckSum(byteArray, 12, 13);
591 + checkArray[0] = -49;
592 + checkArray[1] = -79;
593 + buf = ChannelBuffers.copiedBuffer(checkArray);
594 + ddPacket.setChecksum(buf.readUnsignedShort());
595 + channelHandlerContext = null;
596 + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
597 + message = ddPacket;
598 + ospfInterface.processOspfMessage(message, channelHandlerContext);
599 + lsRequest = new LsRequest();
600 + lsRequest.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
601 + lsRequest.setRouterId(Ip4Address.valueOf("10.10.10.10"));
602 + lsRequest.setOspfVer(2);
603 + lsRequest.setAreaId(Ip4Address.valueOf("12.12.12.12"));
604 + lsRequest.setOspftype(3);
605 + lsRequest.setAuthType(0);
606 + lsRequest.setAuthentication(0);
607 + checksumCalculator = new ChecksumCalculator();
608 + byteArray = lsRequest.asBytes();
609 + lsRequest.setOspfPacLength(byteArray.length);
610 + checkArray = checksumCalculator.calculateOspfCheckSum(byteArray, 12, 13);
611 + checkArray[0] = -47;
612 + checkArray[1] = -72;
613 + buf = ChannelBuffers.copiedBuffer(checkArray);
614 + lsRequest.setChecksum(buf.readUnsignedShort());
615 + message = lsRequest;
616 + channelHandlerContext = null;
617 + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
618 + ospfInterface.processOspfMessage(message, channelHandlerContext);
619 + lsUpdate = new LsUpdate();
620 + lsUpdate.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
621 + lsUpdate.setRouterId(Ip4Address.valueOf("10.10.10.10"));
622 + lsUpdate.setOspfVer(2);
623 + lsUpdate.setAreaId(Ip4Address.valueOf("12.12.12.12"));
624 + lsUpdate.setOspftype(4);
625 + lsUpdate.setAuthType(0);
626 + lsUpdate.setAuthentication(0);
627 + checksumCalculator = new ChecksumCalculator();
628 + byteArray = lsUpdate.asBytes();
629 + lsUpdate.setOspfPacLength(byteArray.length);
630 + checkArray = checksumCalculator.calculateOspfCheckSum(byteArray, 12, 13);
631 + checkArray[0] = -47;
632 + checkArray[1] = -77;
633 + buf = ChannelBuffers.copiedBuffer(checkArray);
634 + lsUpdate.setChecksum(buf.readUnsignedShort());
635 + message = lsUpdate;
636 + ospfInterface.processOspfMessage(message, channelHandlerContext);
637 + lsAck = new LsAcknowledge();
638 + lsAck.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
639 + lsAck.setRouterId(Ip4Address.valueOf("10.10.10.10"));
640 + lsAck.setOspfVer(2);
641 + lsAck.setAreaId(Ip4Address.valueOf("12.12.12.12"));
642 + lsAck.setOspftype(5);
643 + lsAck.setAuthType(0);
644 + lsAck.setAuthentication(0);
645 + checksumCalculator = new ChecksumCalculator();
646 + byteArray = lsAck.asBytes();
647 + lsAck.setOspfPacLength(byteArray.length);
648 + checkArray = checksumCalculator.calculateOspfCheckSum(byteArray, 12, 13);
649 + checkArray[0] = -47;
650 + checkArray[1] = -74;
651 + buf = ChannelBuffers.copiedBuffer(checkArray);
652 + lsAck.setChecksum(buf.readUnsignedShort());
653 + message = lsAck;
654 + channelHandlerContext = null;
655 + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
656 + ospfInterface.processOspfMessage(message, channelHandlerContext);
657 + assertThat(ospfInterface, is(notNullValue()));
460 } 658 }
461 659
462 /** 660 /**
463 - * Tests transmitDelay() getter method. 661 + * Tests processHelloMessage() method.
464 */ 662 */
465 @Test 663 @Test
466 - public void testGetTransmitDelay() throws Exception { 664 + public void testProcessHelloMessage() throws Exception {
467 - ospfInterface.setTransmitDelay(100); 665 + ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11"));
468 - assertThat(ospfInterface.transmitDelay(), is(100)); 666 + ospfInterface.setInterfaceType(1);
667 + ospfInterface.setIpNetworkMask(Ip4Address.valueOf("244.244.244.244"));
668 + ospfInterface.setHelloIntervalTime(10);
669 + ospfInterface.setRouterDeadIntervalTime(10);
670 + ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12"));
671 + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
672 + OspfMessage message;
673 + helloPacket = new HelloPacket();
674 + helloPacket.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
675 + helloPacket.setOspfVer(2);
676 + helloPacket.setAreaId(Ip4Address.valueOf("12.12.12.12"));
677 + helloPacket.setNetworkMask(Ip4Address.valueOf("244.244.244.244"));
678 + helloPacket.setHelloInterval(10);
679 + helloPacket.setRouterDeadInterval(10);
680 + helloPacket.setDr(Ip4Address.valueOf("10.10.10.10"));
681 + helloPacket.setBdr(Ip4Address.valueOf("11.11.11.11"));
682 + helloPacket.setRouterId(Ip4Address.valueOf("111.111.111.111"));
683 + message = helloPacket;
684 + ospfInterface.processHelloMessage(message, channelHandlerContext);
685 + assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
469 } 686 }
470 687
471 /** 688 /**
472 - * Tests transmitDelay() setter method. 689 + * Tests processHelloMessage() method.
473 */ 690 */
474 @Test 691 @Test
475 - public void testSetTransmitDelay() throws Exception { 692 + public void testProcessHelloMessage1() throws Exception {
476 - ospfInterface.setTransmitDelay(100); 693 + ospfInterface.setOspfArea(ospfArea);
477 - assertThat(ospfInterface.transmitDelay(), is(100)); 694 + ospfInterface.setInterfaceType(2);
695 + ospfInterface.setRouterPriority(1);
696 + ospfInterface.interfaceUp();
697 + ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11"));
698 + ospfInterface.setState(OspfInterfaceState.WAITING);
699 + ospfInterface.setInterfaceType(2);
700 + ospfInterface.setIpNetworkMask(Ip4Address.valueOf("244.244.244.244"));
701 + ospfInterface.setHelloIntervalTime(10);
702 + ospfInterface.setRouterDeadIntervalTime(10);
703 + ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12"));
704 + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
705 + OspfMessage message;
706 + helloPacket = new HelloPacket();
707 + helloPacket.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
708 + helloPacket.setOspfVer(2);
709 + helloPacket.setAreaId(Ip4Address.valueOf("12.12.12.12"));
710 + helloPacket.setNetworkMask(Ip4Address.valueOf("244.244.244.244"));
711 + helloPacket.setHelloInterval(10);
712 + helloPacket.setRouterDeadInterval(10);
713 + helloPacket.setDr(Ip4Address.valueOf("10.10.10.10"));
714 + helloPacket.setBdr(Ip4Address.valueOf("11.11.11.11"));
715 + helloPacket.setRouterId(Ip4Address.valueOf("2.2.2.2"));
716 + message = helloPacket;
717 + channelHandlerContext = null;
718 + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
719 + ospfInterface.processHelloMessage(message, channelHandlerContext);
720 + assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
721 + ospfNbrHashMap = new HashMap();
722 + ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("10.10.10.10"),
723 + Ip4Address.valueOf("2.2.2.2"), 2,
724 + topologyForDeviceAndLink);
725 + ospfNbr.setNeighborId(Ip4Address.valueOf("2.2.2.2"));
726 + ospfNbr.setRouterPriority(0);
727 + ospfNbr.setNeighborDr(Ip4Address.valueOf("13.13.13.13"));
728 + ospfInterface.addNeighbouringRouter(ospfNbr);
729 + channelHandlerContext = null;
730 + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
731 + ospfInterface.processHelloMessage(message, channelHandlerContext);
732 + assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
478 } 733 }
479 734
480 /** 735 /**
481 - * Tests equals() method. 736 + * Tests processDdMessage() method.
482 */ 737 */
483 @Test 738 @Test
484 - public void testEquals() throws Exception { 739 + public void testProcessDdMessage() throws Exception {
485 - assertThat(ospfInterface.equals(new OspfInterfaceImpl()), is(true)); 740 + ospfInterface.setOspfArea(ospfArea);
741 + ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11"));
742 + ospfInterface.setInterfaceType(2);
743 + ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
744 + ospfInterface.setHelloIntervalTime(10);
745 + ospfInterface.setRouterDeadIntervalTime(10);
746 + ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12"));
747 + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
748 + OspfMessage message;
749 + ddPacket = new DdPacket();
750 + ddPacket.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
751 + ddPacket.setOspfVer(2);
752 + ddPacket.setAreaId(Ip4Address.valueOf("12.12.12.12"));
753 + ddPacket.setRouterId(Ip4Address.valueOf("2.2.2.2"));
754 + ddPacket.setIsOpaqueCapable(true);
755 + ddPacket.setIsMore(1);
756 + ddPacket.setIsInitialize(1);
757 + ddPacket.setIsMaster(1);
758 + ddPacket.setSequenceNo(123);
759 + message = ddPacket;
760 + ospfNbrHashMap = new HashMap();
761 + ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("10.10.10.10"),
762 + Ip4Address.valueOf("2.2.2.2"), 2,
763 + topologyForDeviceAndLink);
764 + ospfNbr.setLastDdPacket(createDdPacket());
765 + ospfNbr.setNeighborId(Ip4Address.valueOf("2.2.2.2"));
766 + ospfNbr.setState(OspfNeighborState.EXSTART);
767 + ospfNbr.setRouterPriority(0);
768 + ospfNbr.setNeighborDr(Ip4Address.valueOf("13.13.13.13"));
769 + ospfNbr.setDdSeqNum(123);
770 + ospfInterface.addNeighbouringRouter(ospfNbr);
771 + channelHandlerContext = null;
772 + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
773 + ospfInterface.processDdMessage(message, channelHandlerContext);
774 + assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
486 } 775 }
487 776
488 /** 777 /**
489 - * Tests hashCode() method. 778 + * Tests processDdMessage() method.
779 + */
780 + @Test(expected = Exception.class)
781 + public void testProcessDdMessage3() throws Exception {
782 + ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11"));
783 + ospfInterface.setInterfaceType(2);
784 + ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
785 + ospfInterface.setHelloIntervalTime(10);
786 + ospfInterface.setRouterDeadIntervalTime(10);
787 + ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12"));
788 + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
789 + OspfMessage message;
790 + ddPacket = new DdPacket();
791 + ddPacket.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
792 + ddPacket.setOspfVer(2);
793 + ddPacket.setAreaId(Ip4Address.valueOf("12.12.12.12"));
794 + ddPacket.setRouterId(Ip4Address.valueOf("2.2.2.2"));
795 + ddPacket.setIsOpaqueCapable(true);
796 + ddPacket.setIsMore(1);
797 + ddPacket.setIsInitialize(1);
798 + ddPacket.setIsMaster(1);
799 + ddPacket.setSequenceNo(123);
800 + message = ddPacket;
801 + ospfNbrHashMap = new HashMap();
802 + ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("10.10.10.10"),
803 + Ip4Address.valueOf("2.2.2.2"), 2,
804 + topologyForDeviceAndLink);
805 + ospfNbr.setLastDdPacket(createDdPacket());
806 + ospfNbr.setNeighborId(Ip4Address.valueOf("2.2.2.2"));
807 + ospfNbr.setState(OspfNeighborState.EXSTART);
808 + ospfNbr.setRouterPriority(0);
809 + ospfNbr.setNeighborDr(Ip4Address.valueOf("13.13.13.13"));
810 + ospfNbr.setDdSeqNum(123);
811 + ospfInterface.addNeighbouringRouter(ospfNbr);
812 + ddPacket.setIsMore(1);
813 + ddPacket.setIsInitialize(0);
814 + ddPacket.setIsMaster(0);
815 + ddPacket.setSequenceNo(123);
816 + ospfInterface.addNeighbouringRouter(ospfNbr);
817 + channelHandlerContext = null;
818 + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
819 + ospfInterface.processDdMessage(message, channelHandlerContext);
820 + assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
821 + }
822 +
823 + /**
824 + * Tests processDdMessage() method.
825 + */
826 + @Test(expected = Exception.class)
827 + public void testProcessDdMessage1() throws Exception {
828 + ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11"));
829 + ospfInterface.setInterfaceType(2);
830 + ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
831 + ospfInterface.setHelloIntervalTime(10);
832 + ospfInterface.setRouterDeadIntervalTime(10);
833 + ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12"));
834 + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
835 + OspfMessage message;
836 + ddPacket = new DdPacket();
837 + ddPacket.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
838 + ddPacket.setOspfVer(2);
839 + ddPacket.setAreaId(Ip4Address.valueOf("12.12.12.12"));
840 + ddPacket.setRouterId(Ip4Address.valueOf("2.2.2.2"));
841 + ddPacket.setIsOpaqueCapable(true);
842 + ddPacket.setIsMore(1);
843 + ddPacket.setIsInitialize(1);
844 + ddPacket.setIsMaster(1);
845 + ddPacket.setSequenceNo(123);
846 + message = ddPacket;
847 + ospfNbrHashMap = new HashMap();
848 + ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("10.10.10.10"),
849 + Ip4Address.valueOf("2.2.2.2"), 2,
850 + topologyForDeviceAndLink);
851 + ospfNbr.setLastDdPacket(createDdPacket());
852 + ospfNbr.setNeighborId(Ip4Address.valueOf("2.2.2.2"));
853 + ospfNbr.setState(OspfNeighborState.EXCHANGE);
854 + ospfNbr.setRouterPriority(0);
855 + ospfNbr.setNeighborDr(Ip4Address.valueOf("13.13.13.13"));
856 + ospfNbr.setDdSeqNum(123);
857 + ospfInterface.addNeighbouringRouter(ospfNbr);
858 + ddPacket.setIsMore(1);
859 + ddPacket.setIsInitialize(0);
860 + ddPacket.setIsMaster(0);
861 + ddPacket.setSequenceNo(123);
862 + ospfInterface.addNeighbouringRouter(ospfNbr);
863 + channelHandlerContext = null;
864 + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
865 + ospfInterface.processDdMessage(message, channelHandlerContext);
866 + assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
867 +
868 + }
869 +
870 + /**
871 + * Tests processDdMessage() method.
872 + */
873 + @Test(expected = Exception.class)
874 + public void testProcessDdMessage2() throws Exception {
875 + ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11"));
876 + ospfInterface.setInterfaceType(2);
877 + ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
878 + ospfInterface.setHelloIntervalTime(10);
879 + ospfInterface.setRouterDeadIntervalTime(10);
880 + ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12"));
881 + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
882 + OspfMessage message;
883 + ddPacket = new DdPacket();
884 + ddPacket.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
885 + ddPacket.setOspfVer(2);
886 + ddPacket.setAreaId(Ip4Address.valueOf("12.12.12.12"));
887 + ddPacket.setRouterId(Ip4Address.valueOf("2.2.2.2"));
888 + ddPacket.setIsOpaqueCapable(true);
889 + ddPacket.setIsMore(1);
890 + ddPacket.setIsInitialize(1);
891 + ddPacket.setIsMaster(1);
892 + ddPacket.setSequenceNo(123);
893 + message = ddPacket;
894 + ospfNbrHashMap = new HashMap();
895 + ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("10.10.10.10"),
896 + Ip4Address.valueOf("2.2.2.2"), 2,
897 + topologyForDeviceAndLink);
898 + ospfNbr.setLastDdPacket(createDdPacket());
899 + ospfNbr.setNeighborId(Ip4Address.valueOf("2.2.2.2"));
900 + ospfNbr.setState(OspfNeighborState.LOADING);
901 + ospfNbr.setRouterPriority(0);
902 + ospfNbr.setNeighborDr(Ip4Address.valueOf("13.13.13.13"));
903 + ospfNbr.setDdSeqNum(123);
904 + ospfInterface.addNeighbouringRouter(ospfNbr);
905 + ospfInterface.setState(OspfInterfaceState.POINT2POINT);
906 + channelHandlerContext = null;
907 + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
908 + ospfInterface.processDdMessage(message, channelHandlerContext);
909 + assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
910 +
911 + }
912 +
913 + /**
914 + * Tests processDdMessage() method.
915 + */
916 + @Test(expected = Exception.class)
917 + public void testProcessDdMessage4() throws Exception {
918 + ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11"));
919 + ospfInterface.setInterfaceType(2);
920 + ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
921 + ospfInterface.setHelloIntervalTime(10);
922 + ospfInterface.setRouterDeadIntervalTime(10);
923 + ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12"));
924 + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
925 + OspfMessage message;
926 + ddPacket = new DdPacket();
927 + ddPacket.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
928 + ddPacket.setOspfVer(2);
929 + ddPacket.setAreaId(Ip4Address.valueOf("12.12.12.12"));
930 + ddPacket.setRouterId(Ip4Address.valueOf("2.2.2.2"));
931 + ddPacket.setIsOpaqueCapable(true);
932 + ddPacket.setIsMore(1);
933 + ddPacket.setIsInitialize(1);
934 + ddPacket.setIsMaster(1);
935 + ddPacket.setSequenceNo(123);
936 + message = ddPacket;
937 + ospfNbrHashMap = new HashMap();
938 + ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("10.10.10.10"),
939 + Ip4Address.valueOf("2.2.2.2"), 2,
940 + topologyForDeviceAndLink);
941 + ospfNbr.setLastDdPacket(createDdPacket());
942 + ospfNbr.setNeighborId(Ip4Address.valueOf("2.2.2.2"));
943 + ospfNbr.setState(OspfNeighborState.EXCHANGE);
944 + ospfNbr.setRouterPriority(0);
945 + ospfNbr.setNeighborDr(Ip4Address.valueOf("13.13.13.13"));
946 + ospfNbr.setDdSeqNum(123);
947 + ospfInterface.addNeighbouringRouter(ospfNbr);
948 + ospfInterface.setState(OspfInterfaceState.POINT2POINT);
949 + channelHandlerContext = null;
950 + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
951 + ddPacket.setIsMore(1);
952 + ddPacket.setIsInitialize(0);
953 + ddPacket.setIsMaster(1);
954 + ddPacket.setSequenceNo(123);
955 + ospfInterface.addNeighbouringRouter(ospfNbr);
956 + ospfNbr.setState(OspfNeighborState.EXCHANGE);
957 + ospfInterface.addNeighbouringRouter(ospfNbr);
958 + channelHandlerContext = null;
959 + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
960 + ospfInterface.processDdMessage(message, channelHandlerContext);
961 + assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
962 +
963 + }
964 +
965 + /**
966 + * Tests processDdMessage() method.
967 + */
968 + @Test(expected = Exception.class)
969 + public void testProcessDdMessage5() throws Exception {
970 + ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11"));
971 + ospfInterface.setInterfaceType(2);
972 + ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
973 + ospfInterface.setHelloIntervalTime(10);
974 + ospfInterface.setRouterDeadIntervalTime(10);
975 + ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12"));
976 + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
977 + OspfMessage message;
978 + ddPacket = new DdPacket();
979 + ddPacket.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
980 + ddPacket.setOspfVer(2);
981 + ddPacket.setAreaId(Ip4Address.valueOf("12.12.12.12"));
982 + ddPacket.setRouterId(Ip4Address.valueOf("2.2.2.2"));
983 + ddPacket.setIsOpaqueCapable(true);
984 + ddPacket.setIsMore(1);
985 + ddPacket.setIsInitialize(1);
986 + ddPacket.setIsMaster(1);
987 + ddPacket.setSequenceNo(123);
988 + message = ddPacket;
989 + ospfNbrHashMap = new HashMap();
990 + ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("10.10.10.10"),
991 + Ip4Address.valueOf("2.2.2.2"), 2,
992 + topologyForDeviceAndLink);
993 + ospfNbr.setLastDdPacket(createDdPacket());
994 + ospfNbr.setNeighborId(Ip4Address.valueOf("2.2.2.2"));
995 + ospfNbr.setState(OspfNeighborState.EXCHANGE);
996 + ospfNbr.setRouterPriority(0);
997 + ospfNbr.setNeighborDr(Ip4Address.valueOf("13.13.13.13"));
998 + ospfNbr.setDdSeqNum(123);
999 + ospfInterface.addNeighbouringRouter(ospfNbr);
1000 + ospfInterface.setState(OspfInterfaceState.POINT2POINT);
1001 + channelHandlerContext = null;
1002 + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
1003 + ddPacket.setIsMore(1);
1004 + ddPacket.setIsInitialize(1);
1005 + ddPacket.setIsMaster(0);
1006 + ddPacket.setSequenceNo(123);
1007 + ospfInterface.addNeighbouringRouter(ospfNbr);
1008 + ospfNbr.setState(OspfNeighborState.EXCHANGE);
1009 + ospfInterface.addNeighbouringRouter(ospfNbr);
1010 + channelHandlerContext = null;
1011 + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
1012 + ospfInterface.processDdMessage(message, channelHandlerContext);
1013 + assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
1014 +
1015 + }
1016 +
1017 + /**
1018 + * Tests processDdMessage() method.
1019 + */
1020 + @Test(expected = Exception.class)
1021 + public void testProcessDdMessage6() throws Exception {
1022 + ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11"));
1023 + ospfInterface.setInterfaceType(2);
1024 + ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
1025 + ospfInterface.setHelloIntervalTime(10);
1026 + ospfInterface.setRouterDeadIntervalTime(10);
1027 + ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12"));
1028 + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
1029 + OspfMessage message;
1030 + ddPacket = new DdPacket();
1031 + ddPacket.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
1032 + ddPacket.setOspfVer(2);
1033 + ddPacket.setAreaId(Ip4Address.valueOf("12.12.12.12"));
1034 + ddPacket.setRouterId(Ip4Address.valueOf("2.2.2.2"));
1035 + ddPacket.setIsOpaqueCapable(true);
1036 + ddPacket.setIsMore(1);
1037 + ddPacket.setIsInitialize(1);
1038 + ddPacket.setIsMaster(1);
1039 + ddPacket.setSequenceNo(123);
1040 + message = ddPacket;
1041 + ospfNbrHashMap = new HashMap();
1042 + ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("10.10.10.10"),
1043 + Ip4Address.valueOf("2.2.2.2"), 2,
1044 + topologyForDeviceAndLink);
1045 + ospfNbr.setLastDdPacket(createDdPacket());
1046 + ospfNbr.setNeighborId(Ip4Address.valueOf("2.2.2.2"));
1047 + ospfNbr.setState(OspfNeighborState.FULL);
1048 + ospfNbr.setRouterPriority(0);
1049 + ospfNbr.setNeighborDr(Ip4Address.valueOf("13.13.13.13"));
1050 + ospfNbr.setDdSeqNum(123);
1051 + ospfInterface.addNeighbouringRouter(ospfNbr);
1052 + ospfInterface.setState(OspfInterfaceState.POINT2POINT);
1053 + channelHandlerContext = null;
1054 + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
1055 + ddPacket.setIsMore(1);
1056 + ddPacket.setIsInitialize(1);
1057 + ddPacket.setIsMaster(0);
1058 + ddPacket.setSequenceNo(123);
1059 + ospfInterface.addNeighbouringRouter(ospfNbr);
1060 + ospfNbr.setState(OspfNeighborState.FULL);
1061 + ospfInterface.addNeighbouringRouter(ospfNbr);
1062 + channelHandlerContext = null;
1063 + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
1064 + ospfInterface.processDdMessage(message, channelHandlerContext);
1065 + assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
1066 +
1067 + }
1068 +
1069 + /**
1070 + * Tests processLsRequestMessage() method.
1071 + */
1072 + @Test(expected = Exception.class)
1073 + public void testProcessLSRequestMessage() throws Exception {
1074 + ospfArea.setRouterId(Ip4Address.valueOf("11.11.11.11"));
1075 + ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12"));
1076 + ospfInterface.setOspfArea(ospfArea);
1077 + ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11"));
1078 + ospfInterface.setInterfaceType(2);
1079 + ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
1080 + ospfInterface.setHelloIntervalTime(10);
1081 + ospfInterface.setRouterDeadIntervalTime(10);
1082 + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
1083 + OspfMessage message;
1084 + lsRequest = new LsRequest();
1085 + lsRequest.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
1086 + lsRequest.setOspfVer(2);
1087 + lsRequest.setAreaId(Ip4Address.valueOf("12.12.12.12"));
1088 + lsRequest.setRouterId(Ip4Address.valueOf("10.226.165.100"));
1089 + List<LsRequestPacket> lsRequests = new ArrayList();
1090 + LsRequestPacket lsRequestPacket = new LsRequestPacket();
1091 + lsRequestPacket.setLsType(OspfLsaType.AREA_LOCAL_OPAQUE_LSA.value());
1092 + lsRequestPacket.setLinkStateId("2.2.2.2");
1093 + lsRequestPacket.setOwnRouterId("10.226.165.100");
1094 + lsRequests.add(lsRequestPacket);
1095 + lsRequests.add(lsRequestPacket);
1096 + lsRequest.addLinkStateRequests(lsRequestPacket);
1097 + message = lsRequest;
1098 + ospfNbrHashMap = new HashMap();
1099 + ospfNbr.setState(OspfNeighborState.EXCHANGE);
1100 + ospfNbr = new OspfNbrImpl(ospfArea, createOspfInterface(), Ip4Address.valueOf("10.10.10.10"),
1101 + Ip4Address.valueOf("10.226.165.100"), 2,
1102 + topologyForDeviceAndLink);
1103 + ospfNbr.setLastDdPacket(createDdPacket());
1104 + ospfNbr.setNeighborId(Ip4Address.valueOf("10.226.165.100"));
1105 + ospfNbr.setState(OspfNeighborState.FULL);
1106 + ospfNbr.setRouterPriority(0);
1107 + ospfNbr.setNeighborDr(Ip4Address.valueOf("13.13.13.13"));
1108 + ospfNbr.setDdSeqNum(123);
1109 + ospfInterface.addNeighbouringRouter(ospfNbr);
1110 + OpaqueLsaHeader lsaHeader = new OpaqueLsaHeader();
1111 + lsaHeader.setLsType(OspfLsaType.AREA_LOCAL_OPAQUE_LSA.value());
1112 + lsaHeader.setLinkStateId("2.2.2.2");
1113 + lsaHeader.setAdvertisingRouter(Ip4Address.valueOf("10.226.165.100"));
1114 + OpaqueLsa10 opaqueLsa10 = new OpaqueLsa10(lsaHeader);
1115 + ospfArea.addLsa(opaqueLsa10, false, ospfInterface);
1116 + ospfInterface.setOspfArea(ospfArea);
1117 + ospfInterface.processLsRequestMessage(message, channelHandlerContext);
1118 + assertThat(ospfInterface, is(notNullValue()));
1119 + }
1120 +
1121 + /**
1122 + * Tests processLsUpdateMessage() method.
490 */ 1123 */
491 @Test 1124 @Test
492 - public void testHashCode() throws Exception { 1125 + public void testProcessLSUpdateMessage() throws Exception {
493 - result = ospfInterface.hashCode(); 1126 + ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11"));
494 - assertThat(result, is(notNullValue())); 1127 + ospfInterface.setInterfaceType(2);
1128 + ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
1129 + ospfInterface.setHelloIntervalTime(10);
1130 + ospfInterface.setRouterDeadIntervalTime(10);
1131 + ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12"));
1132 + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
1133 + OspfMessage message;
1134 + lsUpdate = new LsUpdate();
1135 + lsUpdate.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
1136 + lsUpdate.setOspfVer(2);
1137 + lsUpdate.setAreaId(Ip4Address.valueOf("12.12.12.12"));
1138 + lsUpdate.setRouterId(Ip4Address.valueOf("10.226.165.100"));
1139 + RouterLsa routerLsa = new RouterLsa();
1140 + lsUpdate.addLsa(routerLsa);
1141 + lsUpdate.setNumberOfLsa(1);
1142 + message = lsUpdate;
1143 + ospfNbrHashMap = new HashMap();
1144 + ospfNbr.setState(OspfNeighborState.FULL);
1145 + ospfNbr = new OspfNbrImpl(ospfArea, createOspfInterface(), Ip4Address.valueOf("10.10.10.10"),
1146 + Ip4Address.valueOf("10.226.165.100"), 2,
1147 + topologyForDeviceAndLink);
1148 + ospfNbr.setLastDdPacket(createDdPacket());
1149 + ospfNbr.setNeighborId(Ip4Address.valueOf("2.2.2.2"));
1150 + ospfNbr.setState(OspfNeighborState.FULL);
1151 + ospfNbr.setRouterPriority(0);
1152 + ospfNbr.setNeighborDr(Ip4Address.valueOf("13.13.13.13"));
1153 + ospfNbr.setDdSeqNum(123);
1154 + ospfInterface.addNeighbouringRouter(ospfNbr);
1155 + channelHandlerContext = null;
1156 + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
1157 + ospfInterface.processLsUpdateMessage(message, channelHandlerContext);
1158 + assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
1159 +
1160 + }
1161 +
1162 + @Test(expected = Exception.class)
1163 + public void testProcessLSAckMessage() throws Exception {
1164 + ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11"));
1165 + ospfInterface.setInterfaceType(2);
1166 + ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
1167 + ospfInterface.setHelloIntervalTime(10);
1168 + ospfInterface.setRouterDeadIntervalTime(10);
1169 + ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12"));
1170 + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
1171 + OspfMessage message;
1172 + lsAck = new LsAcknowledge();
1173 + lsAck.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
1174 + lsAck.setOspfVer(2);
1175 + lsAck.setAreaId(Ip4Address.valueOf("12.12.12.12"));
1176 + LsaHeader lsaHeader = new LsaHeader();
1177 + lsAck.addLinkStateHeader(lsaHeader);
1178 + message = lsAck;
1179 + ospfNbr = new OspfNbrImpl(ospfArea, createOspfInterface(), Ip4Address.valueOf("10.10.10.10"),
1180 + Ip4Address.valueOf("10.226.165.100"), 2,
1181 + topologyForDeviceAndLink);
1182 + ospfNbr.setLastDdPacket(createDdPacket());
1183 + ospfNbr.setNeighborId(Ip4Address.valueOf("2.2.2.2"));
1184 + ospfNbr.setState(OspfNeighborState.FULL);
1185 + ospfNbr.setRouterPriority(0);
1186 + ospfNbr.setNeighborDr(Ip4Address.valueOf("13.13.13.13"));
1187 + ospfNbr.setDdSeqNum(123);
1188 + channelHandlerContext = null;
1189 + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
1190 + ospfInterface.processLsAckMessage(message, channelHandlerContext);
1191 + assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
1192 +
495 } 1193 }
496 1194
497 /** 1195 /**
498 - * Tests to string method. 1196 + * Tests electRouter() method.
499 */ 1197 */
500 @Test 1198 @Test
501 - public void testToString() throws Exception { 1199 + public void testElectRouter() throws Exception {
502 - assertThat(ospfInterface.toString(), is(notNullValue())); 1200 + ospfInterface.setOspfArea(ospfArea);
1201 + ospfInterface.setDr(Ip4Address.valueOf("3.3.3.3"));
1202 + ospfInterface.setBdr(Ip4Address.valueOf("3.3.3.3"));
1203 + ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
1204 + ChannelConfig channelConfig = EasyMock.createMock(ChannelConfig.class);
1205 + EasyMock.expect(channelConfig.getBufferFactory()).andReturn(new HeapChannelBufferFactory());
1206 + Channel channel = EasyMock.createMock(Channel.class);
1207 + ospfInterface.electRouter(channel);
1208 + assertThat(ospfInterface.dr(), is(notNullValue()));
1209 + }
1210 +
1211 + /**
1212 + * Tests electBdr() method.
1213 + */
1214 + @Test
1215 + public void testElectBdr() throws Exception {
1216 + ospfEligibleRouter = new OspfEligibleRouter();
1217 + ospfEligibleRouter.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
1218 + ospfEligibleRouter.setIsDr(true);
1219 + ospfEligibleRouter.setRouterPriority(10);
1220 + ospfEligibleRouter.setRouterId(Ip4Address.valueOf("1.1.1.1"));
1221 + ospfEligibleRouter.setIsBdr(false);
1222 + OspfEligibleRouter ospfEligibleRouter1 = new OspfEligibleRouter();
1223 + ospfEligibleRouter.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
1224 + ospfEligibleRouter.setIsDr(true);
1225 + ospfEligibleRouter.setRouterPriority(10);
1226 + ospfEligibleRouter.setRouterId(Ip4Address.valueOf("1.1.1.1"));
1227 + ospfEligibleRouter.setIsBdr(false);
1228 + OspfEligibleRouter ospfEligibleRouter2 = new OspfEligibleRouter();
1229 + ospfEligibleRouter.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
1230 + ospfEligibleRouter.setIsDr(true);
1231 + ospfEligibleRouter.setRouterPriority(10);
1232 + ospfEligibleRouter.setRouterId(Ip4Address.valueOf("1.1.1.1"));
1233 + ospfEligibleRouter.setIsBdr(false);
1234 + List<OspfEligibleRouter> ospfEligibleRouters = new ArrayList<>();
1235 +
1236 + ospfEligibleRouters.add(ospfEligibleRouter);
1237 + ospfEligibleRouters.add(ospfEligibleRouter1);
1238 + ospfEligibleRouters.add(ospfEligibleRouter2);
1239 + OspfEligibleRouter eligibleRouter = ospfInterface.electBdr(ospfEligibleRouters);
1240 + assertThat(ospfEligibleRouters.size(), is(3));
1241 + assertThat(eligibleRouter, is(notNullValue()));
1242 + }
1243 +
1244 + /**
1245 + * Tests electDr() method.
1246 + */
1247 + @Test
1248 + public void testElectDR() throws Exception {
1249 + ospfEligibleRouter = new OspfEligibleRouter();
1250 + ospfEligibleRouter.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
1251 + ospfEligibleRouter.setIsDr(true);
1252 + ospfEligibleRouter.setRouterPriority(10);
1253 + ospfEligibleRouter.setRouterId(Ip4Address.valueOf("1.1.1.1"));
1254 + ospfEligibleRouter.setIsBdr(false);
1255 + OspfEligibleRouter ospfEligibleRouter1 = new OspfEligibleRouter();
1256 + ospfEligibleRouter.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
1257 + ospfEligibleRouter.setIsDr(true);
1258 + ospfEligibleRouter.setRouterPriority(10);
1259 + ospfEligibleRouter.setRouterId(Ip4Address.valueOf("1.1.1.1"));
1260 + ospfEligibleRouter.setIsBdr(false);
1261 + OspfEligibleRouter ospfEligibleRouter2 = new OspfEligibleRouter();
1262 + ospfEligibleRouter.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
1263 + ospfEligibleRouter.setIsDr(true);
1264 + ospfEligibleRouter.setRouterPriority(10);
1265 + ospfEligibleRouter.setRouterId(Ip4Address.valueOf("1.1.1.1"));
1266 + ospfEligibleRouter.setIsBdr(false);
1267 + List<OspfEligibleRouter> ospfEligibleRouters = new ArrayList<>();
1268 + ospfEligibleRouters.add(ospfEligibleRouter);
1269 + ospfEligibleRouters.add(ospfEligibleRouter1);
1270 + ospfEligibleRouters.add(ospfEligibleRouter2);
1271 + OspfEligibleRouter eligibleRouter = ospfInterface.electDr(ospfEligibleRouters,
1272 + ospfEligibleRouter);
1273 + assertThat(ospfEligibleRouters.size(), is(3));
1274 + assertThat(eligibleRouter, is(notNullValue()));
1275 + }
1276 +
1277 + /**
1278 + * Tests selectRouterBasedOnPriority() method.
1279 + */
1280 + @Test
1281 + public void testSelectRouterBasedOnPriority() throws Exception {
1282 + ospfEligibleRouter = new OspfEligibleRouter();
1283 + ospfEligibleRouter.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
1284 + ospfEligibleRouter.setIsDr(true);
1285 + ospfEligibleRouter.setRouterPriority(10);
1286 + ospfEligibleRouter.setRouterId(Ip4Address.valueOf("1.1.1.1"));
1287 + ospfEligibleRouter.setIsBdr(false);
1288 + OspfEligibleRouter ospfEligibleRouter1 = new OspfEligibleRouter();
1289 + ospfEligibleRouter.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
1290 + ospfEligibleRouter.setIsDr(true);
1291 + ospfEligibleRouter.setRouterPriority(11);
1292 + ospfEligibleRouter.setRouterId(Ip4Address.valueOf("1.1.1.1"));
1293 + ospfEligibleRouter.setIsBdr(false);
1294 + OspfEligibleRouter ospfEligibleRouter2 = new OspfEligibleRouter();
1295 + ospfEligibleRouter.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
1296 + ospfEligibleRouter.setIsDr(true);
1297 + ospfEligibleRouter.setRouterPriority(12);
1298 + ospfEligibleRouter.setRouterId(Ip4Address.valueOf("1.1.1.1"));
1299 + ospfEligibleRouter.setIsBdr(false);
1300 + List<OspfEligibleRouter> ospfEligibleRouters = new ArrayList<>();
1301 + ospfEligibleRouters.add(ospfEligibleRouter);
1302 + ospfEligibleRouters.add(ospfEligibleRouter1);
1303 + ospfEligibleRouters.add(ospfEligibleRouter2);
1304 + OspfEligibleRouter eligibleRouter = ospfInterface.selectRouterBasedOnPriority(
1305 + ospfEligibleRouters);
1306 + assertThat(eligibleRouter, is(notNullValue()));
1307 + }
1308 +
1309 + /**
1310 + * Tests addDeviceInformation() method.
1311 + */
1312 + @Test(expected = Exception.class)
1313 + public void testAddDeviceInformation() throws Exception {
1314 + ospfNbr = new OspfNbrImpl(ospfArea, createOspfInterface(), Ip4Address.valueOf("10.10.10.10"),
1315 + Ip4Address.valueOf("10.226.165.100"), 2,
1316 + topologyForDeviceAndLink);
1317 +
1318 + ospfInterface.addDeviceInformation(new OspfRouterImpl());
1319 + assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
1320 + }
1321 +
1322 + /**
1323 + * Tests removeDeviceInformation() method.
1324 + */
1325 + @Test(expected = Exception.class)
1326 + public void testRemoveDeviceInformation() throws Exception {
1327 + ospfNbr = new OspfNbrImpl(ospfArea, createOspfInterface(), Ip4Address.valueOf("10.10.10.10"),
1328 + Ip4Address.valueOf("10.226.165.100"), 2,
1329 + topologyForDeviceAndLink);
1330 +
1331 + ospfInterface.removeDeviceInformation(new OspfRouterImpl());
1332 + assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
1333 + }
1334 +
1335 + /**
1336 + * Tests addLinkInformation() method.
1337 + */
1338 + @Test(expected = Exception.class)
1339 + public void testaddLinkInformation() throws Exception {
1340 + ospfNbr = new OspfNbrImpl(ospfArea, createOspfInterface(), Ip4Address.valueOf("10.10.10.10"),
1341 + Ip4Address.valueOf("10.226.165.100"), 2,
1342 + topologyForDeviceAndLink);
1343 +
1344 + List topTlv = new ArrayList();
1345 + topTlv.add(new RouterTlv(new TlvHeader()));
1346 + ospfInterface.addLinkInformation(new OspfRouterImpl(), new OspfLinkTedImpl());
1347 + assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
503 } 1348 }
1349 +
1350 + /**
1351 + * Tests removeLinkInformation() method.
1352 + */
1353 + @Test(expected = Exception.class)
1354 + public void testRemoveLinkInformation() throws Exception {
1355 + ospfNbr = new OspfNbrImpl(ospfArea, createOspfInterface(), Ip4Address.valueOf("10.10.10.10"),
1356 + Ip4Address.valueOf("10.226.165.100"), 2,
1357 + topologyForDeviceAndLink);
1358 +
1359 + ospfInterface.removeLinkInformation(new OspfRouterImpl(), new OspfLinkTedImpl());
1360 + assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
1361 + }
1362 +
1363 + /**
1364 + * Utility for test method.
1365 + */
1366 + private DdPacket createDdPacket() throws OspfParseException {
1367 + byte[] ddPacket = {2, 2, 0, 32, -64, -88, -86, 8, 0, 0, 0, 1, -96, 82,
1368 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, -36, 2, 7, 65, 119, -87, 126};
1369 + DdPacket ddPacket1 = new DdPacket();
1370 + ChannelBuffer buf = ChannelBuffers.buffer(ddPacket.length);
1371 + buf.writeBytes(ddPacket);
1372 + ddPacket1.readFrom(buf);
1373 + return ddPacket1;
1374 + }
1375 +
1376 + /**
1377 + * Utility for test method.
1378 + */
1379 + private OspfInterfaceImpl createOspfInterface() throws UnknownHostException {
1380 + ospfInterface = new OspfInterfaceImpl();
1381 + OspfAreaImpl ospfArea = new OspfAreaImpl();
1382 + OspfInterfaceChannelHandler ospfInterfaceChannelHandler = EasyMock.createMock(
1383 + OspfInterfaceChannelHandler.class);
1384 + ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("10.226.165.164"),
1385 + Ip4Address.valueOf("1.1.1.1"), 2,
1386 + topologyForDeviceAndLink);
1387 + ospfNbr.setState(OspfNeighborState.EXSTART);
1388 + ospfNbr.setNeighborId(Ip4Address.valueOf("10.226.165.100"));
1389 + this.ospfInterface = new OspfInterfaceImpl();
1390 + this.ospfInterface.setIpAddress(Ip4Address.valueOf("10.226.165.164"));
1391 + this.ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
1392 + this.ospfInterface.setBdr(Ip4Address.valueOf("111.111.111.111"));
1393 + this.ospfInterface.setDr(Ip4Address.valueOf("111.111.111.111"));
1394 + this.ospfInterface.setHelloIntervalTime(20);
1395 + this.ospfInterface.setInterfaceType(2);
1396 + this.ospfInterface.setReTransmitInterval(2000);
1397 + this.ospfInterface.setMtu(6500);
1398 + this.ospfInterface.setRouterDeadIntervalTime(1000);
1399 + this.ospfInterface.setRouterPriority(1);
1400 + this.ospfInterface.setInterfaceType(1);
1401 + this.ospfInterface.addNeighbouringRouter(ospfNbr);
1402 + return this.ospfInterface;
1403 + }
1404 +
1405 + /**
1406 + * Utility for test method.
1407 + */
1408 + private OspfInterfaceImpl createOspfInterface1() throws UnknownHostException {
1409 + ospfInterface = new OspfInterfaceImpl();
1410 + OspfAreaImpl ospfArea = new OspfAreaImpl();
1411 + OspfInterfaceChannelHandler ospfInterfaceChannelHandler = EasyMock.createMock(
1412 + OspfInterfaceChannelHandler.class);
1413 + ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("10.226.165.164"),
1414 + Ip4Address.valueOf("1.1.1.1"), 2,
1415 + topologyForDeviceAndLink);
1416 + ospfNbr.setState(OspfNeighborState.FULL);
1417 + ospfNbr.setNeighborId(Ip4Address.valueOf("10.226.165.100"));
1418 + ospfInterface = new OspfInterfaceImpl();
1419 + ospfInterface.setIpAddress(Ip4Address.valueOf("10.226.165.164"));
1420 + ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
1421 + ospfInterface.setBdr(Ip4Address.valueOf("111.111.111.111"));
1422 + ospfInterface.setDr(Ip4Address.valueOf("111.111.111.111"));
1423 + ospfInterface.setHelloIntervalTime(20);
1424 + ospfInterface.setInterfaceType(2);
1425 + ospfInterface.setReTransmitInterval(2000);
1426 + ospfInterface.setMtu(6500);
1427 + ospfInterface.setRouterDeadIntervalTime(1000);
1428 + ospfInterface.setRouterPriority(1);
1429 + ospfInterface.setInterfaceType(1);
1430 + ospfInterface.addNeighbouringRouter(ospfNbr);
1431 + return ospfInterface;
1432 + }
1433 +
1434 + /**
1435 + * Utility for test method.
1436 + */
1437 + private OspfAreaImpl createOspfArea() throws UnknownHostException {
1438 + OspfAreaAddressRangeImpl ospfAreaAddressRange;
1439 + ospfAreaAddressRange = createOspfAreaAddressRange();
1440 + addressRanges.add(ospfAreaAddressRange);
1441 + OspfAreaImpl ospfArea = new OspfAreaImpl();
1442 + ospfArea.setAreaId(Ip4Address.valueOf("10.226.165.164"));
1443 + ospfArea.setExternalRoutingCapability(true);
1444 + OspfInterfaceImpl ospfInterface = createOspfInterface();
1445 + ospfInterfaces.add(ospfInterface);
1446 + ospfArea.setOspfInterfaceList(ospfInterfaces);
1447 + RouterLsa routerLsa = new RouterLsa();
1448 + routerLsa.setLsType(1);
1449 + routerLsa.setLinkStateId("2.2.2.2");
1450 + routerLsa.setAdvertisingRouter(Ip4Address.valueOf("2.2.2.2"));
1451 + try {
1452 + ospfArea.addLsa(routerLsa, false, ospfInterface);
1453 + } catch (Exception e) {
1454 + System.out.println("ospfAreaImpl createOspfArea");
1455 + }
1456 + ospfArea.setRouterId(Ip4Address.valueOf("111.111.111.111"));
1457 +
1458 + return ospfArea;
1459 + }
1460 +
1461 + /**
1462 + * Utility for test method.
1463 + */
1464 + private OspfAreaAddressRangeImpl createOspfAreaAddressRange() {
1465 + OspfAreaAddressRangeImpl ospfAreaAddressRange = new OspfAreaAddressRangeImpl();
1466 + ospfAreaAddressRange.setIpAddress(Ip4Address.valueOf("10.226.165.164"));
1467 + ospfAreaAddressRange.setAdvertise(true);
1468 + ospfAreaAddressRange.setMask("mask");
1469 + return ospfAreaAddressRange;
1470 + }
1471 +
504 } 1472 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -71,7 +71,7 @@ public class ControllerTest { ...@@ -71,7 +71,7 @@ public class ControllerTest {
71 ospfInterface.setIpAddress(Ip4Address.valueOf("1.1.1.1")); 71 ospfInterface.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
72 ospfInterfaces.add(ospfInterface); 72 ospfInterfaces.add(ospfInterface);
73 ospfArea.setAreaId(Ip4Address.valueOf("2.2.2.2")); 73 ospfArea.setAreaId(Ip4Address.valueOf("2.2.2.2"));
74 - ospfArea.setInterfacesLst(ospfInterfaces); 74 + ospfArea.setOspfInterfaceList(ospfInterfaces);
75 ospfProcess.setProcessId("10.10.10.10"); 75 ospfProcess.setProcessId("10.10.10.10");
76 ospfAreas = new ArrayList(); 76 ospfAreas = new ArrayList();
77 ospfAreas.add(ospfArea); 77 ospfAreas.add(ospfArea);
...@@ -82,7 +82,7 @@ public class ControllerTest { ...@@ -82,7 +82,7 @@ public class ControllerTest {
82 ospfProcess1.setProcessId("11.11.11.11"); 82 ospfProcess1.setProcessId("11.11.11.11");
83 ospfArea1 = new OspfAreaImpl(); 83 ospfArea1 = new OspfAreaImpl();
84 ospfArea1.setAreaId(Ip4Address.valueOf("2.2.2.2")); 84 ospfArea1.setAreaId(Ip4Address.valueOf("2.2.2.2"));
85 - ospfArea1.setInterfacesLst(ospfInterfaces); 85 + ospfArea1.setOspfInterfaceList(ospfInterfaces);
86 ospfAreas.add(ospfArea1); 86 ospfAreas.add(ospfArea1);
87 ospfProcess1.setAreas(ospfAreas); 87 ospfProcess1.setAreas(ospfAreas);
88 ospfProcesses.add(ospfProcess1); 88 ospfProcesses.add(ospfProcess1);
...@@ -167,83 +167,6 @@ public class ControllerTest { ...@@ -167,83 +167,6 @@ public class ControllerTest {
167 assertThat(controller, is(notNullValue())); 167 assertThat(controller, is(notNullValue()));
168 } 168 }
169 169
170 - /**
171 - * Tests deleteInterfaceFromArea() method.
172 - */
173 - @Test
174 - public void testDeleteInterfaceFromArea() throws Exception {
175 - controller.updateConfig(ospfProcesses);
176 - assertThat(controller.deleteInterfaceFromArea("10.10.10.10", "2.2.2.2", "1.1.1.1"), is(true));
177 - assertThat(controller.deleteInterfaceFromArea("10.10.10.10", "2.2.2.2", "5.5.5.5"), is(false));
178 - }
179 -
180 - /**
181 - * Tests checkArea() method.
182 - */
183 - @Test
184 - public void testCheckArea() throws Exception {
185 - controller.updateConfig(ospfProcesses);
186 - assertThat(controller.checkArea("10.10.10.10", "2.2.2.2"), is(true));
187 - }
188 -
189 - /**
190 - * Tests checkArea() method.
191 - */
192 - @Test
193 - public void testCheckArea1() throws Exception {
194 - controller.updateConfig(ospfProcesses);
195 - assertThat(controller.checkArea("10.10.10.10", "111.111.111.111"), is(false));
196 - }
197 -
198 - /**
199 - * Tests checkProcess() method.
200 - */
201 - @Test
202 - public void testCheckProcess() throws Exception {
203 - controller.updateConfig(ospfProcesses);
204 - assertThat(controller.checkProcess("3.3.3.3"), is(false));
205 - assertThat(controller.checkProcess("1.1.1.1"), is(false));
206 - }
207 -
208 - /**
209 - * Tests checkInterface() method.
210 - */
211 - @Test
212 - public void testCheckInterface() throws Exception {
213 - controller.updateConfig(ospfProcesses);
214 - assertThat(controller.checkInterface("10.10.10.10", "2.2.2.2", "1.1.1.1"), is(true));
215 - }
216 -
217 - /**
218 - * Tests updateAreaInProcess() method.
219 - */
220 - @Test
221 - public void testUpdateAreaInProcess() throws Exception {
222 - controller.updateConfig(ospfProcesses);
223 - controller.updateAreaInProcess("10.10.10.10", "2.2.2.2", ospfArea);
224 - assertThat(controller, is(notNullValue()));
225 - }
226 -
227 - /**
228 - * Tests updateConfig() method.
229 - */
230 - @Test
231 - public void testUpdateConfig() throws Exception {
232 - controller.updateConfig(ospfProcesses);
233 - controller.updateConfig(ospfProcesses);
234 - controller.updateConfig(ospfProcesses);
235 - assertThat(controller, is(notNullValue()));
236 - }
237 -
238 - /**
239 - * Tests updateConfig() method.
240 - */
241 - @Test
242 - public void testUpdateConfig2() throws Exception {
243 - controller.updateConfig(ospfProcesses);
244 - controller.updateConfig(ospfProcesses);
245 - assertThat(controller, is(notNullValue()));
246 - }
247 170
248 /** 171 /**
249 * Tests updateConfig() method. 172 * Tests updateConfig() method.
...@@ -257,7 +180,7 @@ public class ControllerTest { ...@@ -257,7 +180,7 @@ public class ControllerTest {
257 ospfInterface.setIpAddress(Ip4Address.valueOf("10.10.10.5")); 180 ospfInterface.setIpAddress(Ip4Address.valueOf("10.10.10.5"));
258 ospfInterfaces.add(ospfInterface); 181 ospfInterfaces.add(ospfInterface);
259 ospfArea.setAreaId(Ip4Address.valueOf("2.2.2.2")); 182 ospfArea.setAreaId(Ip4Address.valueOf("2.2.2.2"));
260 - ospfArea.setInterfacesLst(ospfInterfaces); 183 + ospfArea.setOspfInterfaceList(ospfInterfaces);
261 ospfProcess.setProcessId("10.10.10.10"); 184 ospfProcess.setProcessId("10.10.10.10");
262 ospfAreas = new ArrayList(); 185 ospfAreas = new ArrayList();
263 ospfAreas.add(ospfArea); 186 ospfAreas.add(ospfArea);
...@@ -269,67 +192,6 @@ public class ControllerTest { ...@@ -269,67 +192,6 @@ public class ControllerTest {
269 } 192 }
270 193
271 /** 194 /**
272 - * Tests deleteConfig() method.
273 - */
274 - @Test(expected = Exception.class)
275 - public void testDeleteConfig() throws Exception {
276 - controller.updateConfig(ospfProcesses);
277 - controller.deleteConfig(ospfProcesses, "INTERFACE");
278 - assertThat(controller, is(notNullValue()));
279 - }
280 -
281 - /**
282 - * Tests deleteConfig() method.
283 - */
284 - @Test(expected = Exception.class)
285 - public void testDeleteConfig1() throws Exception {
286 - controller.updateConfig(ospfProcesses);
287 - controller.deleteConfig(ospfProcesses, "AREA");
288 - assertThat(controller, is(notNullValue()));
289 - }
290 -
291 - /**
292 - * Tests deleteConfig() method.
293 - */
294 -
295 - @Test
296 - public void testDeleteConfig2() throws Exception {
297 - controller.updateConfig(ospfProcesses);
298 - controller.deleteConfig(ospfProcesses, "PROCESS");
299 - assertThat(controller, is(notNullValue()));
300 - }
301 -
302 - /**
303 - * Tests deleteConfig() method.
304 - */
305 - @Test
306 - public void testDeleteConfig3() throws Exception {
307 - ospfProcesses = new ArrayList();
308 - controller.deleteConfig(ospfProcesses, "PROCESS");
309 - assertThat(controller, is(notNullValue()));
310 - }
311 -
312 - /**
313 - * Tests deleteConfig() method.
314 - */
315 - @Test
316 - public void testDeleteConfig4() throws Exception {
317 - controller.updateConfig(ospfProcesses);
318 - controller.deleteConfig(ospfProcesses, "PROCESS");
319 - controller.updateConfig(ospfProcesses);
320 - assertThat(controller, is(notNullValue()));
321 - }
322 -
323 - /**
324 - * Tests deleteProcessWhenExists() method.
325 - */
326 - @Test
327 - public void testDeleteProcessWhenExists() throws Exception {
328 - controller.updateConfig(ospfProcesses);
329 - controller.deleteProcessWhenExists(ospfProcesses, "PROCESS");
330 - }
331 -
332 - /**
333 * Tests addLinkDetails() method. 195 * Tests addLinkDetails() method.
334 */ 196 */
335 @Test 197 @Test
...@@ -350,7 +212,7 @@ public class ControllerTest { ...@@ -350,7 +212,7 @@ public class ControllerTest {
350 controller.start(ospfAgent, driverService); 212 controller.start(ospfAgent, driverService);
351 ospfRouter = new OspfRouterImpl(); 213 ospfRouter = new OspfRouterImpl();
352 controller.addLinkDetails(ospfRouter, new OspfLinkTedImpl()); 214 controller.addLinkDetails(ospfRouter, new OspfLinkTedImpl());
353 - controller.removeLinkDetails(ospfRouter); 215 + controller.removeLinkDetails(ospfRouter, new OspfLinkTedImpl());
354 assertThat(controller, is(notNullValue())); 216 assertThat(controller, is(notNullValue()));
355 } 217 }
356 } 218 }
...\ No newline at end of file ...\ No newline at end of file
......
1 +/*
2 + * Copyright 2016-present 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 com.fasterxml.jackson.databind.JsonNode;
19 +import com.fasterxml.jackson.databind.ObjectMapper;
20 +import org.junit.After;
21 +import org.junit.Before;
22 +import org.junit.Test;
23 +import org.onosproject.ospf.controller.OspfProcess;
24 +
25 +import java.util.ArrayList;
26 +import java.util.List;
27 +
28 +import static org.hamcrest.CoreMatchers.is;
29 +import static org.hamcrest.CoreMatchers.notNullValue;
30 +import static org.hamcrest.MatcherAssert.assertThat;
31 +
32 +/**
33 + * Unit test class for OspfJsonParsingUtilTest.
34 + */
35 +public class OspfConfigUtilTest {
36 + private ObjectMapper mapper;
37 + private JsonNode jsonNode;
38 + private List<OspfProcess> ospfProcessList = new ArrayList<>();
39 + private String jsonString = "{\n" +
40 + "\t\"processes\": {\n" +
41 + "\t\t\"areas\": [{\n" +
42 + "\t\t\t\"interface\": [{\n" +
43 + "\t\t\t\t\"interfaceIndex\": \"2\",\n" +
44 + "\n" +
45 + "\t\t\t\t\"helloIntervalTime\": \"10\",\n" +
46 + "\n" +
47 + "\t\t\t\t\"routerDeadIntervalTime\": \"40\",\n" +
48 + "\n" +
49 + "\t\t\t\t\"interfaceType\": \"2\",\n" +
50 + "\n" +
51 + "\t\t\t\t\"reTransmitInterval\": \"5\"\n" +
52 + "\t\t\t}],\n" +
53 + "\t\t\t\"areaId\": \"5.5.5.5\",\n" +
54 + "\n" +
55 + "\t\t\t\"routerId\": \"7.7.7.7\",\n" +
56 + "\n" +
57 + "\t\t\t\"isOpaqueEnable\": \"false\",\n" +
58 + "\n" +
59 + "\t\t\t\"externalRoutingCapability\": \"true\"\n" +
60 + "\t\t}]\n" +
61 + "\t}\n" +
62 + "}";
63 +
64 + @Before
65 + public void setUp() throws Exception {
66 + mapper = new ObjectMapper();
67 + jsonNode = mapper.readTree(jsonString);
68 + mapper = new ObjectMapper();
69 + }
70 +
71 + @After
72 + public void tearDown() throws Exception {
73 +
74 + }
75 +
76 + @Test
77 + public void testProcesses() throws Exception {
78 + jsonNode.path("areas");
79 + ospfProcessList = OspfConfigUtil.processes(jsonNode);
80 + assertThat(ospfProcessList, is(notNullValue()));
81 + }
82 +}
...\ No newline at end of file ...\ No newline at end of file
...@@ -46,10 +46,8 @@ public class OspfControllerImplTest { ...@@ -46,10 +46,8 @@ public class OspfControllerImplTest {
46 private OspfControllerImpl ospfController; 46 private OspfControllerImpl ospfController;
47 private OspfRouterListener ospfRouterListener; 47 private OspfRouterListener ospfRouterListener;
48 private OspfLinkListener ospfLinkListener; 48 private OspfLinkListener ospfLinkListener;
49 - private Controller controller;
50 private List<OspfProcess> ospfProcesses; 49 private List<OspfProcess> ospfProcesses;
51 private OspfProcess process1; 50 private OspfProcess process1;
52 - private OspfProcess process2;
53 private List<OspfArea> areas; 51 private List<OspfArea> areas;
54 private OspfAreaImpl ospfArea; 52 private OspfAreaImpl ospfArea;
55 private List<OspfInterface> ospfInterfaces; 53 private List<OspfInterface> ospfInterfaces;
...@@ -61,7 +59,6 @@ public class OspfControllerImplTest { ...@@ -61,7 +59,6 @@ public class OspfControllerImplTest {
61 @Before 59 @Before
62 public void setUp() throws Exception { 60 public void setUp() throws Exception {
63 ospfController = new OspfControllerImpl(); 61 ospfController = new OspfControllerImpl();
64 - controller = new Controller();
65 } 62 }
66 63
67 @After 64 @After
...@@ -69,7 +66,6 @@ public class OspfControllerImplTest { ...@@ -69,7 +66,6 @@ public class OspfControllerImplTest {
69 ospfController = null; 66 ospfController = null;
70 ospfRouterListener = null; 67 ospfRouterListener = null;
71 ospfLinkListener = null; 68 ospfLinkListener = null;
72 - controller = null;
73 ospfProcesses = null; 69 ospfProcesses = null;
74 areas = null; 70 areas = null;
75 ospfArea = null; 71 ospfArea = null;
...@@ -140,38 +136,6 @@ public class OspfControllerImplTest { ...@@ -140,38 +136,6 @@ public class OspfControllerImplTest {
140 } 136 }
141 137
142 /** 138 /**
143 - * Tests updateConfig() method.
144 - */
145 - @Test
146 - public void testUpdateConfig() throws Exception {
147 - ospfProcess = new OspfProcessImpl();
148 - ospfArea = new OspfAreaImpl();
149 - ospfInterface = new OspfInterfaceImpl();
150 - ospfInterfaces = new ArrayList();
151 - ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11"));
152 - ospfInterfaces.add(ospfInterface);
153 - ospfArea.setAreaId(Ip4Address.valueOf("2.2.2.2"));
154 - ospfArea.setInterfacesLst(ospfInterfaces);
155 - ospfProcess.setProcessId("10.10.10.10");
156 - areas = new ArrayList();
157 - areas.add(ospfArea);
158 - ospfProcess.setAreas(areas);
159 - ospfProcesses = new ArrayList();
160 - ospfProcesses.add(ospfProcess);
161 - process1 = new OspfProcessImpl();
162 - process1.setProcessId("11.11.11.11");
163 - ospfArea1 = new OspfAreaImpl();
164 - ospfArea1.setAreaId(Ip4Address.valueOf("2.2.2.2"));
165 - ospfArea1.setInterfacesLst(ospfInterfaces);
166 - areas.add(ospfArea1);
167 - process1.setAreas(areas);
168 - ospfProcesses.add(process1);
169 - ospfController.updateConfig(ospfProcesses);
170 - assertThat(ospfController, is(notNullValue()));
171 -
172 - }
173 -
174 - /**
175 * Tests deleteConfig() method. 139 * Tests deleteConfig() method.
176 */ 140 */
177 @Test 141 @Test
...@@ -183,7 +147,7 @@ public class OspfControllerImplTest { ...@@ -183,7 +147,7 @@ public class OspfControllerImplTest {
183 ospfInterface.setIpAddress(Ip4Address.valueOf("10.10.10.5")); 147 ospfInterface.setIpAddress(Ip4Address.valueOf("10.10.10.5"));
184 ospfInterfaces.add(ospfInterface); 148 ospfInterfaces.add(ospfInterface);
185 ospfArea.setAreaId(Ip4Address.valueOf("2.2.2.2")); 149 ospfArea.setAreaId(Ip4Address.valueOf("2.2.2.2"));
186 - ospfArea.setInterfacesLst(ospfInterfaces); 150 + ospfArea.setOspfInterfaceList(ospfInterfaces);
187 ospfProcess.setProcessId("10.10.10.10"); 151 ospfProcess.setProcessId("10.10.10.10");
188 areas = new ArrayList(); 152 areas = new ArrayList();
189 areas.add(ospfArea); 153 areas.add(ospfArea);
...@@ -194,7 +158,7 @@ public class OspfControllerImplTest { ...@@ -194,7 +158,7 @@ public class OspfControllerImplTest {
194 process1.setProcessId("11.11.11.11"); 158 process1.setProcessId("11.11.11.11");
195 ospfArea1 = new OspfAreaImpl(); 159 ospfArea1 = new OspfAreaImpl();
196 ospfArea1.setAreaId(Ip4Address.valueOf("2.2.2.2")); 160 ospfArea1.setAreaId(Ip4Address.valueOf("2.2.2.2"));
197 - ospfArea1.setInterfacesLst(ospfInterfaces); 161 + ospfArea1.setOspfInterfaceList(ospfInterfaces);
198 areas.add(ospfArea1); 162 areas.add(ospfArea1);
199 process1.setAreas(areas); 163 process1.setAreas(areas);
200 ospfProcesses.add(process1); 164 ospfProcesses.add(process1);
...@@ -221,7 +185,7 @@ public class OspfControllerImplTest { ...@@ -221,7 +185,7 @@ public class OspfControllerImplTest {
221 ospfRouter = new OspfRouterImpl(); 185 ospfRouter = new OspfRouterImpl();
222 186
223 ospfController.agent.addLink(ospfRouter, new OspfLinkTedImpl()); 187 ospfController.agent.addLink(ospfRouter, new OspfLinkTedImpl());
224 - ospfController.agent.deleteLink(ospfRouter); 188 + ospfController.agent.deleteLink(ospfRouter, new OspfLinkTedImpl());
225 assertThat(ospfController, is(notNullValue())); 189 assertThat(ospfController, is(notNullValue()));
226 } 190 }
227 191
......
...@@ -21,6 +21,7 @@ import org.junit.Test; ...@@ -21,6 +21,7 @@ import org.junit.Test;
21 import org.onlab.packet.Ip4Address; 21 import org.onlab.packet.Ip4Address;
22 import org.onlab.packet.Ip6Address; 22 import org.onlab.packet.Ip6Address;
23 23
24 +import java.net.InetAddress;
24 import java.util.ArrayList; 25 import java.util.ArrayList;
25 import java.util.List; 26 import java.util.List;
26 27
...@@ -31,8 +32,6 @@ import static org.junit.Assert.assertThat; ...@@ -31,8 +32,6 @@ import static org.junit.Assert.assertThat;
31 * Unit test class for OspfDeviceTedImpl. 32 * Unit test class for OspfDeviceTedImpl.
32 */ 33 */
33 public class OspfDeviceTedImplTest { 34 public class OspfDeviceTedImplTest {
34 - private static final Ip6Address LOCAL_ADDRESS = Ip6Address.valueOf("::1");
35 -
36 private OspfDeviceTedImpl ospfDeviceTed; 35 private OspfDeviceTedImpl ospfDeviceTed;
37 36
38 @Before 37 @Before
...@@ -128,10 +127,10 @@ public class OspfDeviceTedImplTest { ...@@ -128,10 +127,10 @@ public class OspfDeviceTedImplTest {
128 /** 127 /**
129 * Tests ipv6RouterIds() getter method. 128 * Tests ipv6RouterIds() getter method.
130 */ 129 */
131 - @Test 130 + @Test(expected = Exception.class)
132 public void testIpv6RouterIds() throws Exception { 131 public void testIpv6RouterIds() throws Exception {
133 List list = new ArrayList(); 132 List list = new ArrayList();
134 - list.add(LOCAL_ADDRESS); 133 + list.add(Ip6Address.valueOf(InetAddress.getLocalHost()));
135 ospfDeviceTed.setIpv6RouterIds(list); 134 ospfDeviceTed.setIpv6RouterIds(list);
136 assertThat(ospfDeviceTed.ipv6RouterIds().size(), is(1)); 135 assertThat(ospfDeviceTed.ipv6RouterIds().size(), is(1));
137 } 136 }
...@@ -139,10 +138,10 @@ public class OspfDeviceTedImplTest { ...@@ -139,10 +138,10 @@ public class OspfDeviceTedImplTest {
139 /** 138 /**
140 * Tests ipv6RouterIds() setter method. 139 * Tests ipv6RouterIds() setter method.
141 */ 140 */
142 - @Test 141 + @Test(expected = Exception.class)
143 public void testSetIpv6RouterIds() throws Exception { 142 public void testSetIpv6RouterIds() throws Exception {
144 List list = new ArrayList(); 143 List list = new ArrayList();
145 - list.add(LOCAL_ADDRESS); 144 + list.add(Ip6Address.valueOf(InetAddress.getLocalHost()));
146 ospfDeviceTed.setIpv6RouterIds(list); 145 ospfDeviceTed.setIpv6RouterIds(list);
147 assertThat(ospfDeviceTed.ipv6RouterIds().size(), is(1)); 146 assertThat(ospfDeviceTed.ipv6RouterIds().size(), is(1));
148 } 147 }
......
...@@ -18,9 +18,7 @@ package org.onosproject.ospf.controller.impl; ...@@ -18,9 +18,7 @@ package org.onosproject.ospf.controller.impl;
18 import org.easymock.EasyMock; 18 import org.easymock.EasyMock;
19 import org.jboss.netty.buffer.ChannelBuffer; 19 import org.jboss.netty.buffer.ChannelBuffer;
20 import org.jboss.netty.buffer.ChannelBuffers; 20 import org.jboss.netty.buffer.ChannelBuffers;
21 -import org.jboss.netty.buffer.HeapChannelBufferFactory;
22 import org.jboss.netty.channel.Channel; 21 import org.jboss.netty.channel.Channel;
23 -import org.jboss.netty.channel.ChannelConfig;
24 import org.jboss.netty.channel.ChannelFuture; 22 import org.jboss.netty.channel.ChannelFuture;
25 import org.jboss.netty.channel.ChannelHandlerContext; 23 import org.jboss.netty.channel.ChannelHandlerContext;
26 import org.jboss.netty.channel.ChannelStateEvent; 24 import org.jboss.netty.channel.ChannelStateEvent;
...@@ -30,34 +28,27 @@ import org.junit.After; ...@@ -30,34 +28,27 @@ import org.junit.After;
30 import org.junit.Before; 28 import org.junit.Before;
31 import org.junit.Test; 29 import org.junit.Test;
32 import org.onlab.packet.Ip4Address; 30 import org.onlab.packet.Ip4Address;
31 +import org.onosproject.ospf.controller.OspfArea;
33 import org.onosproject.ospf.controller.OspfAreaAddressRange; 32 import org.onosproject.ospf.controller.OspfAreaAddressRange;
34 import org.onosproject.ospf.controller.OspfInterface; 33 import org.onosproject.ospf.controller.OspfInterface;
35 -import org.onosproject.ospf.controller.OspfNbr; 34 +import org.onosproject.ospf.controller.OspfLsaType;
36 import org.onosproject.ospf.controller.OspfNeighborState; 35 import org.onosproject.ospf.controller.OspfNeighborState;
36 +import org.onosproject.ospf.controller.OspfProcess;
37 import org.onosproject.ospf.controller.TopologyForDeviceAndLink; 37 import org.onosproject.ospf.controller.TopologyForDeviceAndLink;
38 import org.onosproject.ospf.controller.area.OspfAreaAddressRangeImpl; 38 import org.onosproject.ospf.controller.area.OspfAreaAddressRangeImpl;
39 import org.onosproject.ospf.controller.area.OspfAreaImpl; 39 import org.onosproject.ospf.controller.area.OspfAreaImpl;
40 import org.onosproject.ospf.controller.area.OspfInterfaceImpl; 40 import org.onosproject.ospf.controller.area.OspfInterfaceImpl;
41 -import org.onosproject.ospf.controller.util.OspfEligibleRouter; 41 +import org.onosproject.ospf.controller.area.OspfProcessImpl;
42 import org.onosproject.ospf.exceptions.OspfParseException; 42 import org.onosproject.ospf.exceptions.OspfParseException;
43 import org.onosproject.ospf.protocol.lsa.LsaHeader; 43 import org.onosproject.ospf.protocol.lsa.LsaHeader;
44 -import org.onosproject.ospf.protocol.lsa.TlvHeader;
45 -import org.onosproject.ospf.protocol.lsa.tlvtypes.RouterTlv;
46 import org.onosproject.ospf.protocol.lsa.types.RouterLsa; 44 import org.onosproject.ospf.protocol.lsa.types.RouterLsa;
47 -import org.onosproject.ospf.protocol.ospfpacket.OspfMessage;
48 -import org.onosproject.ospf.protocol.ospfpacket.subtype.LsRequestPacket;
49 import org.onosproject.ospf.protocol.ospfpacket.types.DdPacket; 45 import org.onosproject.ospf.protocol.ospfpacket.types.DdPacket;
50 import org.onosproject.ospf.protocol.ospfpacket.types.HelloPacket; 46 import org.onosproject.ospf.protocol.ospfpacket.types.HelloPacket;
51 -import org.onosproject.ospf.protocol.ospfpacket.types.LsAcknowledge;
52 -import org.onosproject.ospf.protocol.ospfpacket.types.LsRequest;
53 -import org.onosproject.ospf.protocol.ospfpacket.types.LsUpdate;
54 import org.onosproject.ospf.protocol.util.ChecksumCalculator; 47 import org.onosproject.ospf.protocol.util.ChecksumCalculator;
55 -import org.onosproject.ospf.protocol.util.OspfInterfaceState;
56 48
57 import java.net.SocketAddress; 49 import java.net.SocketAddress;
58 import java.net.UnknownHostException; 50 import java.net.UnknownHostException;
59 import java.util.ArrayList; 51 import java.util.ArrayList;
60 -import java.util.HashMap;
61 import java.util.List; 52 import java.util.List;
62 53
63 import static org.hamcrest.CoreMatchers.is; 54 import static org.hamcrest.CoreMatchers.is;
...@@ -69,214 +60,143 @@ import static org.hamcrest.MatcherAssert.assertThat; ...@@ -69,214 +60,143 @@ import static org.hamcrest.MatcherAssert.assertThat;
69 * Unit test class for OspfInterfaceChannelHandler. 60 * Unit test class for OspfInterfaceChannelHandler.
70 */ 61 */
71 public class OspfInterfaceChannelHandlerTest { 62 public class OspfInterfaceChannelHandlerTest {
72 - 63 + private final String string1 = "2.2.2.2";
73 - private List<OspfAreaAddressRange> addressRanges; 64 + private List<OspfAreaAddressRange> addressRanges = new ArrayList();
74 - private List<OspfInterface> ospfInterfaces; 65 + private List<OspfInterface> ospfInterfaces = new ArrayList<>();
75 private Controller controller; 66 private Controller controller;
76 private OspfAreaImpl ospfArea; 67 private OspfAreaImpl ospfArea;
77 private OspfInterfaceImpl ospfInterface; 68 private OspfInterfaceImpl ospfInterface;
78 private OspfInterfaceChannelHandler ospfInterfaceChannelHandler; 69 private OspfInterfaceChannelHandler ospfInterfaceChannelHandler;
79 - private HashMap<String, OspfNbr> ospfNbrHashMap;
80 private OspfNbrImpl ospfNbr; 70 private OspfNbrImpl ospfNbr;
81 - private Channel channel;
82 private ChannelHandlerContext channelHandlerContext; 71 private ChannelHandlerContext channelHandlerContext;
83 private ChannelStateEvent channelStateEvent; 72 private ChannelStateEvent channelStateEvent;
84 - private HelloPacket helloPacket; 73 + private TopologyForDeviceAndLink topologyForDeviceAndLink;
85 - private DdPacket ddPacket; 74 + private List<OspfProcess> ospfProcesses = new ArrayList<>();
86 - private ChecksumCalculator checksumCalculator; 75 + private OspfProcess ospfProcess;
76 + private Ip4Address ip4Address1 = Ip4Address.valueOf("10.10.10.10");
77 + private Ip4Address ip4Address2 = Ip4Address.valueOf("2.2.2.2");
78 + private Ip4Address ip4Address3 = Ip4Address.valueOf("13.13.13.13");
79 + private Ip4Address ip4Address4 = Ip4Address.valueOf("111.111.111.111");
80 + private Ip4Address ip4Address5 = Ip4Address.valueOf("10.226.165.164");
81 + private Ip4Address ip4Address6 = Ip4Address.valueOf("1.1.1.1");
82 + private Ip4Address ip4Address7 = Ip4Address.valueOf("10.226.165.100");
83 + private Ip4Address subnetAddress = Ip4Address.valueOf("255.255.255.255");
87 private byte[] byteArray; 84 private byte[] byteArray;
88 private byte[] checkArray; 85 private byte[] checkArray;
86 + private HelloPacket helloPacket;
87 + private ChecksumCalculator checksumCalculator;
89 private ChannelBuffer buf; 88 private ChannelBuffer buf;
90 - private OspfEligibleRouter ospfEligibleRouter; 89 + private List<OspfArea> ospfAreas = new ArrayList<>();
91 - private LsUpdate lsUpdate;
92 - private LsAcknowledge lsAck;
93 - private LsRequest lsRequest;
94 - private TopologyForDeviceAndLink topologyForDeviceAndLink;
95 90
96 @Before 91 @Before
97 public void setUp() throws Exception { 92 public void setUp() throws Exception {
98 - addressRanges = new ArrayList(); 93 + ospfProcess = new OspfProcessImpl();
99 - ospfInterfaces = new ArrayList<>();
100 ospfArea = createOspfArea(); 94 ospfArea = createOspfArea();
101 - ospfInterface = createOspfInterface(); 95 + ospfAreas.add(ospfArea);
102 - ospfNbrHashMap = new HashMap(); 96 + ospfProcess.setAreas(ospfAreas);
97 + ospfProcesses.add(ospfProcess);
98 + controller = new Controller();
103 topologyForDeviceAndLink = new TopologyForDeviceAndLinkImpl(); 99 topologyForDeviceAndLink = new TopologyForDeviceAndLinkImpl();
104 - ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("10.10.10.10"), 100 + ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface, ip4Address1,
105 - Ip4Address.valueOf("2.2.2.2"), 2, 101 + ip4Address2, 2, topologyForDeviceAndLink);
106 - new OspfInterfaceChannelHandler(new Controller(), ospfArea, 102 + ospfNbr.setNeighborId(ip4Address1);
107 - ospfInterface),
108 - topologyForDeviceAndLink);
109 - ospfNbr.setNeighborId(Ip4Address.valueOf("10.10.10.10"));
110 ospfNbr.setRouterPriority(0); 103 ospfNbr.setRouterPriority(0);
111 - ospfNbr.setNeighborDr(Ip4Address.valueOf("13.13.13.13")); 104 + ospfNbr.setNeighborDr(ip4Address3);
112 ospfInterface.addNeighbouringRouter(ospfNbr); 105 ospfInterface.addNeighbouringRouter(ospfNbr);
113 - controller = new Controller(); 106 + ospfInterfaceChannelHandler = new OspfInterfaceChannelHandler(controller, ospfProcesses);
114 - ospfInterfaceChannelHandler = new OspfInterfaceChannelHandler();
115 - ospfInterfaceChannelHandler = new OspfInterfaceChannelHandler(controller, ospfArea,
116 - ospfInterface);
117 } 107 }
118 108
119 @After 109 @After
120 public void tearDown() throws Exception { 110 public void tearDown() throws Exception {
121 ospfInterfaceChannelHandler = null; 111 ospfInterfaceChannelHandler = null;
122 - addressRanges = null;
123 - ospfInterfaces = null;
124 - controller = null;
125 - ospfArea = null;
126 ospfInterfaceChannelHandler = null; 112 ospfInterfaceChannelHandler = null;
127 ospfInterface = null; 113 ospfInterface = null;
128 - ospfNbrHashMap = null;
129 - channel = null;
130 channelHandlerContext = null; 114 channelHandlerContext = null;
131 channelStateEvent = null; 115 channelStateEvent = null;
132 - helloPacket = null;
133 - ddPacket = null;
134 - checksumCalculator = null;
135 - byteArray = null;
136 - checkArray = null;
137 - ospfEligibleRouter = null;
138 - lsUpdate = null;
139 - lsAck = null;
140 - lsRequest = null;
141 } 116 }
142 117
143 /** 118 /**
144 - * Tests interfaceUp() method. 119 + * Tests channelConnected() method.
145 */ 120 */
146 - @Test 121 + @Test(expected = Exception.class)
147 - public void testInterfaceUp() throws Exception { 122 + public void testChannelConnected() throws Exception {
148 - ospfInterface.setInterfaceType(2); 123 + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
149 - ospfInterface.setRouterPriority(0); 124 + channelStateEvent = EasyMock.createMock(ChannelStateEvent.class);
150 - ospfInterfaceChannelHandler.interfaceUp(); 125 + ospfInterfaceChannelHandler.channelConnected(channelHandlerContext, channelStateEvent);
151 - assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
152 } 126 }
153 127
154 /** 128 /**
155 - * Tests interfaceUp() method. 129 + * Tests exceptionCaught() method.
156 */ 130 */
157 - @Test 131 + @Test(expected = Exception.class)
158 - public void testInterfaceUp1() throws Exception { 132 + public void testExceptionCaught() throws Exception {
159 - 133 + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
160 - ospfInterface.setInterfaceType(2); 134 + ExceptionEvent exception = EasyMock.createMock(ExceptionEvent.class);
161 - ospfInterface.setRouterPriority(0); 135 + ospfInterfaceChannelHandler.exceptionCaught(channelHandlerContext, exception);
162 - ospfInterfaceChannelHandler.interfaceUp();
163 assertThat(ospfInterfaceChannelHandler, is(notNullValue())); 136 assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
164 } 137 }
165 138
166 /** 139 /**
167 - * Tests interfaceUp() method. 140 + * Tests channelDisconnected() method.
168 */ 141 */
169 @Test 142 @Test
170 - public void testInterfaceUp2() throws Exception { 143 + public void testChannelDisconnected() throws Exception {
171 - ospfInterface.setInterfaceType(1); 144 + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
172 - ospfInterface.setRouterPriority(1); 145 + channelStateEvent = EasyMock.createMock(ChannelStateEvent.class);
173 - ospfInterfaceChannelHandler.interfaceUp(); 146 + ospfInterfaceChannelHandler.channelDisconnected(channelHandlerContext, channelStateEvent);
174 assertThat(ospfInterfaceChannelHandler, is(notNullValue())); 147 assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
175 } 148 }
176 149
177 /** 150 /**
178 - * Tests interfaceUp() method. 151 + * Tests initializeInterfaceMap() method.
179 */ 152 */
180 @Test 153 @Test
181 - public void testInterfaceUp3() throws Exception { 154 + public void testInitializeInterfaceMap() throws Exception {
182 - ospfInterface.setInterfaceType(2); 155 + ospfInterfaceChannelHandler.initializeInterfaceMap();
183 - ospfInterface.setRouterPriority(1);
184 - ospfInterfaceChannelHandler.interfaceUp();
185 assertThat(ospfInterfaceChannelHandler, is(notNullValue())); 156 assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
186 } 157 }
187 158
188 /** 159 /**
189 - * Tests backupSeen() method. 160 + * Tests updateInterfaceMap() method.
190 - */
191 - @Test
192 - public void testBackupSeen() throws Exception {
193 - channel = EasyMock.createMock(Channel.class);
194 - ospfInterface.setState(OspfInterfaceState.WAITING);
195 - ospfInterfaceChannelHandler.backupSeen(channel);
196 - assertThat(ospfInterface.dr(), is(notNullValue()));
197 - }
198 -
199 - /**
200 - * Tests waitTimer() method.
201 - */
202 - @Test
203 - public void testWaitTimer() throws Exception {
204 - channel = EasyMock.createMock(Channel.class);
205 - ospfInterface.setState(OspfInterfaceState.WAITING);
206 - ospfInterface.setIpAddress(Ip4Address.valueOf("10.10.10.10"));
207 - ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
208 - ospfInterfaceChannelHandler.waitTimer(channel);
209 - assertThat(ospfInterface.dr(), is(notNullValue()));
210 - }
211 -
212 - /**
213 - * Tests neighborChange() method.
214 */ 161 */
215 @Test 162 @Test
216 - public void testNeighborChange() throws Exception { 163 + public void testUpdateInterfaceMap() throws Exception {
217 - ospfNbrHashMap = new HashMap(); 164 + ospfInterfaceChannelHandler.updateInterfaceMap(ospfProcesses);
218 - ospfNbr = new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(), 165 + assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
219 - Ip4Address.valueOf("1.1.1.1"), Ip4Address.valueOf("2.2.2.2"), 2,
220 - new OspfInterfaceChannelHandler(new Controller(),
221 - new OspfAreaImpl(),
222 - new OspfInterfaceImpl()),
223 - topologyForDeviceAndLink);
224 - ospfNbr.setNeighborId(Ip4Address.valueOf("111.111.111.111"));
225 - ospfNbrHashMap.put("111.111.111.111", ospfNbr);
226 - ospfNbr.setState(OspfNeighborState.EXCHANGE);
227 - ospfInterface.setListOfNeighbors(ospfNbrHashMap);
228 - ospfInterface.setIpAddress(Ip4Address.valueOf("10.10.10.10"));
229 - ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
230 - ospfInterface.setIpAddress(Ip4Address.valueOf("10.10.10.10"));
231 - ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
232 - channel = EasyMock.createMock(Channel.class);
233 - ospfInterface.setState(OspfInterfaceState.DR);
234 - ospfInterfaceChannelHandler.waitTimer(channel);
235 - assertThat(ospfInterface.dr(), is(Ip4Address.valueOf("0.0.0.0")));
236 - }
237 -
238 - /**
239 - * Tests interfaceDown() method.
240 - */
241 - @Test(expected = Exception.class)
242 - public void testInterfaceDown() throws Exception {
243 - ospfInterfaceChannelHandler.interfaceDown();
244 - assertThat(ospfInterface.state(), is(OspfInterfaceState.DOWN));
245 } 166 }
246 167
247 /** 168 /**
248 - * Tests channelConnected() method. 169 + * Utility for test method.
249 */ 170 */
250 - @Test(expected = Exception.class) 171 + private OspfAreaImpl createOspfArea() throws Exception {
251 - public void testChannelConnected() throws Exception { 172 + OspfAreaAddressRangeImpl ospfAreaAddressRange;
252 - channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class); 173 + ospfAreaAddressRange = createOspfAreaAddressRange();
253 - channelStateEvent = EasyMock.createMock(ChannelStateEvent.class); 174 + addressRanges.add(ospfAreaAddressRange);
254 - ospfInterfaceChannelHandler.channelConnected(channelHandlerContext, channelStateEvent); 175 + OspfAreaImpl ospfArea = new OspfAreaImpl();
255 - assertThat(ospfInterface.state(), is(notNullValue())); 176 + ospfArea.setAreaId(ip4Address5);
256 - } 177 + ospfArea.setExternalRoutingCapability(true);
178 + OspfInterfaceImpl ospfInterface = createOspfInterface();
179 + ospfInterfaces.add(ospfInterface);
180 + ospfArea.setOspfInterfaceList(ospfInterfaces);
181 + RouterLsa routerLsa = new RouterLsa();
182 + routerLsa.setLsType(1);
183 + routerLsa.setLinkStateId(string1);
184 + routerLsa.setAdvertisingRouter(ip4Address2);
185 + ospfArea.addLsa(routerLsa, false, ospfInterface);
186 + ospfArea.setRouterId(ip4Address4);
257 187
258 - /** 188 + return ospfArea;
259 - * Tests exceptionCaught() method.
260 - */
261 - @Test(expected = Exception.class)
262 - public void testExceptionCaught() throws Exception {
263 - channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
264 - ExceptionEvent exception = EasyMock.createMock(ExceptionEvent.class);
265 - ospfInterfaceChannelHandler.exceptionCaught(channelHandlerContext, exception);
266 - assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
267 } 189 }
268 190
269 /** 191 /**
270 - * Tests channelDisconnected() method. 192 + * Utility for test method.
271 */ 193 */
272 - @Test(expected = Exception.class) 194 + private OspfAreaAddressRangeImpl createOspfAreaAddressRange() {
273 - public void testChannelDisconnected() throws Exception { 195 + OspfAreaAddressRangeImpl ospfAreaAddressRange = new OspfAreaAddressRangeImpl();
274 - channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class); 196 + ospfAreaAddressRange.setIpAddress(ip4Address5);
275 - channelStateEvent = EasyMock.createMock(ChannelStateEvent.class); 197 + ospfAreaAddressRange.setAdvertise(true);
276 - 198 + ospfAreaAddressRange.setMask("mask");
277 - ospfInterfaceChannelHandler.channelDisconnected(channelHandlerContext, channelStateEvent); 199 + return ospfAreaAddressRange;
278 -
279 - assertThat(ospfInterface.state(), is(notNullValue()));
280 } 200 }
281 201
282 /** 202 /**
...@@ -333,752 +253,6 @@ public class OspfInterfaceChannelHandlerTest { ...@@ -333,752 +253,6 @@ public class OspfInterfaceChannelHandlerTest {
333 } 253 }
334 254
335 /** 255 /**
336 - * Tests processOspfMessage() method.
337 - */
338 - @Test
339 - public void testProcessOspfMessage() throws Exception {
340 - ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11"));
341 - ospfInterface.setIpNetworkMask(Ip4Address.valueOf("225.225.225.225"));
342 - ospfInterface.setInterfaceType(2);
343 - ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12"));
344 - channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
345 - OspfMessage message;
346 - helloPacket = new HelloPacket();
347 - helloPacket.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
348 - helloPacket.setRouterId(Ip4Address.valueOf("10.10.10.10"));
349 - helloPacket.setOspfVer(2);
350 - helloPacket.setAreaId(Ip4Address.valueOf("12.12.12.12"));
351 - helloPacket.setOptions(2);
352 - helloPacket.setNetworkMask(Ip4Address.valueOf("3.3.3.3"));
353 - helloPacket.setOspftype(1);
354 - helloPacket.setAuthType(0);
355 - helloPacket.setHelloInterval(60);
356 - helloPacket.setRouterDeadInterval(60);
357 - helloPacket.setAuthentication(0);
358 - checksumCalculator = new ChecksumCalculator();
359 - byteArray = helloPacket.asBytes();
360 - helloPacket.setOspfPacLength(byteArray.length);
361 - checkArray = checksumCalculator.calculateOspfCheckSum(byteArray, 12, 13);
362 - checkArray[0] = -53;
363 - checkArray[1] = 37;
364 - buf = ChannelBuffers.copiedBuffer(checkArray);
365 - helloPacket.setChecksum(buf.readUnsignedShort());
366 - message = helloPacket;
367 - ospfInterfaceChannelHandler.processOspfMessage(message, channelHandlerContext);
368 - ddPacket = new DdPacket();
369 - ddPacket.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
370 - ddPacket.setRouterId(Ip4Address.valueOf("10.10.10.10"));
371 - ddPacket.setOspfVer(2);
372 - ddPacket.setAreaId(Ip4Address.valueOf("12.12.12.12"));
373 - ddPacket.setOptions(2);
374 - ddPacket.setOspftype(2);
375 - ddPacket.setAuthType(0);
376 - ddPacket.setAuthentication(0);
377 - checksumCalculator = new ChecksumCalculator();
378 - byteArray = ddPacket.asBytes();
379 - ddPacket.setOspfPacLength(byteArray.length);
380 - checkArray = checksumCalculator.calculateOspfCheckSum(byteArray, 12, 13);
381 - checkArray[0] = -49;
382 - checkArray[1] = -79;
383 - buf = ChannelBuffers.copiedBuffer(checkArray);
384 - ddPacket.setChecksum(buf.readUnsignedShort());
385 - message = ddPacket;
386 - ospfInterfaceChannelHandler.processOspfMessage(message, channelHandlerContext);
387 - lsRequest = new LsRequest();
388 - lsRequest.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
389 - lsRequest.setRouterId(Ip4Address.valueOf("10.10.10.10"));
390 - lsRequest.setOspfVer(2);
391 - lsRequest.setAreaId(Ip4Address.valueOf("12.12.12.12"));
392 - lsRequest.setOspftype(3);
393 - lsRequest.setAuthType(0);
394 - lsRequest.setAuthentication(0);
395 - checksumCalculator = new ChecksumCalculator();
396 - byteArray = lsRequest.asBytes();
397 - lsRequest.setOspfPacLength(byteArray.length);
398 - checkArray = checksumCalculator.calculateOspfCheckSum(byteArray, 12, 13);
399 - checkArray[0] = -33;
400 - checkArray[1] = -58;
401 - buf = ChannelBuffers.copiedBuffer(checkArray);
402 - lsRequest.setChecksum(buf.readUnsignedShort());
403 - message = lsRequest;
404 - ospfInterfaceChannelHandler.processOspfMessage(message, channelHandlerContext);
405 - lsUpdate = new LsUpdate();
406 - lsUpdate.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
407 - lsUpdate.setRouterId(Ip4Address.valueOf("10.10.10.10"));
408 - lsUpdate.setOspfVer(2);
409 - lsUpdate.setAreaId(Ip4Address.valueOf("12.12.12.12"));
410 - lsUpdate.setOspftype(4);
411 - lsUpdate.setAuthType(0);
412 - lsUpdate.setAuthentication(0);
413 - checksumCalculator = new ChecksumCalculator();
414 - byteArray = lsUpdate.asBytes();
415 - lsUpdate.setOspfPacLength(byteArray.length);
416 - checkArray = checksumCalculator.calculateOspfCheckSum(byteArray, 12, 13);
417 - checkArray[0] = -47;
418 - checkArray[1] = -77;
419 - buf = ChannelBuffers.copiedBuffer(checkArray);
420 - lsUpdate.setChecksum(buf.readUnsignedShort());
421 - message = lsUpdate;
422 - ospfInterfaceChannelHandler.processOspfMessage(message, channelHandlerContext);
423 - lsAck = new LsAcknowledge();
424 - lsAck.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
425 - lsAck.setRouterId(Ip4Address.valueOf("10.10.10.10"));
426 - lsAck.setOspfVer(2);
427 - lsAck.setAreaId(Ip4Address.valueOf("12.12.12.12"));
428 - lsAck.setOspftype(5);
429 - lsAck.setAuthType(0);
430 - lsAck.setAuthentication(0);
431 - checksumCalculator = new ChecksumCalculator();
432 - byteArray = lsAck.asBytes();
433 - lsAck.setOspfPacLength(byteArray.length);
434 - checkArray = checksumCalculator.calculateOspfCheckSum(byteArray, 12, 13);
435 - checkArray[0] = -47;
436 - checkArray[1] = -74;
437 - buf = ChannelBuffers.copiedBuffer(checkArray);
438 - lsAck.setChecksum(buf.readUnsignedShort());
439 - message = lsAck;
440 - ospfInterfaceChannelHandler.processOspfMessage(message, channelHandlerContext);
441 - assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
442 -
443 - }
444 -
445 - /**
446 - * Tests processHelloMessage() method.
447 - */
448 - @Test
449 - public void testProcessHelloMessage() throws Exception {
450 - ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11"));
451 - ospfInterface.setInterfaceType(1);
452 - ospfInterface.setIpNetworkMask(Ip4Address.valueOf("244.244.244.244"));
453 - ospfInterface.setHelloIntervalTime(10);
454 - ospfInterface.setRouterDeadIntervalTime(10);
455 - ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12"));
456 - channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
457 - OspfMessage message;
458 - helloPacket = new HelloPacket();
459 - helloPacket.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
460 - helloPacket.setOspfVer(2);
461 - helloPacket.setAreaId(Ip4Address.valueOf("12.12.12.12"));
462 - helloPacket.setNetworkMask(Ip4Address.valueOf("244.244.244.244"));
463 - helloPacket.setHelloInterval(10);
464 - helloPacket.setRouterDeadInterval(10);
465 - helloPacket.setDr(Ip4Address.valueOf("10.10.10.10"));
466 - helloPacket.setBdr(Ip4Address.valueOf("11.11.11.11"));
467 - helloPacket.setRouterId(Ip4Address.valueOf("111.111.111.111"));
468 - message = helloPacket;
469 - ospfInterfaceChannelHandler.processHelloMessage(message, channelHandlerContext);
470 - assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
471 - }
472 -
473 - /**
474 - * Tests processHelloMessage() method.
475 - */
476 - @Test
477 - public void testProcessHelloMessage1() throws Exception {
478 - ospfInterface.setInterfaceType(2);
479 - ospfInterface.setRouterPriority(1);
480 - ospfInterfaceChannelHandler.interfaceUp();
481 - ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11"));
482 - ospfInterface.setState(OspfInterfaceState.WAITING);
483 - ospfInterface.setInterfaceType(2);
484 - ospfInterface.setIpNetworkMask(Ip4Address.valueOf("244.244.244.244"));
485 - ospfInterface.setHelloIntervalTime(10);
486 - ospfInterface.setRouterDeadIntervalTime(10);
487 - ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12"));
488 - channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
489 - OspfMessage message;
490 - helloPacket = new HelloPacket();
491 - helloPacket.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
492 - helloPacket.setOspfVer(2);
493 - helloPacket.setAreaId(Ip4Address.valueOf("12.12.12.12"));
494 - helloPacket.setNetworkMask(Ip4Address.valueOf("244.244.244.244"));
495 - helloPacket.setHelloInterval(10);
496 - helloPacket.setRouterDeadInterval(10);
497 - helloPacket.setDr(Ip4Address.valueOf("10.10.10.10"));
498 - helloPacket.setBdr(Ip4Address.valueOf("11.11.11.11"));
499 - helloPacket.setRouterId(Ip4Address.valueOf("2.2.2.2"));
500 - message = helloPacket;
501 - ospfInterfaceChannelHandler.processHelloMessage(message, channelHandlerContext);
502 - assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
503 - ospfNbrHashMap = new HashMap();
504 - ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("10.10.10.10"),
505 - Ip4Address.valueOf("2.2.2.2"), 2,
506 - new OspfInterfaceChannelHandler(new Controller(), ospfArea,
507 - ospfInterface),
508 - topologyForDeviceAndLink);
509 - ospfNbr.setNeighborId(Ip4Address.valueOf("2.2.2.2"));
510 - ospfNbr.setRouterPriority(0);
511 - ospfNbr.setNeighborDr(Ip4Address.valueOf("13.13.13.13"));
512 - ospfInterface.addNeighbouringRouter(ospfNbr);
513 - ospfInterfaceChannelHandler.processHelloMessage(message, channelHandlerContext);
514 - assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
515 - }
516 -
517 - /**
518 - * Tests processDdMessage() method.
519 - */
520 - @Test
521 - public void testProcessDdMessage() throws Exception {
522 - ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11"));
523 - ospfInterface.setInterfaceType(2);
524 - ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
525 - ospfInterface.setHelloIntervalTime(10);
526 - ospfInterface.setRouterDeadIntervalTime(10);
527 - ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12"));
528 - channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
529 - OspfMessage message;
530 - ddPacket = new DdPacket();
531 - ddPacket.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
532 - ddPacket.setOspfVer(2);
533 - ddPacket.setAreaId(Ip4Address.valueOf("12.12.12.12"));
534 - ddPacket.setRouterId(Ip4Address.valueOf("2.2.2.2"));
535 - ddPacket.setIsOpaqueCapable(true);
536 - ddPacket.setIsMore(1);
537 - ddPacket.setIsInitialize(1);
538 - ddPacket.setIsMaster(1);
539 - ddPacket.setSequenceNo(123);
540 - message = ddPacket;
541 - ospfNbrHashMap = new HashMap();
542 - ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("10.10.10.10"),
543 - Ip4Address.valueOf("2.2.2.2"), 2,
544 - new OspfInterfaceChannelHandler(new Controller(), ospfArea,
545 - ospfInterface),
546 - topologyForDeviceAndLink);
547 - ospfNbr.setLastDdPacket(createDdPacket());
548 - ospfNbr.setNeighborId(Ip4Address.valueOf("2.2.2.2"));
549 - ospfNbr.setState(OspfNeighborState.EXSTART);
550 - ospfNbr.setRouterPriority(0);
551 - ospfNbr.setNeighborDr(Ip4Address.valueOf("13.13.13.13"));
552 - ospfNbr.setDdSeqNum(123);
553 - ospfInterface.addNeighbouringRouter(ospfNbr);
554 - ospfInterfaceChannelHandler.processDdMessage(message, channelHandlerContext);
555 - assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
556 - }
557 -
558 - /**
559 - * Tests processDdMessage() method.
560 - */
561 - @Test(expected = Exception.class)
562 - public void testProcessDdMessage3() throws Exception {
563 - ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11"));
564 - ospfInterface.setInterfaceType(2);
565 - ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
566 - ospfInterface.setHelloIntervalTime(10);
567 - ospfInterface.setRouterDeadIntervalTime(10);
568 - ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12"));
569 - channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
570 - OspfMessage message;
571 - ddPacket = new DdPacket();
572 - ddPacket.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
573 - ddPacket.setOspfVer(2);
574 - ddPacket.setAreaId(Ip4Address.valueOf("12.12.12.12"));
575 - ddPacket.setRouterId(Ip4Address.valueOf("2.2.2.2"));
576 - ddPacket.setIsOpaqueCapable(true);
577 - ddPacket.setIsMore(1);
578 - ddPacket.setIsInitialize(1);
579 - ddPacket.setIsMaster(1);
580 - ddPacket.setSequenceNo(123);
581 - message = ddPacket;
582 - ospfNbrHashMap = new HashMap();
583 - ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("10.10.10.10"),
584 - Ip4Address.valueOf("2.2.2.2"), 2,
585 - new OspfInterfaceChannelHandler(new Controller(), ospfArea,
586 - ospfInterface),
587 - topologyForDeviceAndLink);
588 - ospfNbr.setLastDdPacket(createDdPacket());
589 - ospfNbr.setNeighborId(Ip4Address.valueOf("2.2.2.2"));
590 - ospfNbr.setState(OspfNeighborState.EXSTART);
591 - ospfNbr.setRouterPriority(0);
592 - ospfNbr.setNeighborDr(Ip4Address.valueOf("13.13.13.13"));
593 - ospfNbr.setDdSeqNum(123);
594 - ospfInterface.addNeighbouringRouter(ospfNbr);
595 - ddPacket.setIsMore(1);
596 - ddPacket.setIsInitialize(0);
597 - ddPacket.setIsMaster(0);
598 - ddPacket.setSequenceNo(123);
599 - ospfInterface.addNeighbouringRouter(ospfNbr);
600 - ospfInterfaceChannelHandler.processDdMessage(message, channelHandlerContext);
601 - assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
602 - }
603 -
604 - /**
605 - * Tests processDdMessage() method.
606 - */
607 - @Test(expected = Exception.class)
608 - public void testProcessDdMessage1() throws Exception {
609 - ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11"));
610 - ospfInterface.setInterfaceType(2);
611 - ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
612 - ospfInterface.setHelloIntervalTime(10);
613 - ospfInterface.setRouterDeadIntervalTime(10);
614 - ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12"));
615 - channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
616 - OspfMessage message;
617 - ddPacket = new DdPacket();
618 - ddPacket.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
619 - ddPacket.setOspfVer(2);
620 - ddPacket.setAreaId(Ip4Address.valueOf("12.12.12.12"));
621 - ddPacket.setRouterId(Ip4Address.valueOf("2.2.2.2"));
622 - ddPacket.setIsOpaqueCapable(true);
623 - ddPacket.setIsMore(1);
624 - ddPacket.setIsInitialize(1);
625 - ddPacket.setIsMaster(1);
626 - ddPacket.setSequenceNo(123);
627 - message = ddPacket;
628 - ospfNbrHashMap = new HashMap();
629 - ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("10.10.10.10"),
630 - Ip4Address.valueOf("2.2.2.2"), 2,
631 - new OspfInterfaceChannelHandler(new Controller(), ospfArea,
632 - ospfInterface),
633 - topologyForDeviceAndLink);
634 - ospfNbr.setLastDdPacket(createDdPacket());
635 - ospfNbr.setNeighborId(Ip4Address.valueOf("2.2.2.2"));
636 - ospfNbr.setState(OspfNeighborState.EXCHANGE);
637 - ospfNbr.setRouterPriority(0);
638 - ospfNbr.setNeighborDr(Ip4Address.valueOf("13.13.13.13"));
639 - ospfNbr.setDdSeqNum(123);
640 - ospfInterface.addNeighbouringRouter(ospfNbr);
641 - ddPacket.setIsMore(1);
642 - ddPacket.setIsInitialize(0);
643 - ddPacket.setIsMaster(0);
644 - ddPacket.setSequenceNo(123);
645 - ospfInterface.addNeighbouringRouter(ospfNbr);
646 - ospfInterfaceChannelHandler.processDdMessage(message, channelHandlerContext);
647 - assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
648 -
649 - }
650 -
651 - /**
652 - * Tests processDdMessage() method.
653 - */
654 - @Test(expected = Exception.class)
655 - public void testProcessDdMessage2() throws Exception {
656 - ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11"));
657 - ospfInterface.setInterfaceType(2);
658 - ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
659 - ospfInterface.setHelloIntervalTime(10);
660 - ospfInterface.setRouterDeadIntervalTime(10);
661 - ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12"));
662 - channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
663 - OspfMessage message;
664 - ddPacket = new DdPacket();
665 - ddPacket.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
666 - ddPacket.setOspfVer(2);
667 - ddPacket.setAreaId(Ip4Address.valueOf("12.12.12.12"));
668 - ddPacket.setRouterId(Ip4Address.valueOf("2.2.2.2"));
669 - ddPacket.setIsOpaqueCapable(true);
670 - ddPacket.setIsMore(1);
671 - ddPacket.setIsInitialize(1);
672 - ddPacket.setIsMaster(1);
673 - ddPacket.setSequenceNo(123);
674 - message = ddPacket;
675 - ospfNbrHashMap = new HashMap();
676 - ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("10.10.10.10"),
677 - Ip4Address.valueOf("2.2.2.2"), 2,
678 - new OspfInterfaceChannelHandler(new Controller(), ospfArea,
679 - ospfInterface),
680 - topologyForDeviceAndLink);
681 - ospfNbr.setLastDdPacket(createDdPacket());
682 - ospfNbr.setNeighborId(Ip4Address.valueOf("2.2.2.2"));
683 - ospfNbr.setState(OspfNeighborState.LOADING);
684 - ospfNbr.setRouterPriority(0);
685 - ospfNbr.setNeighborDr(Ip4Address.valueOf("13.13.13.13"));
686 - ospfNbr.setDdSeqNum(123);
687 - ospfInterface.addNeighbouringRouter(ospfNbr);
688 - ospfInterfaceChannelHandler.processDdMessage(message, channelHandlerContext);
689 - ddPacket.setIsMore(1);
690 - ddPacket.setIsInitialize(0);
691 - ddPacket.setIsMaster(0);
692 - ddPacket.setSequenceNo(123);
693 - ospfInterface.addNeighbouringRouter(ospfNbr);
694 - ospfNbr.setState(OspfNeighborState.LOADING);
695 - ospfInterface.addNeighbouringRouter(ospfNbr);
696 -
697 - ospfInterfaceChannelHandler.processDdMessage(message, channelHandlerContext);
698 -
699 - assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
700 -
701 - }
702 -
703 - /**
704 - * Tests processLsRequestMessage() method.
705 - */
706 - @Test
707 - public void testProcessLSRequestMessage() throws Exception {
708 - ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11"));
709 - ospfInterface.setInterfaceType(2);
710 - ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
711 - ospfInterface.setHelloIntervalTime(10);
712 - ospfInterface.setRouterDeadIntervalTime(10);
713 - ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12"));
714 - channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
715 - OspfMessage message;
716 - lsRequest = new LsRequest();
717 - lsRequest.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
718 - lsRequest.setOspfVer(2);
719 - lsRequest.setAreaId(Ip4Address.valueOf("12.12.12.12"));
720 - lsRequest.setRouterId(Ip4Address.valueOf("10.226.165.100"));
721 - List<LsRequestPacket> lsRequests = new ArrayList();
722 - LsRequestPacket lsRequestPacket = new LsRequestPacket();
723 - lsRequestPacket.setLsType(3);
724 - lsRequestPacket.setLinkStateId("2.2.2.2");
725 - lsRequestPacket.setOwnRouterId("2.2.2.2");
726 - lsRequests.add(lsRequestPacket);
727 - lsRequests.add(lsRequestPacket);
728 - lsRequest.addLinkStateRequests(new LsRequestPacket());
729 - lsRequest.addLinkStateRequests(new LsRequestPacket());
730 - message = lsRequest;
731 - ospfNbrHashMap = new HashMap();
732 - ospfNbr.setState(OspfNeighborState.EXCHANGE);
733 - ospfNbr = new OspfNbrImpl(ospfArea, createOspfInterface(), Ip4Address.valueOf("10.10.10.10"),
734 - Ip4Address.valueOf("10.226.165.100"), 2,
735 - new OspfInterfaceChannelHandler(new Controller(), ospfArea,
736 - createOspfInterface1()),
737 - topologyForDeviceAndLink);
738 - ospfNbr.setLastDdPacket(createDdPacket());
739 - ospfNbr.setNeighborId(Ip4Address.valueOf("2.2.2.2"));
740 - ospfNbr.setState(OspfNeighborState.FULL);
741 - ospfNbr.setRouterPriority(0);
742 - ospfNbr.setNeighborDr(Ip4Address.valueOf("13.13.13.13"));
743 - ospfNbr.setDdSeqNum(123);
744 - ospfInterface.addNeighbouringRouter(ospfNbr);
745 - ospfInterface.setListOfNeighbors(ospfNbrHashMap);
746 - ospfInterfaceChannelHandler.processLsRequestMessage(message, channelHandlerContext);
747 - assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
748 -
749 - }
750 -
751 - /**
752 - * Tests processLsUpdateMessage() method.
753 - */
754 - @Test
755 - public void testProcessLSUpdateMessage() throws Exception {
756 - ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11"));
757 - ospfInterface.setInterfaceType(2);
758 - ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
759 - ospfInterface.setHelloIntervalTime(10);
760 - ospfInterface.setRouterDeadIntervalTime(10);
761 - ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12"));
762 - channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
763 - OspfMessage message;
764 - lsUpdate = new LsUpdate();
765 - lsUpdate.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
766 - lsUpdate.setOspfVer(2);
767 - lsUpdate.setAreaId(Ip4Address.valueOf("12.12.12.12"));
768 - lsUpdate.setRouterId(Ip4Address.valueOf("10.226.165.100"));
769 - RouterLsa routerLsa = new RouterLsa();
770 - lsUpdate.addLsa(routerLsa);
771 - lsUpdate.setNumberOfLsa(1);
772 - message = lsUpdate;
773 - ospfNbrHashMap = new HashMap();
774 - ospfNbr.setState(OspfNeighborState.FULL);
775 - ospfNbr = new OspfNbrImpl(ospfArea, createOspfInterface(), Ip4Address.valueOf("10.10.10.10"),
776 - Ip4Address.valueOf("10.226.165.100"), 2,
777 - new OspfInterfaceChannelHandler(new Controller(), ospfArea,
778 - createOspfInterface1()),
779 - topologyForDeviceAndLink);
780 - ospfNbr.setLastDdPacket(createDdPacket());
781 - ospfNbr.setNeighborId(Ip4Address.valueOf("2.2.2.2"));
782 - ospfNbr.setState(OspfNeighborState.FULL);
783 - ospfNbr.setRouterPriority(0);
784 - ospfNbr.setNeighborDr(Ip4Address.valueOf("13.13.13.13"));
785 - ospfNbr.setDdSeqNum(123);
786 - ospfInterface.addNeighbouringRouter(ospfNbr);
787 - ospfInterfaceChannelHandler.processLsUpdateMessage(message, channelHandlerContext);
788 - assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
789 -
790 - }
791 -
792 - @Test(expected = Exception.class)
793 - public void testProcessLSAckMessage() throws Exception {
794 - ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11"));
795 - ospfInterface.setInterfaceType(2);
796 - ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
797 - ospfInterface.setHelloIntervalTime(10);
798 - ospfInterface.setRouterDeadIntervalTime(10);
799 - ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12"));
800 - channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
801 - OspfMessage message;
802 - lsAck = new LsAcknowledge();
803 - lsAck.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
804 - lsAck.setOspfVer(2);
805 - lsAck.setAreaId(Ip4Address.valueOf("12.12.12.12"));
806 - LsaHeader lsaHeader = new LsaHeader();
807 - lsAck.addLinkStateHeader(lsaHeader);
808 - message = lsAck;
809 - ospfNbr = new OspfNbrImpl(ospfArea, createOspfInterface(), Ip4Address.valueOf("10.10.10.10"),
810 - Ip4Address.valueOf("10.226.165.100"), 2,
811 - new OspfInterfaceChannelHandler(new Controller(), ospfArea,
812 - createOspfInterface()),
813 - topologyForDeviceAndLink);
814 - ospfNbr.setLastDdPacket(createDdPacket());
815 - ospfNbr.setNeighborId(Ip4Address.valueOf("2.2.2.2"));
816 - ospfNbr.setState(OspfNeighborState.FULL);
817 - ospfNbr.setRouterPriority(0);
818 - ospfNbr.setNeighborDr(Ip4Address.valueOf("13.13.13.13"));
819 - ospfNbr.setDdSeqNum(123);
820 - ospfInterfaceChannelHandler.processLsAckMessage(message, channelHandlerContext);
821 - assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
822 -
823 - }
824 -
825 - /**
826 - * Tests compareDdPackets() method.
827 - */
828 - @Test
829 - public void testCompareDDPackets() throws Exception {
830 - ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11"));
831 - ospfInterface.setInterfaceType(2);
832 - ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
833 - ospfInterface.setHelloIntervalTime(10);
834 - ospfInterface.setRouterDeadIntervalTime(10);
835 - ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12"));
836 - channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
837 - OspfMessage message;
838 - ddPacket = new DdPacket();
839 - ddPacket.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
840 - ddPacket.setOspfVer(2);
841 - ddPacket.setIsInitialize(1);
842 - ddPacket.setIsMaster(1);
843 - ddPacket.setIsMore(1);
844 - ddPacket.setOptions(2);
845 - ddPacket.setAreaId(Ip4Address.valueOf("12.12.12.12"));
846 - assertThat(ospfInterfaceChannelHandler.compareDdPackets(ddPacket, ddPacket), is(true));
847 - }
848 -
849 - @Test(expected = Exception.class)
850 - public void testCloseChannel() throws Exception {
851 - channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
852 -
853 - ospfInterfaceChannelHandler.closeChannel(channelHandlerContext);
854 -
855 - assertThat(ospfInterface.dr(), is(notNullValue()));
856 - }
857 -
858 - /**
859 - * Tests electRouter() method.
860 - */
861 - @Test
862 - public void testElectRouter() throws Exception {
863 - ospfInterface.setDr(Ip4Address.valueOf("3.3.3.3"));
864 - ospfInterface.setBdr(Ip4Address.valueOf("3.3.3.3"));
865 - ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
866 - ChannelConfig channelConfig = EasyMock.createMock(ChannelConfig.class);
867 - EasyMock.expect(channelConfig.getBufferFactory()).andReturn(new HeapChannelBufferFactory());
868 - Channel channel = EasyMock.createMock(Channel.class);
869 - ospfInterfaceChannelHandler.electRouter(channel);
870 - assertThat(ospfInterface.dr(), is(notNullValue()));
871 - }
872 -
873 - /**
874 - * Tests electBdr() method.
875 - */
876 - @Test
877 - public void testElectBdr() throws Exception {
878 - ospfEligibleRouter = new OspfEligibleRouter();
879 - ospfEligibleRouter.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
880 - ospfEligibleRouter.setIsDr(true);
881 - ospfEligibleRouter.setRouterPriority(10);
882 - ospfEligibleRouter.setRouterId(Ip4Address.valueOf("1.1.1.1"));
883 - ospfEligibleRouter.setIsBdr(false);
884 - OspfEligibleRouter ospfEligibleRouter1 = new OspfEligibleRouter();
885 - ospfEligibleRouter.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
886 - ospfEligibleRouter.setIsDr(true);
887 - ospfEligibleRouter.setRouterPriority(10);
888 - ospfEligibleRouter.setRouterId(Ip4Address.valueOf("1.1.1.1"));
889 - ospfEligibleRouter.setIsBdr(false);
890 - OspfEligibleRouter ospfEligibleRouter2 = new OspfEligibleRouter();
891 - ospfEligibleRouter.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
892 - ospfEligibleRouter.setIsDr(true);
893 - ospfEligibleRouter.setRouterPriority(10);
894 - ospfEligibleRouter.setRouterId(Ip4Address.valueOf("1.1.1.1"));
895 - ospfEligibleRouter.setIsBdr(false);
896 - List<OspfEligibleRouter> ospfEligibleRouters = new ArrayList<>();
897 -
898 - ospfEligibleRouters.add(ospfEligibleRouter);
899 - ospfEligibleRouters.add(ospfEligibleRouter1);
900 - ospfEligibleRouters.add(ospfEligibleRouter2);
901 - OspfEligibleRouter eligibleRouter = ospfInterfaceChannelHandler.electBdr(ospfEligibleRouters);
902 - assertThat(ospfEligibleRouters.size(), is(3));
903 - assertThat(eligibleRouter, is(notNullValue()));
904 - }
905 -
906 - /**
907 - * Tests electDr() method.
908 - */
909 - @Test
910 - public void testElectDR() throws Exception {
911 - ospfEligibleRouter = new OspfEligibleRouter();
912 - ospfEligibleRouter.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
913 - ospfEligibleRouter.setIsDr(true);
914 - ospfEligibleRouter.setRouterPriority(10);
915 - ospfEligibleRouter.setRouterId(Ip4Address.valueOf("1.1.1.1"));
916 - ospfEligibleRouter.setIsBdr(false);
917 - OspfEligibleRouter ospfEligibleRouter1 = new OspfEligibleRouter();
918 - ospfEligibleRouter.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
919 - ospfEligibleRouter.setIsDr(true);
920 - ospfEligibleRouter.setRouterPriority(10);
921 - ospfEligibleRouter.setRouterId(Ip4Address.valueOf("1.1.1.1"));
922 - ospfEligibleRouter.setIsBdr(false);
923 - OspfEligibleRouter ospfEligibleRouter2 = new OspfEligibleRouter();
924 - ospfEligibleRouter.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
925 - ospfEligibleRouter.setIsDr(true);
926 - ospfEligibleRouter.setRouterPriority(10);
927 - ospfEligibleRouter.setRouterId(Ip4Address.valueOf("1.1.1.1"));
928 - ospfEligibleRouter.setIsBdr(false);
929 - List<OspfEligibleRouter> ospfEligibleRouters = new ArrayList<>();
930 - ospfEligibleRouters.add(ospfEligibleRouter);
931 - ospfEligibleRouters.add(ospfEligibleRouter1);
932 - ospfEligibleRouters.add(ospfEligibleRouter2);
933 - OspfEligibleRouter eligibleRouter = ospfInterfaceChannelHandler.electDr(ospfEligibleRouters,
934 - ospfEligibleRouter);
935 - assertThat(ospfEligibleRouters.size(), is(3));
936 - assertThat(eligibleRouter, is(notNullValue()));
937 - }
938 -
939 - /**
940 - * Tests selectRouterBasedOnPriority() method.
941 - */
942 - @Test
943 - public void testSelectRouterBasedOnPriority() throws Exception {
944 - ospfEligibleRouter = new OspfEligibleRouter();
945 - ospfEligibleRouter.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
946 - ospfEligibleRouter.setIsDr(true);
947 - ospfEligibleRouter.setRouterPriority(10);
948 - ospfEligibleRouter.setRouterId(Ip4Address.valueOf("1.1.1.1"));
949 - ospfEligibleRouter.setIsBdr(false);
950 - OspfEligibleRouter ospfEligibleRouter1 = new OspfEligibleRouter();
951 - ospfEligibleRouter.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
952 - ospfEligibleRouter.setIsDr(true);
953 - ospfEligibleRouter.setRouterPriority(11);
954 - ospfEligibleRouter.setRouterId(Ip4Address.valueOf("1.1.1.1"));
955 - ospfEligibleRouter.setIsBdr(false);
956 - OspfEligibleRouter ospfEligibleRouter2 = new OspfEligibleRouter();
957 - ospfEligibleRouter.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
958 - ospfEligibleRouter.setIsDr(true);
959 - ospfEligibleRouter.setRouterPriority(12);
960 - ospfEligibleRouter.setRouterId(Ip4Address.valueOf("1.1.1.1"));
961 - ospfEligibleRouter.setIsBdr(false);
962 - List<OspfEligibleRouter> ospfEligibleRouters = new ArrayList<>();
963 - ospfEligibleRouters.add(ospfEligibleRouter);
964 - ospfEligibleRouters.add(ospfEligibleRouter1);
965 - ospfEligibleRouters.add(ospfEligibleRouter2);
966 - OspfEligibleRouter eligibleRouter = ospfInterfaceChannelHandler.selectRouterBasedOnPriority(
967 - ospfEligibleRouters);
968 - assertThat(eligibleRouter, is(notNullValue()));
969 - }
970 -
971 - /**
972 - * Tests addDeviceInformation() method.
973 - */
974 - @Test(expected = Exception.class)
975 - public void testAddDeviceInformation() throws Exception {
976 - ospfNbr = new OspfNbrImpl(ospfArea, createOspfInterface(), Ip4Address.valueOf("10.10.10.10"),
977 - Ip4Address.valueOf("10.226.165.100"), 2,
978 - new OspfInterfaceChannelHandler(new Controller(), ospfArea,
979 - createOspfInterface()),
980 - topologyForDeviceAndLink);
981 -
982 - ospfInterfaceChannelHandler.addDeviceInformation(new OspfRouterImpl());
983 - assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
984 - }
985 -
986 - /**
987 - * Tests removeDeviceInformation() method.
988 - */
989 - @Test(expected = Exception.class)
990 - public void testRemoveDeviceInformation() throws Exception {
991 - ospfNbr = new OspfNbrImpl(ospfArea, createOspfInterface(), Ip4Address.valueOf("10.10.10.10"),
992 - Ip4Address.valueOf("10.226.165.100"), 2,
993 - new OspfInterfaceChannelHandler(new Controller(), ospfArea,
994 - createOspfInterface()),
995 - topologyForDeviceAndLink);
996 -
997 - ospfInterfaceChannelHandler.removeDeviceInformation(new OspfRouterImpl());
998 - assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
999 - }
1000 -
1001 - /**
1002 - * Tests addLinkInformation() method.
1003 - */
1004 - @Test(expected = Exception.class)
1005 - public void testaddLinkInformation() throws Exception {
1006 - ospfNbr = new OspfNbrImpl(ospfArea, createOspfInterface(), Ip4Address.valueOf("10.10.10.10"),
1007 - Ip4Address.valueOf("10.226.165.100"), 2,
1008 - new OspfInterfaceChannelHandler(new Controller(), ospfArea,
1009 - createOspfInterface()),
1010 - topologyForDeviceAndLink);
1011 -
1012 - List topTlv = new ArrayList();
1013 - topTlv.add(new RouterTlv(new TlvHeader()));
1014 - ospfInterfaceChannelHandler.addLinkInformation(new OspfRouterImpl(), new OspfLinkTedImpl());
1015 - assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
1016 - }
1017 -
1018 - /**
1019 - * Tests removeLinkInformation() method.
1020 - */
1021 - @Test(expected = Exception.class)
1022 - public void testRemoveLinkInformation() throws Exception {
1023 - ospfNbr = new OspfNbrImpl(ospfArea, createOspfInterface(), Ip4Address.valueOf("10.10.10.10"),
1024 - Ip4Address.valueOf("10.226.165.100"), 2,
1025 - new OspfInterfaceChannelHandler(new Controller(), ospfArea,
1026 - createOspfInterface()),
1027 - topologyForDeviceAndLink);
1028 -
1029 - ospfInterfaceChannelHandler.removeLinkInformation(ospfNbr);
1030 - assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
1031 - }
1032 -
1033 - /**
1034 - * Utility for test method.
1035 - */
1036 - private DdPacket createDdPacket() throws OspfParseException {
1037 - byte[] ddPacket = {2, 2, 0, 32, -64, -88, -86, 8, 0, 0, 0, 1, -96, 82,
1038 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, -36, 2, 7, 65, 119, -87, 126};
1039 - DdPacket ddPacket1 = new DdPacket();
1040 - ChannelBuffer buf = ChannelBuffers.buffer(ddPacket.length);
1041 - buf.writeBytes(ddPacket);
1042 - ddPacket1.readFrom(buf);
1043 - return ddPacket1;
1044 - }
1045 -
1046 - /**
1047 - * Utility for test method.
1048 - */
1049 - private OspfInterfaceImpl createOspfInterface() throws UnknownHostException {
1050 - ospfInterface = new OspfInterfaceImpl();
1051 - OspfAreaImpl ospfArea = new OspfAreaImpl();
1052 - OspfInterfaceChannelHandler ospfInterfaceChannelHandler = EasyMock.createMock(
1053 - OspfInterfaceChannelHandler.class);
1054 - ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("10.226.165.164"),
1055 - Ip4Address.valueOf("1.1.1.1"), 2, ospfInterfaceChannelHandler,
1056 - topologyForDeviceAndLink);
1057 - ospfNbr.setState(OspfNeighborState.EXSTART);
1058 - ospfNbr.setNeighborId(Ip4Address.valueOf("10.226.165.100"));
1059 - this.ospfInterface = new OspfInterfaceImpl();
1060 - this.ospfInterface.setIpAddress(Ip4Address.valueOf("10.226.165.164"));
1061 - this.ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
1062 - this.ospfInterface.setAreaId(2);
1063 - this.ospfInterface.setAuthKey("authKey");
1064 - this.ospfInterface.setAuthType("AuthReq");
1065 - this.ospfInterface.setBdr(Ip4Address.valueOf("111.111.111.111"));
1066 - this.ospfInterface.setDr(Ip4Address.valueOf("111.111.111.111"));
1067 - this.ospfInterface.setHelloIntervalTime(20);
1068 - this.ospfInterface.setInterfaceCost(10);
1069 - this.ospfInterface.setInterfaceType(2);
1070 - this.ospfInterface.setReTransmitInterval(2000);
1071 - this.ospfInterface.setMtu(6500);
1072 - this.ospfInterface.setPollInterval(1000);
1073 - this.ospfInterface.setRouterDeadIntervalTime(1000);
1074 - this.ospfInterface.setRouterPriority(1);
1075 - this.ospfInterface.setTransmitDelay(500);
1076 - this.ospfInterface.setInterfaceType(1);
1077 - this.ospfInterface.addNeighbouringRouter(ospfNbr);
1078 - return this.ospfInterface;
1079 - }
1080 -
1081 - /**
1082 * Utility for test method. 256 * Utility for test method.
1083 */ 257 */
1084 private OspfInterfaceImpl createOspfInterface1() throws UnknownHostException { 258 private OspfInterfaceImpl createOspfInterface1() throws UnknownHostException {
...@@ -1086,28 +260,21 @@ public class OspfInterfaceChannelHandlerTest { ...@@ -1086,28 +260,21 @@ public class OspfInterfaceChannelHandlerTest {
1086 OspfAreaImpl ospfArea = new OspfAreaImpl(); 260 OspfAreaImpl ospfArea = new OspfAreaImpl();
1087 OspfInterfaceChannelHandler ospfInterfaceChannelHandler = EasyMock.createMock( 261 OspfInterfaceChannelHandler ospfInterfaceChannelHandler = EasyMock.createMock(
1088 OspfInterfaceChannelHandler.class); 262 OspfInterfaceChannelHandler.class);
1089 - ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("10.226.165.164"), 263 + ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface, ip4Address5,
1090 - Ip4Address.valueOf("1.1.1.1"), 2, ospfInterfaceChannelHandler, 264 + ip4Address6, 2, topologyForDeviceAndLink);
1091 - topologyForDeviceAndLink);
1092 ospfNbr.setState(OspfNeighborState.FULL); 265 ospfNbr.setState(OspfNeighborState.FULL);
1093 - ospfNbr.setNeighborId(Ip4Address.valueOf("10.226.165.100")); 266 + ospfNbr.setNeighborId(ip4Address7);
1094 ospfInterface = new OspfInterfaceImpl(); 267 ospfInterface = new OspfInterfaceImpl();
1095 - ospfInterface.setIpAddress(Ip4Address.valueOf("10.226.165.164")); 268 + ospfInterface.setIpAddress(ip4Address5);
1096 - ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255")); 269 + ospfInterface.setIpNetworkMask(subnetAddress);
1097 - ospfInterface.setAreaId(2); 270 + ospfInterface.setBdr(ip4Address4);
1098 - ospfInterface.setAuthKey("authKey"); 271 + ospfInterface.setDr(ip4Address4);
1099 - ospfInterface.setAuthType("AuthReq");
1100 - ospfInterface.setBdr(Ip4Address.valueOf("111.111.111.111"));
1101 - ospfInterface.setDr(Ip4Address.valueOf("111.111.111.111"));
1102 ospfInterface.setHelloIntervalTime(20); 272 ospfInterface.setHelloIntervalTime(20);
1103 - ospfInterface.setInterfaceCost(10);
1104 ospfInterface.setInterfaceType(2); 273 ospfInterface.setInterfaceType(2);
1105 ospfInterface.setReTransmitInterval(2000); 274 ospfInterface.setReTransmitInterval(2000);
1106 ospfInterface.setMtu(6500); 275 ospfInterface.setMtu(6500);
1107 - ospfInterface.setPollInterval(1000);
1108 ospfInterface.setRouterDeadIntervalTime(1000); 276 ospfInterface.setRouterDeadIntervalTime(1000);
1109 ospfInterface.setRouterPriority(1); 277 ospfInterface.setRouterPriority(1);
1110 - ospfInterface.setTransmitDelay(500);
1111 ospfInterface.setInterfaceType(1); 278 ospfInterface.setInterfaceType(1);
1112 ospfInterface.addNeighbouringRouter(ospfNbr); 279 ospfInterface.addNeighbouringRouter(ospfNbr);
1113 return ospfInterface; 280 return ospfInterface;
...@@ -1116,41 +283,45 @@ public class OspfInterfaceChannelHandlerTest { ...@@ -1116,41 +283,45 @@ public class OspfInterfaceChannelHandlerTest {
1116 /** 283 /**
1117 * Utility for test method. 284 * Utility for test method.
1118 */ 285 */
1119 - private OspfAreaImpl createOspfArea() throws UnknownHostException { 286 + private OspfInterfaceImpl createOspfInterface() throws Exception {
1120 - OspfAreaAddressRangeImpl ospfAreaAddressRange; 287 + ospfInterface = new OspfInterfaceImpl();
1121 - ospfAreaAddressRange = createOspfAreaAddressRange(); 288 + LsaHeader lsaHeader = new LsaHeader();
1122 - addressRanges.add(ospfAreaAddressRange); 289 + lsaHeader.setLsType(OspfLsaType.ROUTER.value());
1123 - OspfAreaImpl ospfArea = new OspfAreaImpl();
1124 - ospfArea.setStubCost(10);
1125 - ospfArea.setAreaId(Ip4Address.valueOf("10.226.165.164"));
1126 - ospfArea.setExternalRoutingCapability(true);
1127 - ospfArea.setTransitCapability(true);
1128 - ospfArea.setAddressRanges(addressRanges);
1129 - OspfInterfaceImpl ospfInterface = createOspfInterface();
1130 - ospfInterfaces.add(ospfInterface);
1131 - ospfArea.setInterfacesLst(ospfInterfaces);
1132 RouterLsa routerLsa = new RouterLsa(); 290 RouterLsa routerLsa = new RouterLsa();
1133 - routerLsa.setLsType(1); 291 + OspfAreaImpl ospfArea = new OspfAreaImpl();
1134 - routerLsa.setLinkStateId("2.2.2.2"); 292 + ospfArea.addLsa(routerLsa, true, ospfInterface);
1135 - routerLsa.setAdvertisingRouter(Ip4Address.valueOf("2.2.2.2")); 293 + ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface, ip4Address5,
1136 - try { 294 + ip4Address6, 2, topologyForDeviceAndLink);
1137 - ospfArea.addLsa(routerLsa, false, ospfInterface); 295 + ospfNbr.setState(OspfNeighborState.EXSTART);
1138 - } catch (Exception e) { 296 + ospfNbr.setNeighborId(ip4Address7);
1139 - System.out.println("ospfAreaImpl createOspfArea"); 297 + this.ospfInterface = new OspfInterfaceImpl();
1140 - } 298 + this.ospfInterface.setIpAddress(ip4Address5);
1141 - ospfArea.setRouterId(Ip4Address.valueOf("111.111.111.111")); 299 + this.ospfInterface.setIpNetworkMask(subnetAddress);
1142 - 300 + this.ospfInterface.setBdr(ip4Address4);
1143 - return ospfArea; 301 + this.ospfInterface.setDr(ip4Address4);
302 + this.ospfInterface.setHelloIntervalTime(20);
303 + this.ospfInterface.setInterfaceType(2);
304 + this.ospfInterface.setReTransmitInterval(2000);
305 + this.ospfInterface.setMtu(6500);
306 + this.ospfInterface.setRouterDeadIntervalTime(1000);
307 + this.ospfInterface.setRouterPriority(1);
308 + this.ospfInterface.setInterfaceType(1);
309 + this.ospfInterface.setInterfaceIndex(1);
310 + this.ospfInterface.addNeighbouringRouter(ospfNbr);
311 + this.ospfInterface.setOspfArea(ospfArea);
312 + return this.ospfInterface;
1144 } 313 }
1145 314
1146 /** 315 /**
1147 * Utility for test method. 316 * Utility for test method.
1148 */ 317 */
1149 - private OspfAreaAddressRangeImpl createOspfAreaAddressRange() { 318 + private DdPacket createDdPacket() throws OspfParseException {
1150 - OspfAreaAddressRangeImpl ospfAreaAddressRange = new OspfAreaAddressRangeImpl(); 319 + byte[] ddPacket = {2, 2, 0, 32, -64, -88, -86, 8, 0, 0, 0, 1, -96, 82,
1151 - ospfAreaAddressRange.setIpAddress(Ip4Address.valueOf("10.226.165.164")); 320 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, -36, 2, 7, 65, 119, -87, 126};
1152 - ospfAreaAddressRange.setAdvertise(true); 321 + DdPacket ddPacket1 = new DdPacket();
1153 - ospfAreaAddressRange.setMask("mask"); 322 + ChannelBuffer buf = ChannelBuffers.buffer(ddPacket.length);
1154 - return ospfAreaAddressRange; 323 + buf.writeBytes(ddPacket);
324 + ddPacket1.readFrom(buf);
325 + return ddPacket1;
1155 } 326 }
1156 } 327 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -21,6 +21,7 @@ import org.junit.Test; ...@@ -21,6 +21,7 @@ import org.junit.Test;
21 import org.onlab.packet.Ip4Address; 21 import org.onlab.packet.Ip4Address;
22 import org.onlab.util.Bandwidth; 22 import org.onlab.util.Bandwidth;
23 23
24 +import java.net.InetAddress;
24 import java.util.ArrayList; 25 import java.util.ArrayList;
25 import java.util.List; 26 import java.util.List;
26 27
...@@ -32,8 +33,6 @@ import static org.junit.Assert.assertThat; ...@@ -32,8 +33,6 @@ import static org.junit.Assert.assertThat;
32 * Unit test class for OspfDeviceTedImpl. 33 * Unit test class for OspfDeviceTedImpl.
33 */ 34 */
34 public class OspfLinkTedImplTest { 35 public class OspfLinkTedImplTest {
35 - private static final Ip4Address LOCAL_ADDRESS = Ip4Address.valueOf("127.0.0.1");
36 -
37 private OspfLinkTedImpl ospfLinkTed; 36 private OspfLinkTedImpl ospfLinkTed;
38 37
39 @Before 38 @Before
...@@ -91,7 +90,7 @@ public class OspfLinkTedImplTest { ...@@ -91,7 +90,7 @@ public class OspfLinkTedImplTest {
91 @Test 90 @Test
92 public void testIpv4RemRouterId() throws Exception { 91 public void testIpv4RemRouterId() throws Exception {
93 List list = new ArrayList(); 92 List list = new ArrayList();
94 - list.add(LOCAL_ADDRESS); 93 + list.add(Ip4Address.valueOf(InetAddress.getLocalHost()));
95 ospfLinkTed.setIpv4RemRouterId(list); 94 ospfLinkTed.setIpv4RemRouterId(list);
96 assertThat(ospfLinkTed.ipv4RemRouterId().size(), is(1)); 95 assertThat(ospfLinkTed.ipv4RemRouterId().size(), is(1));
97 } 96 }
...@@ -102,7 +101,7 @@ public class OspfLinkTedImplTest { ...@@ -102,7 +101,7 @@ public class OspfLinkTedImplTest {
102 @Test 101 @Test
103 public void testSetIpv4RemRouterId() throws Exception { 102 public void testSetIpv4RemRouterId() throws Exception {
104 List list = new ArrayList(); 103 List list = new ArrayList();
105 - list.add(LOCAL_ADDRESS); 104 + list.add(Ip4Address.valueOf(InetAddress.getLocalHost()));
106 ospfLinkTed.setIpv4RemRouterId(list); 105 ospfLinkTed.setIpv4RemRouterId(list);
107 assertThat(ospfLinkTed.ipv4RemRouterId().size(), is(1)); 106 assertThat(ospfLinkTed.ipv4RemRouterId().size(), is(1));
108 } 107 }
...@@ -133,7 +132,7 @@ public class OspfLinkTedImplTest { ...@@ -133,7 +132,7 @@ public class OspfLinkTedImplTest {
133 @Test 132 @Test
134 public void testIpv4LocRouterId() throws Exception { 133 public void testIpv4LocRouterId() throws Exception {
135 List list = new ArrayList(); 134 List list = new ArrayList();
136 - list.add(LOCAL_ADDRESS); 135 + list.add(Ip4Address.valueOf(InetAddress.getLocalHost()));
137 ospfLinkTed.setIpv4LocRouterId(list); 136 ospfLinkTed.setIpv4LocRouterId(list);
138 assertThat(ospfLinkTed.ipv4LocRouterId().size(), is(1)); 137 assertThat(ospfLinkTed.ipv4LocRouterId().size(), is(1));
139 } 138 }
...@@ -144,7 +143,7 @@ public class OspfLinkTedImplTest { ...@@ -144,7 +143,7 @@ public class OspfLinkTedImplTest {
144 @Test 143 @Test
145 public void testSetIpv4LocRouterId() throws Exception { 144 public void testSetIpv4LocRouterId() throws Exception {
146 List list = new ArrayList(); 145 List list = new ArrayList();
147 - list.add(LOCAL_ADDRESS); 146 + list.add(Ip4Address.valueOf(InetAddress.getLocalHost()));
148 ospfLinkTed.setIpv4LocRouterId(list); 147 ospfLinkTed.setIpv4LocRouterId(list);
149 assertThat(ospfLinkTed.ipv4LocRouterId().size(), is(1)); 148 assertThat(ospfLinkTed.ipv4LocRouterId().size(), is(1));
150 } 149 }
......
...@@ -28,7 +28,7 @@ import java.net.InetSocketAddress; ...@@ -28,7 +28,7 @@ import java.net.InetSocketAddress;
28 import java.net.SocketAddress; 28 import java.net.SocketAddress;
29 29
30 import static org.hamcrest.CoreMatchers.is; 30 import static org.hamcrest.CoreMatchers.is;
31 -import static org.hamcrest.CoreMatchers.nullValue; 31 +import static org.hamcrest.CoreMatchers.notNullValue;
32 import static org.hamcrest.MatcherAssert.assertThat; 32 import static org.hamcrest.MatcherAssert.assertThat;
33 33
34 /** 34 /**
...@@ -36,7 +36,7 @@ import static org.hamcrest.MatcherAssert.assertThat; ...@@ -36,7 +36,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
36 */ 36 */
37 public class OspfMessageDecoderTest { 37 public class OspfMessageDecoderTest {
38 38
39 - private final byte[] hellopacket = {0, 0, 0, 0, 2, 1, 0, 44, -64, -88, -86, 8, 0, 0, 0, 1, 39, 59, 39 + private final byte[] hellopacket = {0, 0, 0, 0, 0, 2, 1, 0, 44, -64, -88, -86, 8, 0, 0, 0, 1, 39, 59,
40 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, 0, 0, 10, 2, 1, 0, 0, 0, 40 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, 0, 0, 10, 2, 1, 0, 0, 0,
41 40, -64, -88, -86, 8, 0, 0, 0, 0}; 41 40, -64, -88, -86, 8, 0, 0, 0, 0};
42 private final byte[] ddpacket = {0, 0, 0, 0, 2, 2, 0, 32, -64, -88, -86, 8, 0, 0, 0, 1, -96, 82, 42 private final byte[] ddpacket = {0, 0, 0, 0, 2, 2, 0, 32, -64, -88, -86, 8, 0, 0, 0, 1, -96, 82,
...@@ -75,10 +75,10 @@ public class OspfMessageDecoderTest { ...@@ -75,10 +75,10 @@ public class OspfMessageDecoderTest {
75 */ 75 */
76 @Test 76 @Test
77 public void testDecode() throws Exception { 77 public void testDecode() throws Exception {
78 -
79 channel = EasyMock.createMock(Channel.class); 78 channel = EasyMock.createMock(Channel.class);
80 socketAddress = InetSocketAddress.createUnresolved("127.0.0.1", 7000); 79 socketAddress = InetSocketAddress.createUnresolved("127.0.0.1", 7000);
81 channelBuffer = ChannelBuffers.copiedBuffer(hellopacket); 80 channelBuffer = ChannelBuffers.copiedBuffer(hellopacket);
82 - assertThat(ospfMessageDecoder.decode(ctx, channel, channelBuffer), is(nullValue())); 81 + ospfMessageDecoder.decode(ctx, channel, channelBuffer);
82 + assertThat(ospfMessageDecoder, is(notNullValue()));
83 } 83 }
84 } 84 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -17,24 +17,11 @@ package org.onosproject.ospf.controller.impl; ...@@ -17,24 +17,11 @@ package org.onosproject.ospf.controller.impl;
17 17
18 18
19 import org.easymock.EasyMock; 19 import org.easymock.EasyMock;
20 -import org.jboss.netty.buffer.ChannelBuffer;
21 -import org.jboss.netty.buffer.ChannelBuffers;
22 import org.jboss.netty.channel.Channel; 20 import org.jboss.netty.channel.Channel;
23 import org.jboss.netty.channel.ChannelHandlerContext; 21 import org.jboss.netty.channel.ChannelHandlerContext;
24 import org.junit.After; 22 import org.junit.After;
25 import org.junit.Before; 23 import org.junit.Before;
26 import org.junit.Test; 24 import org.junit.Test;
27 -import org.onlab.packet.Ip4Address;
28 -import org.onosproject.ospf.controller.area.OspfInterfaceImpl;
29 -import org.onosproject.ospf.protocol.ospfpacket.types.DdPacket;
30 -import org.onosproject.ospf.protocol.ospfpacket.types.HelloPacket;
31 -import org.onosproject.ospf.protocol.ospfpacket.types.LsAcknowledge;
32 -import org.onosproject.ospf.protocol.ospfpacket.types.LsRequest;
33 -import org.onosproject.ospf.protocol.ospfpacket.types.LsUpdate;
34 -import org.onosproject.ospf.protocol.util.OspfInterfaceState;
35 -
36 -import java.net.InetSocketAddress;
37 -import java.net.SocketAddress;
38 25
39 import static org.hamcrest.CoreMatchers.is; 26 import static org.hamcrest.CoreMatchers.is;
40 import static org.hamcrest.CoreMatchers.notNullValue; 27 import static org.hamcrest.CoreMatchers.notNullValue;
...@@ -44,55 +31,24 @@ import static org.hamcrest.MatcherAssert.assertThat; ...@@ -44,55 +31,24 @@ import static org.hamcrest.MatcherAssert.assertThat;
44 * Created by sdn on 13/1/16. 31 * Created by sdn on 13/1/16.
45 */ 32 */
46 public class OspfMessageEncoderTest { 33 public class OspfMessageEncoderTest {
47 - private final byte[] hpacket = {2, 1, 0, 44, -64, -88, -86, 8, 0, 0, 0, 1, 39, 59, 34 +
48 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, 0, 0, 10, 2, 1, 0, 0, 0, 35 + private final byte[] object = {2, 1, 0, 44, -64, -88, -86, 8, 0, 0, 0, 1, 39,
49 - 40, -64, -88, -86, 8, 0, 0, 0, 0}; 36 + 59, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, 0, 0, 10, 2, 1, 0, 0,
50 - private final byte[] dpacket = {2, 2, 0, 32, -64, -88, -86, 8, 0, 0, 0, 1, -96, 82, 37 + 0, 40, -64, -88, -86, 8, 0, 0, 0, 0};
51 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, -36, 2, 7, 65, 119, -87, 126};
52 - private final byte[] lrpacket = {2, 3, 0, 36, -64, -88, -86, 3, 0, 0, 0, 1, -67, -57,
53 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -64, -88, -86, 8, -64, -88, -86, 8};
54 - private byte[] lAckpacket = {2, 5, 0, 44, -64, -88, -86, 8, 0, 0, 0, 1, -30, -12,
55 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 16, 2, 1, -64, -88, -86, 2, -64,
56 - -88, -86, 2, -128, 0, 0, 1, 74, -114, 0, 48};
57 - private HelloPacket helloPacket;
58 - private DdPacket ddPacket;
59 - private LsAcknowledge lsAcknowledge;
60 - private LsRequest lsRequest;
61 - private LsUpdate lsUpdate;
62 - private ChannelHandlerContext ctx;
63 private OspfMessageEncoder ospfMessageEncoder; 38 private OspfMessageEncoder ospfMessageEncoder;
64 - private ChannelBuffer buf; 39 + private ChannelHandlerContext channelHandlerContext;
65 - private SocketAddress socketAddress;
66 private Channel channel; 40 private Channel channel;
67 41
68 @Before 42 @Before
69 public void setUp() throws Exception { 43 public void setUp() throws Exception {
70 ospfMessageEncoder = new OspfMessageEncoder(); 44 ospfMessageEncoder = new OspfMessageEncoder();
71 - helloPacket = new HelloPacket(); 45 + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
72 - ddPacket = new DdPacket(); 46 + channel = EasyMock.createMock(Channel.class);
73 - lsAcknowledge = new LsAcknowledge();
74 - lsRequest = new LsRequest();
75 - lsUpdate = new LsUpdate();
76 - helloPacket.setOspftype(1);
77 - ddPacket.setOspftype(2);
78 - lsAcknowledge.setOspftype(5);
79 - lsRequest.setOspftype(3);
80 - lsUpdate.setOspftype(4);
81 - OspfInterfaceImpl ospfInterface = new OspfInterfaceImpl();
82 - ospfInterface.setState(OspfInterfaceState.DROTHER);
83 - ospfMessageEncoder = new OspfMessageEncoder(ospfInterface);
84 -
85 } 47 }
86 48
87 @After 49 @After
88 public void tearDown() throws Exception { 50 public void tearDown() throws Exception {
89 - helloPacket = null;
90 - ddPacket = null;
91 - lsAcknowledge = null;
92 - lsRequest = null;
93 - lsUpdate = null;
94 ospfMessageEncoder = null; 51 ospfMessageEncoder = null;
95 - buf = null;
96 } 52 }
97 53
98 /** 54 /**
...@@ -100,33 +56,6 @@ public class OspfMessageEncoderTest { ...@@ -100,33 +56,6 @@ public class OspfMessageEncoderTest {
100 */ 56 */
101 @Test 57 @Test
102 public void testEncode() throws Exception { 58 public void testEncode() throws Exception {
103 - socketAddress = InetSocketAddress.createUnresolved("127.0.0.1", 8600); 59 + assertThat(ospfMessageEncoder.encode(channelHandlerContext, channel, object), is(notNullValue()));
104 - channel = EasyMock.createMock(Channel.class);
105 - helloPacket = new HelloPacket();
106 - helloPacket.setDestinationIp(Ip4Address.valueOf("15.15.15.15"));
107 - buf = ChannelBuffers.buffer(hpacket.length);
108 - buf.writeBytes(hpacket);
109 - helloPacket.readFrom(buf);
110 - ospfMessageEncoder.encode(ctx, channel, helloPacket);
111 - ddPacket = new DdPacket();
112 - ddPacket.setDestinationIp(Ip4Address.valueOf("15.15.15.15"));
113 - buf = ChannelBuffers.buffer(dpacket.length);
114 - buf.writeBytes(dpacket);
115 - ddPacket.readFrom(buf);
116 - ospfMessageEncoder.encode(ctx, channel, ddPacket);
117 - lsRequest = new LsRequest();
118 - lsRequest.setDestinationIp(Ip4Address.valueOf("15.15.15.15"));
119 - buf = ChannelBuffers.buffer(lrpacket.length);
120 - buf.writeBytes(lrpacket);
121 - lsRequest.readFrom(buf);
122 - ospfMessageEncoder.encode(ctx, channel, lsRequest);
123 -
124 - lsAcknowledge = new LsAcknowledge();
125 - lsAcknowledge.setDestinationIp(Ip4Address.valueOf("15.15.15.15"));
126 - buf = ChannelBuffers.buffer(lAckpacket.length);
127 - buf.writeBytes(lAckpacket);
128 - lsAcknowledge.readFrom(buf);
129 - ospfMessageEncoder.encode(ctx, channel, lsAcknowledge);
130 - assertThat(ospfMessageEncoder, is(notNullValue()));
131 } 60 }
132 } 61 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -19,31 +19,37 @@ package org.onosproject.ospf.controller.impl; ...@@ -19,31 +19,37 @@ package org.onosproject.ospf.controller.impl;
19 import org.easymock.EasyMock; 19 import org.easymock.EasyMock;
20 import org.jboss.netty.channel.Channel; 20 import org.jboss.netty.channel.Channel;
21 import org.junit.After; 21 import org.junit.After;
22 -import org.junit.Assert;
23 import org.junit.Before; 22 import org.junit.Before;
24 import org.junit.Test; 23 import org.junit.Test;
25 import org.onlab.packet.Ip4Address; 24 import org.onlab.packet.Ip4Address;
25 +import org.onosproject.ospf.controller.OspfAreaAddressRange;
26 import org.onosproject.ospf.controller.OspfInterface; 26 import org.onosproject.ospf.controller.OspfInterface;
27 import org.onosproject.ospf.controller.OspfLsa; 27 import org.onosproject.ospf.controller.OspfLsa;
28 import org.onosproject.ospf.controller.OspfLsaType; 28 import org.onosproject.ospf.controller.OspfLsaType;
29 +import org.onosproject.ospf.controller.OspfMessage;
29 import org.onosproject.ospf.controller.OspfNeighborState; 30 import org.onosproject.ospf.controller.OspfNeighborState;
30 import org.onosproject.ospf.controller.TopologyForDeviceAndLink; 31 import org.onosproject.ospf.controller.TopologyForDeviceAndLink;
32 +import org.onosproject.ospf.controller.area.OspfAreaAddressRangeImpl;
31 import org.onosproject.ospf.controller.area.OspfAreaImpl; 33 import org.onosproject.ospf.controller.area.OspfAreaImpl;
32 import org.onosproject.ospf.controller.area.OspfInterfaceImpl; 34 import org.onosproject.ospf.controller.area.OspfInterfaceImpl;
33 import org.onosproject.ospf.controller.lsdb.LsaWrapperImpl; 35 import org.onosproject.ospf.controller.lsdb.LsaWrapperImpl;
34 import org.onosproject.ospf.controller.lsdb.LsdbAgeImpl; 36 import org.onosproject.ospf.controller.lsdb.LsdbAgeImpl;
37 +import org.onosproject.ospf.controller.util.OspfInterfaceType;
35 import org.onosproject.ospf.protocol.lsa.LsaHeader; 38 import org.onosproject.ospf.protocol.lsa.LsaHeader;
39 +import org.onosproject.ospf.protocol.lsa.OpaqueLsaHeader;
36 import org.onosproject.ospf.protocol.lsa.types.NetworkLsa; 40 import org.onosproject.ospf.protocol.lsa.types.NetworkLsa;
41 +import org.onosproject.ospf.protocol.lsa.types.OpaqueLsa10;
37 import org.onosproject.ospf.protocol.lsa.types.RouterLsa; 42 import org.onosproject.ospf.protocol.lsa.types.RouterLsa;
38 -import org.onosproject.ospf.protocol.ospfpacket.OspfMessage;
39 import org.onosproject.ospf.protocol.ospfpacket.types.DdPacket; 43 import org.onosproject.ospf.protocol.ospfpacket.types.DdPacket;
40 import org.onosproject.ospf.protocol.ospfpacket.types.HelloPacket; 44 import org.onosproject.ospf.protocol.ospfpacket.types.HelloPacket;
41 import org.onosproject.ospf.protocol.ospfpacket.types.LsRequest; 45 import org.onosproject.ospf.protocol.ospfpacket.types.LsRequest;
42 import org.onosproject.ospf.protocol.ospfpacket.types.LsUpdate; 46 import org.onosproject.ospf.protocol.ospfpacket.types.LsUpdate;
43 import org.onosproject.ospf.protocol.util.ChecksumCalculator; 47 import org.onosproject.ospf.protocol.util.ChecksumCalculator;
48 +import org.onosproject.ospf.protocol.util.OspfInterfaceState;
44 import org.onosproject.ospf.protocol.util.OspfUtil; 49 import org.onosproject.ospf.protocol.util.OspfUtil;
45 50
46 import java.net.SocketAddress; 51 import java.net.SocketAddress;
52 +import java.net.UnknownHostException;
47 import java.util.ArrayList; 53 import java.util.ArrayList;
48 import java.util.List; 54 import java.util.List;
49 55
...@@ -55,54 +61,68 @@ import static org.hamcrest.MatcherAssert.assertThat; ...@@ -55,54 +61,68 @@ import static org.hamcrest.MatcherAssert.assertThat;
55 * Unit test class for OspfNbrImpl. 61 * Unit test class for OspfNbrImpl.
56 */ 62 */
57 public class OspfNbrImplTest { 63 public class OspfNbrImplTest {
58 - 64 + private List<OspfAreaAddressRange> addressRanges = new ArrayList();
59 private OspfNbrImpl ospfNbr; 65 private OspfNbrImpl ospfNbr;
66 + private OspfNbrImpl ospfNbr1;
60 private OspfInterfaceImpl ospfInterface; 67 private OspfInterfaceImpl ospfInterface;
61 private OspfAreaImpl ospfArea; 68 private OspfAreaImpl ospfArea;
62 private OspfInterfaceImpl ospfInterface1; 69 private OspfInterfaceImpl ospfInterface1;
63 private OspfInterfaceImpl ospfInterface2; 70 private OspfInterfaceImpl ospfInterface2;
64 - private List<OspfInterface> ospfInterfaces; 71 + private List<OspfInterface> ospfInterfaces = new ArrayList();
65 private List<OspfLsa> ospfLsaList; 72 private List<OspfLsa> ospfLsaList;
66 private Channel channel; 73 private Channel channel;
67 private Channel channel1; 74 private Channel channel1;
68 private Channel channel2; 75 private Channel channel2;
69 private OspfMessage ospfMessage; 76 private OspfMessage ospfMessage;
70 private TopologyForDeviceAndLink topologyForDeviceAndLink; 77 private TopologyForDeviceAndLink topologyForDeviceAndLink;
78 + private LsaHeader lsaHeader;
71 79
72 @Before 80 @Before
73 public void setUp() throws Exception { 81 public void setUp() throws Exception {
82 + lsaHeader = new LsaHeader();
83 + lsaHeader.setLsType(OspfLsaType.ROUTER.value());
84 + RouterLsa routerLsa = new RouterLsa(lsaHeader);
85 + routerLsa.setLsType(OspfLsaType.ROUTER.value());
74 ospfInterface = new OspfInterfaceImpl(); 86 ospfInterface = new OspfInterfaceImpl();
75 ospfInterface.setInterfaceType(2); 87 ospfInterface.setInterfaceType(2);
88 + ospfInterface.setInterfaceIndex(1);
76 ospfInterface.setRouterDeadIntervalTime(30); 89 ospfInterface.setRouterDeadIntervalTime(30);
77 ospfInterface.setReTransmitInterval(30); 90 ospfInterface.setReTransmitInterval(30);
78 ospfInterface.setDr(Ip4Address.valueOf("1.1.1.1")); 91 ospfInterface.setDr(Ip4Address.valueOf("1.1.1.1"));
79 ospfInterface.setIpAddress(Ip4Address.valueOf("1.1.1.1")); 92 ospfInterface.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
80 - ospfArea = new OspfAreaImpl(); 93 + ospfInterface.setState(OspfInterfaceState.POINT2POINT);
94 + ospfArea = createOspfArea();
95 + ospfArea.addLsa(routerLsa, true, ospfInterface);
96 + ospfInterface.setOspfArea(ospfArea);
81 ospfInterface1 = new OspfInterfaceImpl(); 97 ospfInterface1 = new OspfInterfaceImpl();
82 ospfInterface1.setInterfaceType(2); 98 ospfInterface1.setInterfaceType(2);
99 + ospfInterface1.setInterfaceIndex(1);
83 ospfInterface1.setRouterDeadIntervalTime(30); 100 ospfInterface1.setRouterDeadIntervalTime(30);
84 ospfInterface1.setReTransmitInterval(30); 101 ospfInterface1.setReTransmitInterval(30);
85 ospfInterface1.setDr(Ip4Address.valueOf("7.7.7.7")); 102 ospfInterface1.setDr(Ip4Address.valueOf("7.7.7.7"));
86 ospfInterface1.setIpAddress(Ip4Address.valueOf("7.7.7.7")); 103 ospfInterface1.setIpAddress(Ip4Address.valueOf("7.7.7.7"));
104 + ospfInterface1.setState(OspfInterfaceState.DOWN);
105 + ospfInterface1.setOspfArea(ospfArea);
87 ospfInterface2 = new OspfInterfaceImpl(); 106 ospfInterface2 = new OspfInterfaceImpl();
88 ospfInterface2.setInterfaceType(2); 107 ospfInterface2.setInterfaceType(2);
108 + ospfInterface2.setInterfaceIndex(1);
89 ospfInterface2.setRouterDeadIntervalTime(30); 109 ospfInterface2.setRouterDeadIntervalTime(30);
90 ospfInterface2.setReTransmitInterval(30); 110 ospfInterface2.setReTransmitInterval(30);
91 ospfInterface2.setDr(Ip4Address.valueOf("6.6.6.6")); 111 ospfInterface2.setDr(Ip4Address.valueOf("6.6.6.6"));
92 ospfInterface2.setIpAddress(Ip4Address.valueOf("6.6.6.6")); 112 ospfInterface2.setIpAddress(Ip4Address.valueOf("6.6.6.6"));
113 + ospfInterface2.setOspfArea(ospfArea);
114 + ospfInterface1.setState(OspfInterfaceState.DR);
93 ospfInterfaces = new ArrayList(); 115 ospfInterfaces = new ArrayList();
94 ospfInterfaces.add(ospfInterface); 116 ospfInterfaces.add(ospfInterface);
95 ospfInterfaces.add(ospfInterface1); 117 ospfInterfaces.add(ospfInterface1);
96 ospfInterfaces.add(ospfInterface2); 118 ospfInterfaces.add(ospfInterface2);
97 - ospfArea.setInterfacesLst(ospfInterfaces); 119 + ospfArea.setOspfInterfaceList(ospfInterfaces);
120 + ospfInterface.setState(OspfInterfaceState.POINT2POINT);
98 ospfArea.setRouterId(Ip4Address.valueOf("111.111.111.111")); 121 ospfArea.setRouterId(Ip4Address.valueOf("111.111.111.111"));
99 topologyForDeviceAndLink = new TopologyForDeviceAndLinkImpl(); 122 topologyForDeviceAndLink = new TopologyForDeviceAndLinkImpl();
100 ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("1.1.1.1"), 123 ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("1.1.1.1"),
101 Ip4Address.valueOf("2.2.2.2"), 2, 124 Ip4Address.valueOf("2.2.2.2"), 2,
102 - new OspfInterfaceChannelHandler(new Controller(),
103 - ospfArea, ospfInterface),
104 topologyForDeviceAndLink); 125 topologyForDeviceAndLink);
105 -
106 } 126 }
107 127
108 @After 128 @After
...@@ -184,12 +204,19 @@ public class OspfNbrImplTest { ...@@ -184,12 +204,19 @@ public class OspfNbrImplTest {
184 /** 204 /**
185 * Tests negotiationDone() method. 205 * Tests negotiationDone() method.
186 */ 206 */
187 - @Test(expected = Exception.class) 207 + @Test
188 public void testNegotiationDone() throws Exception { 208 public void testNegotiationDone() throws Exception {
209 +
189 ospfLsaList = new ArrayList(); 210 ospfLsaList = new ArrayList();
190 - ospfLsaList.add(new RouterLsa()); 211 + RouterLsa routerLsa = new RouterLsa();
191 - ospfMessage = new HelloPacket(); 212 + routerLsa.setLsType(OspfLsaType.ROUTER.value());
213 + ospfLsaList.add(routerLsa);
214 + DdPacket ddPacket = new DdPacket();
215 + ddPacket.setIsOpaqueCapable(true);
216 + ospfMessage = ddPacket;
192 ospfNbr.setState(OspfNeighborState.EXSTART); 217 ospfNbr.setState(OspfNeighborState.EXSTART);
218 + ospfNbr.setIsOpaqueCapable(true);
219 + channel = null;
193 channel = EasyMock.createMock(Channel.class); 220 channel = EasyMock.createMock(Channel.class);
194 ospfNbr.negotiationDone(ospfMessage, true, ospfLsaList, channel); 221 ospfNbr.negotiationDone(ospfMessage, true, ospfLsaList, channel);
195 channel1 = EasyMock.createMock(Channel.class); 222 channel1 = EasyMock.createMock(Channel.class);
...@@ -230,7 +257,7 @@ public class OspfNbrImplTest { ...@@ -230,7 +257,7 @@ public class OspfNbrImplTest {
230 @Test 257 @Test
231 public void testBadLSReq() throws Exception { 258 public void testBadLSReq() throws Exception {
232 channel = EasyMock.createMock(Channel.class); 259 channel = EasyMock.createMock(Channel.class);
233 - ospfNbr.setState(OspfNeighborState.FULL); 260 + ospfNbr.setState(OspfNeighborState.EXCHANGE);
234 ospfNbr.badLSReq(channel); 261 ospfNbr.badLSReq(channel);
235 assertThat(ospfNbr, is(notNullValue())); 262 assertThat(ospfNbr, is(notNullValue()));
236 } 263 }
...@@ -294,11 +321,24 @@ public class OspfNbrImplTest { ...@@ -294,11 +321,24 @@ public class OspfNbrImplTest {
294 @Test 321 @Test
295 public void testAdjOk() throws Exception { 322 public void testAdjOk() throws Exception {
296 channel = EasyMock.createMock(Channel.class); 323 channel = EasyMock.createMock(Channel.class);
324 + ospfInterface.setInterfaceType(OspfInterfaceType.BROADCAST.value());
297 ospfInterface.setIpAddress(Ip4Address.valueOf("2.2.2.2")); 325 ospfInterface.setIpAddress(Ip4Address.valueOf("2.2.2.2"));
298 - ospfNbr.setState(OspfNeighborState.TWOWAY); 326 + ospfNbr1 = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("1.1.1.1"),
299 - ospfNbr.setNeighborDr(Ip4Address.valueOf("2.2.2.2")); 327 + Ip4Address.valueOf("2.2.2.2"), 2,
300 - ospfNbr.adjOk(channel); 328 + topologyForDeviceAndLink);
301 - Assert.assertNotNull(ospfNbr); 329 + ospfNbr1.setState(OspfNeighborState.TWOWAY);
330 + ospfNbr1.setNeighborDr(Ip4Address.valueOf("2.2.2.2"));
331 + ospfNbr1.adjOk(channel);
332 + assertThat(ospfNbr1, is(notNullValue()));
333 +
334 + ospfInterface.setInterfaceType(OspfInterfaceType.POINT_TO_POINT.value());
335 + ospfNbr1 = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("1.1.1.1"),
336 + Ip4Address.valueOf("2.2.2.2"), 2,
337 + topologyForDeviceAndLink);
338 + channel = null;
339 + channel = EasyMock.createMock(Channel.class);
340 + ospfNbr1.adjOk(channel);
341 + assertThat(ospfNbr1, is(notNullValue()));
302 } 342 }
303 343
304 /** 344 /**
...@@ -321,8 +361,11 @@ public class OspfNbrImplTest { ...@@ -321,8 +361,11 @@ public class OspfNbrImplTest {
321 */ 361 */
322 @Test 362 @Test
323 public void testLoadingDone() throws Exception { 363 public void testLoadingDone() throws Exception {
324 - ospfArea.addLsa(new RouterLsa(), false, ospfInterface); 364 + LsaHeader lsaHeader = new LsaHeader();
325 - ospfArea.addLsa(new RouterLsa(), ospfInterface); 365 + lsaHeader.setLsType(OspfLsaType.ROUTER.value());
366 + RouterLsa routerLsa = new RouterLsa(lsaHeader);
367 + ospfArea.addLsa(routerLsa, false, ospfInterface);
368 + ospfArea.addLsa(routerLsa, ospfInterface);
326 ospfArea.addLsaToMaxAgeBin("lsa", new LsaWrapperImpl()); 369 ospfArea.addLsaToMaxAgeBin("lsa", new LsaWrapperImpl());
327 ospfNbr.loadingDone(); 370 ospfNbr.loadingDone();
328 assertThat(ospfNbr, is(notNullValue())); 371 assertThat(ospfNbr, is(notNullValue()));
...@@ -362,6 +405,7 @@ public class OspfNbrImplTest { ...@@ -362,6 +405,7 @@ public class OspfNbrImplTest {
362 channel1 = EasyMock.createMock(Channel.class); 405 channel1 = EasyMock.createMock(Channel.class);
363 assertThat(ospfNbr.processReceivedLsa(routerlsa, true, channel1, 406 assertThat(ospfNbr.processReceivedLsa(routerlsa, true, channel1,
364 Ip4Address.valueOf("10.10.10.10")), is(true)); 407 Ip4Address.valueOf("10.10.10.10")), is(true));
408 +
365 } 409 }
366 410
367 /** 411 /**
...@@ -394,7 +438,7 @@ public class OspfNbrImplTest { ...@@ -394,7 +438,7 @@ public class OspfNbrImplTest {
394 @Test 438 @Test
395 public void testSendLsa() throws Exception { 439 public void testSendLsa() throws Exception {
396 channel = EasyMock.createMock(Channel.class); 440 channel = EasyMock.createMock(Channel.class);
397 - ospfNbr.sendLsa(new LsaHeader(), Ip4Address.valueOf("1.1.1.1"), channel); 441 + ospfNbr.sendLsa(lsaHeader, Ip4Address.valueOf("1.1.1.1"), channel);
398 assertThat(ospfNbr, is(notNullValue())); 442 assertThat(ospfNbr, is(notNullValue()));
399 } 443 }
400 444
...@@ -648,4 +692,77 @@ public class OspfNbrImplTest { ...@@ -648,4 +692,77 @@ public class OspfNbrImplTest {
648 public void testGetPendingReTxList() throws Exception { 692 public void testGetPendingReTxList() throws Exception {
649 assertThat(ospfNbr.getPendingReTxList(), is(notNullValue())); 693 assertThat(ospfNbr.getPendingReTxList(), is(notNullValue()));
650 } 694 }
695 +
696 + /**
697 + * Utility for test method.
698 + */
699 + private OspfAreaImpl createOspfArea() throws UnknownHostException {
700 + OspfAreaAddressRangeImpl ospfAreaAddressRange;
701 + ospfAreaAddressRange = createOspfAreaAddressRange();
702 + addressRanges.add(ospfAreaAddressRange);
703 + OspfAreaImpl ospfArea = new OspfAreaImpl();
704 + ospfArea.setAreaId(Ip4Address.valueOf("10.226.165.164"));
705 + ospfArea.setExternalRoutingCapability(true);
706 + OspfInterfaceImpl ospfInterface = createOspfInterface();
707 + ospfInterfaces.add(ospfInterface);
708 + ospfArea.setOspfInterfaceList(ospfInterfaces);
709 + RouterLsa routerLsa = new RouterLsa();
710 + routerLsa.setLsType(1);
711 + routerLsa.setLinkStateId("2.2.2.2");
712 + routerLsa.setAdvertisingRouter(Ip4Address.valueOf("2.2.2.2"));
713 + OpaqueLsaHeader opaqueLsaHeader = new OpaqueLsaHeader();
714 + OpaqueLsa10 opaqueLsa10 = new OpaqueLsa10(opaqueLsaHeader);
715 + opaqueLsa10.setLsType(OspfLsaType.AREA_LOCAL_OPAQUE_LSA.value());
716 + opaqueLsa10.setLinkStateId("2.2.2.2");
717 + opaqueLsa10.setAdvertisingRouter(Ip4Address.valueOf("2.2.2.2"));
718 + try {
719 + ospfArea.addLsa(routerLsa, false, ospfInterface);
720 + ospfArea.addLsa(opaqueLsa10, false, ospfInterface);
721 + } catch (Exception e) {
722 + System.out.println("ospfAreaImpl createOspfArea");
723 + }
724 + ospfArea.setRouterId(Ip4Address.valueOf("111.111.111.111"));
725 +
726 + return ospfArea;
727 + }
728 +
729 + /**
730 + * Utility for test method.
731 + */
732 + private OspfAreaAddressRangeImpl createOspfAreaAddressRange() {
733 + OspfAreaAddressRangeImpl ospfAreaAddressRange = new OspfAreaAddressRangeImpl();
734 + ospfAreaAddressRange.setIpAddress(Ip4Address.valueOf("10.226.165.164"));
735 + ospfAreaAddressRange.setAdvertise(true);
736 + ospfAreaAddressRange.setMask("mask");
737 + return ospfAreaAddressRange;
738 + }
739 +
740 + /**
741 + * Utility for test method.
742 + */
743 + private OspfInterfaceImpl createOspfInterface() throws UnknownHostException {
744 + ospfInterface = new OspfInterfaceImpl();
745 + OspfAreaImpl ospfArea = new OspfAreaImpl();
746 + OspfInterfaceChannelHandler ospfInterfaceChannelHandler = EasyMock.createMock(
747 + OspfInterfaceChannelHandler.class);
748 + ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("10.226.165.164"),
749 + Ip4Address.valueOf("1.1.1.1"), 2,
750 + topologyForDeviceAndLink);
751 + ospfNbr.setState(OspfNeighborState.EXSTART);
752 + ospfNbr.setNeighborId(Ip4Address.valueOf("10.226.165.100"));
753 + this.ospfInterface = new OspfInterfaceImpl();
754 + this.ospfInterface.setIpAddress(Ip4Address.valueOf("10.226.165.164"));
755 + this.ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
756 + this.ospfInterface.setBdr(Ip4Address.valueOf("111.111.111.111"));
757 + this.ospfInterface.setDr(Ip4Address.valueOf("111.111.111.111"));
758 + this.ospfInterface.setHelloIntervalTime(20);
759 + this.ospfInterface.setInterfaceType(2);
760 + this.ospfInterface.setReTransmitInterval(2000);
761 + this.ospfInterface.setMtu(6500);
762 + this.ospfInterface.setRouterDeadIntervalTime(1000);
763 + this.ospfInterface.setRouterPriority(1);
764 + this.ospfInterface.setInterfaceType(1);
765 + this.ospfInterface.addNeighbouringRouter(ospfNbr);
766 + return this.ospfInterface;
767 + }
651 } 768 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -18,12 +18,6 @@ package org.onosproject.ospf.controller.impl; ...@@ -18,12 +18,6 @@ package org.onosproject.ospf.controller.impl;
18 import org.jboss.netty.channel.ChannelPipeline; 18 import org.jboss.netty.channel.ChannelPipeline;
19 import org.junit.After; 19 import org.junit.After;
20 import org.junit.Before; 20 import org.junit.Before;
21 -import org.junit.Test;
22 -import org.onosproject.ospf.controller.area.OspfAreaImpl;
23 -import org.onosproject.ospf.controller.area.OspfInterfaceImpl;
24 -
25 -import static org.hamcrest.CoreMatchers.*;
26 -import static org.hamcrest.MatcherAssert.assertThat;
27 21
28 /** 22 /**
29 * Unit test class for OspfPipelineFactory. 23 * Unit test class for OspfPipelineFactory.
...@@ -35,8 +29,6 @@ public class OspfPipelineFactoryTest { ...@@ -35,8 +29,6 @@ public class OspfPipelineFactoryTest {
35 29
36 @Before 30 @Before
37 public void setUp() throws Exception { 31 public void setUp() throws Exception {
38 - ospfPipelineFactory = new OspfPipelineFactory(new Controller(), new OspfAreaImpl(), new OspfInterfaceImpl());
39 -
40 } 32 }
41 33
42 @After 34 @After
...@@ -44,22 +36,4 @@ public class OspfPipelineFactoryTest { ...@@ -44,22 +36,4 @@ public class OspfPipelineFactoryTest {
44 ospfPipelineFactory = null; 36 ospfPipelineFactory = null;
45 channelPipeline = null; 37 channelPipeline = null;
46 } 38 }
47 -
48 - /**
49 - * Tests getPipeline() method.
50 - */
51 - @Test
52 - public void testGetPipeline() throws Exception {
53 - channelPipeline = ospfPipelineFactory.getPipeline();
54 - assertThat(channelPipeline, is(notNullValue()));
55 - }
56 -
57 - /**
58 - * Tests releaseExternalResources() method.
59 - */
60 - @Test
61 - public void testReleaseExternalResources() throws Exception {
62 - ospfPipelineFactory.releaseExternalResources();
63 - assertThat(channelPipeline, is(nullValue()));
64 - }
65 } 39 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -74,8 +74,9 @@ public class LsaQueueConsumerTest { ...@@ -74,8 +74,9 @@ public class LsaQueueConsumerTest {
74 @Test 74 @Test
75 public void testRun() throws Exception { 75 public void testRun() throws Exception {
76 blockingQueue = new ArrayBlockingQueue(5); 76 blockingQueue = new ArrayBlockingQueue(5);
77 - channel = EasyMock.createMock(Channel.class);
78 ospfArea = new OspfAreaImpl(); 77 ospfArea = new OspfAreaImpl();
78 + lsdbAge = new LsdbAgeImpl(ospfArea);
79 + channel = EasyMock.createMock(Channel.class);
79 lsaWrapper = new LsaWrapperImpl(); 80 lsaWrapper = new LsaWrapperImpl();
80 lsaWrapper.setLsaProcessing("verifyChecksum"); 81 lsaWrapper.setLsaProcessing("verifyChecksum");
81 blockingQueue.add(lsaWrapper); 82 blockingQueue.add(lsaWrapper);
...@@ -104,7 +105,7 @@ public class LsaQueueConsumerTest { ...@@ -104,7 +105,7 @@ public class LsaQueueConsumerTest {
104 lsaHeader.setLsType(1); 105 lsaHeader.setLsType(1);
105 lsaWrapper.setLsaHeader(lsaHeader); 106 lsaWrapper.setLsaHeader(lsaHeader);
106 lsaWrapper.setLsaProcessing("refreshLsa"); 107 lsaWrapper.setLsaProcessing("refreshLsa");
107 - lsaWrapper.setLsdbAge(new LsdbAgeImpl(new OspfAreaImpl())); 108 + lsaWrapper.setLsdbAge(new LsdbAgeImpl(ospfArea));
108 blockingQueue.add(lsaWrapper); 109 blockingQueue.add(lsaWrapper);
109 lsaQueueConsumer = new LsaQueueConsumer(blockingQueue, channel, ospfArea); 110 lsaQueueConsumer = new LsaQueueConsumer(blockingQueue, channel, ospfArea);
110 lsaQueueConsumer.run(); 111 lsaQueueConsumer.run();
...@@ -128,7 +129,7 @@ public class LsaQueueConsumerTest { ...@@ -128,7 +129,7 @@ public class LsaQueueConsumerTest {
128 lsaHeader.setLsType(2); 129 lsaHeader.setLsType(2);
129 lsaWrapper.setLsaHeader(lsaHeader); 130 lsaWrapper.setLsaHeader(lsaHeader);
130 lsaWrapper.setLsaProcessing("refreshLsa"); 131 lsaWrapper.setLsaProcessing("refreshLsa");
131 - lsaWrapper.setLsdbAge(new LsdbAgeImpl(new OspfAreaImpl())); 132 + lsaWrapper.setLsdbAge(new LsdbAgeImpl(ospfArea));
132 blockingQueue.add(lsaWrapper); 133 blockingQueue.add(lsaWrapper);
133 lsaQueueConsumer = new LsaQueueConsumer(blockingQueue, channel, ospfArea); 134 lsaQueueConsumer = new LsaQueueConsumer(blockingQueue, channel, ospfArea);
134 lsaQueueConsumer.run(); 135 lsaQueueConsumer.run();
...@@ -155,7 +156,7 @@ public class LsaQueueConsumerTest { ...@@ -155,7 +156,7 @@ public class LsaQueueConsumerTest {
155 lsaHeader.setLsType(2); 156 lsaHeader.setLsType(2);
156 lsaWrapper.setLsaHeader(lsaHeader); 157 lsaWrapper.setLsaHeader(lsaHeader);
157 lsaWrapper.setLsaProcessing("maxAgeLsa"); 158 lsaWrapper.setLsaProcessing("maxAgeLsa");
158 - lsaWrapper.setLsdbAge(new LsdbAgeImpl(new OspfAreaImpl())); 159 + lsaWrapper.setLsdbAge(new LsdbAgeImpl(ospfArea));
159 blockingQueue.add(lsaWrapper); 160 blockingQueue.add(lsaWrapper);
160 lsaQueueConsumer = new LsaQueueConsumer(blockingQueue, channel, ospfArea); 161 lsaQueueConsumer = new LsaQueueConsumer(blockingQueue, channel, ospfArea);
161 lsaQueueConsumer.run(); 162 lsaQueueConsumer.run();
...@@ -168,7 +169,7 @@ public class LsaQueueConsumerTest { ...@@ -168,7 +169,7 @@ public class LsaQueueConsumerTest {
168 @Test 169 @Test
169 public void testSetChannel() throws Exception { 170 public void testSetChannel() throws Exception {
170 channel = EasyMock.createMock(Channel.class); 171 channel = EasyMock.createMock(Channel.class);
171 - lsdbAge = new LsdbAgeImpl(new OspfAreaImpl()); 172 + lsdbAge = new LsdbAgeImpl(ospfArea);
172 lsdbAge.startDbAging(); 173 lsdbAge.startDbAging();
173 lsdbAge.setChannel(channel); 174 lsdbAge.setChannel(channel);
174 assertThat(lsaQueueConsumer, is(notNullValue())); 175 assertThat(lsaQueueConsumer, is(notNullValue()));
......
...@@ -23,6 +23,7 @@ import org.junit.Before; ...@@ -23,6 +23,7 @@ import org.junit.Before;
23 import org.junit.Test; 23 import org.junit.Test;
24 import org.onosproject.ospf.controller.LsaBin; 24 import org.onosproject.ospf.controller.LsaBin;
25 import org.onosproject.ospf.controller.OspfArea; 25 import org.onosproject.ospf.controller.OspfArea;
26 +import org.onosproject.ospf.controller.OspfLsaType;
26 import org.onosproject.ospf.controller.area.OspfAreaImpl; 27 import org.onosproject.ospf.controller.area.OspfAreaImpl;
27 28
28 import static org.hamcrest.CoreMatchers.*; 29 import static org.hamcrest.CoreMatchers.*;
...@@ -181,14 +182,10 @@ public class LsdbAgeImplTest { ...@@ -181,14 +182,10 @@ public class LsdbAgeImplTest {
181 public void testRefereshLsa() throws Exception { 182 public void testRefereshLsa() throws Exception {
182 lsaWrapper = EasyMock.createMock(LsaWrapperImpl.class); 183 lsaWrapper = EasyMock.createMock(LsaWrapperImpl.class);
183 lsaWrapper.setBinNumber(0); 184 lsaWrapper.setBinNumber(0);
185 + lsaWrapper.setLsaType(OspfLsaType.NETWORK);
184 lsdbAge.addLsaToMaxAgeBin("lsa1", lsaWrapper); 186 lsdbAge.addLsaToMaxAgeBin("lsa1", lsaWrapper);
185 lsdbAge.ageLsaAndFlood(); 187 lsdbAge.ageLsaAndFlood();
186 - lsaWrapper.setBinNumber(0);
187 - lsaWrapper = EasyMock.createMock(LsaWrapperImpl.class);
188 - lsdbAge.addLsaToMaxAgeBin("lsa2", lsaWrapper);
189 - lsdbAge.ageLsaAndFlood();
190 lsdbAge.startDbAging(); 188 lsdbAge.startDbAging();
191 - lsaBin = new LsaBinImpl(1809);
192 lsdbAge.refreshLsa(); 189 lsdbAge.refreshLsa();
193 assertThat(lsdbAge, is(notNullValue())); 190 assertThat(lsdbAge, is(notNullValue()));
194 } 191 }
......
1 /* 1 /*
2 - * Copyright 2016-present Open Networking Laboratory 2 + * Copyright 2016 Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
......
...@@ -103,6 +103,16 @@ public class NetworkLsa extends LsaHeader { ...@@ -103,6 +103,16 @@ public class NetworkLsa extends LsaHeader {
103 } 103 }
104 104
105 /** 105 /**
106 + * Gets the list of attached routers.
107 + *
108 + * @return list of attached routers
109 + */
110 + public List<Ip4Address> attachedRouters() {
111 +
112 + return attachedRouters;
113 + }
114 +
115 + /**
106 * Reads from channel buffer and populate instance. 116 * Reads from channel buffer and populate instance.
107 * 117 *
108 * @param channelBuffer channel buffer instance 118 * @param channelBuffer channel buffer instance
......
...@@ -29,7 +29,6 @@ import org.onosproject.ospf.protocol.lsa.tlvtypes.OpaqueTopLevelTlvTypes; ...@@ -29,7 +29,6 @@ import org.onosproject.ospf.protocol.lsa.tlvtypes.OpaqueTopLevelTlvTypes;
29 import org.onosproject.ospf.protocol.lsa.tlvtypes.RouterTlv; 29 import org.onosproject.ospf.protocol.lsa.tlvtypes.RouterTlv;
30 import org.onosproject.ospf.protocol.util.OspfParameters; 30 import org.onosproject.ospf.protocol.util.OspfParameters;
31 31
32 -import java.util.Arrays;
33 import java.util.ArrayList; 32 import java.util.ArrayList;
34 import java.util.List; 33 import java.util.List;
35 34
...@@ -193,11 +192,11 @@ public class OpaqueLsa10 extends OpaqueLsaHeader { ...@@ -193,11 +192,11 @@ public class OpaqueLsa10 extends OpaqueLsaHeader {
193 } 192 }
194 OpaqueLsa10 that = (OpaqueLsa10) o; 193 OpaqueLsa10 that = (OpaqueLsa10) o;
195 return Objects.equal(topLevelValues, that.topLevelValues) && 194 return Objects.equal(topLevelValues, that.topLevelValues) &&
196 - Arrays.equals(opaqueInfo, that.opaqueInfo); 195 + Objects.equal(opaqueInfo, that.opaqueInfo);
197 } 196 }
198 197
199 @Override 198 @Override
200 public int hashCode() { 199 public int hashCode() {
201 - return Objects.hashCode(Arrays.hashCode(opaqueInfo), topLevelValues); 200 + return Objects.hashCode(opaqueInfo, topLevelValues);
202 } 201 }
203 } 202 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -16,13 +16,12 @@ ...@@ -16,13 +16,12 @@
16 package org.onosproject.ospf.protocol.lsa.types; 16 package org.onosproject.ospf.protocol.lsa.types;
17 17
18 import com.google.common.base.MoreObjects; 18 import com.google.common.base.MoreObjects;
19 +import com.google.common.base.Objects;
19 import com.google.common.primitives.Bytes; 20 import com.google.common.primitives.Bytes;
20 import org.jboss.netty.buffer.ChannelBuffer; 21 import org.jboss.netty.buffer.ChannelBuffer;
21 import org.onosproject.ospf.controller.OspfLsaType; 22 import org.onosproject.ospf.controller.OspfLsaType;
22 import org.onosproject.ospf.protocol.lsa.OpaqueLsaHeader; 23 import org.onosproject.ospf.protocol.lsa.OpaqueLsaHeader;
23 24
24 -import java.util.Arrays;
25 -
26 /** 25 /**
27 * Representation of an Opaque LSA of type AS (11). 26 * Representation of an Opaque LSA of type AS (11).
28 */ 27 */
...@@ -107,12 +106,12 @@ public class OpaqueLsa11 extends OpaqueLsaHeader { ...@@ -107,12 +106,12 @@ public class OpaqueLsa11 extends OpaqueLsaHeader {
107 return false; 106 return false;
108 } 107 }
109 OpaqueLsa11 that = (OpaqueLsa11) o; 108 OpaqueLsa11 that = (OpaqueLsa11) o;
110 - return Arrays.equals(opaqueInfo, that.opaqueInfo); 109 + return Objects.equal(opaqueInfo, that.opaqueInfo);
111 } 110 }
112 111
113 @Override 112 @Override
114 public int hashCode() { 113 public int hashCode() {
115 - return Arrays.hashCode(opaqueInfo); 114 + return Objects.hashCode(opaqueInfo);
116 } 115 }
117 116
118 @Override 117 @Override
......
...@@ -16,13 +16,12 @@ ...@@ -16,13 +16,12 @@
16 package org.onosproject.ospf.protocol.lsa.types; 16 package org.onosproject.ospf.protocol.lsa.types;
17 17
18 import com.google.common.base.MoreObjects; 18 import com.google.common.base.MoreObjects;
19 +import com.google.common.base.Objects;
19 import com.google.common.primitives.Bytes; 20 import com.google.common.primitives.Bytes;
20 import org.jboss.netty.buffer.ChannelBuffer; 21 import org.jboss.netty.buffer.ChannelBuffer;
21 import org.onosproject.ospf.controller.OspfLsaType; 22 import org.onosproject.ospf.controller.OspfLsaType;
22 import org.onosproject.ospf.protocol.lsa.OpaqueLsaHeader; 23 import org.onosproject.ospf.protocol.lsa.OpaqueLsaHeader;
23 24
24 -import java.util.Arrays;
25 -
26 /** 25 /**
27 * Representation of an Opaque LSA of type link local (9). 26 * Representation of an Opaque LSA of type link local (9).
28 */ 27 */
...@@ -109,12 +108,12 @@ public class OpaqueLsa9 extends OpaqueLsaHeader { ...@@ -109,12 +108,12 @@ public class OpaqueLsa9 extends OpaqueLsaHeader {
109 return false; 108 return false;
110 } 109 }
111 OpaqueLsa9 that = (OpaqueLsa9) o; 110 OpaqueLsa9 that = (OpaqueLsa9) o;
112 - return Arrays.equals(opaqueInfo, that.opaqueInfo); 111 + return Objects.equal(opaqueInfo, that.opaqueInfo);
113 } 112 }
114 113
115 @Override 114 @Override
116 public int hashCode() { 115 public int hashCode() {
117 - return Arrays.hashCode(opaqueInfo); 116 + return Objects.hashCode(opaqueInfo);
118 } 117 }
119 118
120 @Override 119 @Override
......
...@@ -18,6 +18,7 @@ package org.onosproject.ospf.protocol.ospfpacket; ...@@ -18,6 +18,7 @@ package org.onosproject.ospf.protocol.ospfpacket;
18 18
19 import org.jboss.netty.buffer.ChannelBuffer; 19 import org.jboss.netty.buffer.ChannelBuffer;
20 import org.onlab.packet.Ip4Address; 20 import org.onlab.packet.Ip4Address;
21 +import org.onosproject.ospf.controller.OspfMessage;
21 import org.onosproject.ospf.exceptions.OspfErrorType; 22 import org.onosproject.ospf.exceptions.OspfErrorType;
22 import org.onosproject.ospf.exceptions.OspfParseException; 23 import org.onosproject.ospf.exceptions.OspfParseException;
23 import org.onosproject.ospf.protocol.ospfpacket.types.DdPacket; 24 import org.onosproject.ospf.protocol.ospfpacket.types.DdPacket;
...@@ -46,15 +47,8 @@ public class OspfMessageReader { ...@@ -46,15 +47,8 @@ public class OspfMessageReader {
46 public OspfMessage readFromBuffer(ChannelBuffer channelBuffer) 47 public OspfMessage readFromBuffer(ChannelBuffer channelBuffer)
47 throws Exception { 48 throws Exception {
48 49
49 - if (channelBuffer.readableBytes() < OspfUtil.PACKET_MINIMUM_LENGTH) {
50 - log.error("Packet should have minimum length...");
51 - throw new OspfParseException(OspfErrorType.MESSAGE_HEADER_ERROR, OspfErrorType.BAD_MESSAGE_LENGTH);
52 - }
53 -
54 try { 50 try {
55 OspfPacketHeader ospfHeader = getOspfHeader(channelBuffer); 51 OspfPacketHeader ospfHeader = getOspfHeader(channelBuffer);
56 - int len = ospfHeader.ospfPacLength() - OspfUtil.OSPF_HEADER_LENGTH;
57 -
58 OspfMessage ospfMessage = null; 52 OspfMessage ospfMessage = null;
59 switch (ospfHeader.ospfType()) { 53 switch (ospfHeader.ospfType()) {
60 case OspfParameters.HELLO: 54 case OspfParameters.HELLO:
...@@ -81,7 +75,8 @@ public class OspfMessageReader { ...@@ -81,7 +75,8 @@ public class OspfMessageReader {
81 try { 75 try {
82 log.debug("{} Received::Message Length :: {} ", ospfMessage.ospfMessageType(), 76 log.debug("{} Received::Message Length :: {} ", ospfMessage.ospfMessageType(),
83 ospfHeader.ospfPacLength()); 77 ospfHeader.ospfPacLength());
84 - ospfMessage.readFrom(channelBuffer.readBytes(len)); 78 + ospfMessage.readFrom(channelBuffer.readBytes(ospfHeader.ospfPacLength() -
79 + OspfUtil.OSPF_HEADER_LENGTH));
85 } catch (Exception e) { 80 } catch (Exception e) {
86 throw new OspfParseException(OspfErrorType.OSPF_MESSAGE_ERROR, 81 throw new OspfParseException(OspfErrorType.OSPF_MESSAGE_ERROR,
87 OspfErrorType.BAD_MESSAGE); 82 OspfErrorType.BAD_MESSAGE);
...@@ -105,22 +100,13 @@ public class OspfMessageReader { ...@@ -105,22 +100,13 @@ public class OspfMessageReader {
105 private OspfPacketHeader getOspfHeader(ChannelBuffer channelBuffer) throws Exception { 100 private OspfPacketHeader getOspfHeader(ChannelBuffer channelBuffer) throws Exception {
106 OspfPacketHeader ospfPacketHeader = new OspfPacketHeader(); 101 OspfPacketHeader ospfPacketHeader = new OspfPacketHeader();
107 102
108 - byte[] sourceIpBytes = new byte[OspfUtil.FOUR_BYTES]; 103 + // Determine OSPF version & Packet Type
109 - channelBuffer.readBytes(sourceIpBytes, 0, OspfUtil.FOUR_BYTES);
110 - Ip4Address sourceIP = Ip4Address.valueOf(sourceIpBytes);
111 -
112 - // Determine ospf version & Packet Type
113 int version = channelBuffer.readByte(); //byte 1 is ospf version 104 int version = channelBuffer.readByte(); //byte 1 is ospf version
114 int packetType = channelBuffer.readByte(); //byte 2 is ospf packet type 105 int packetType = channelBuffer.readByte(); //byte 2 is ospf packet type
115 106
116 // byte 3 & 4 combine is packet length. 107 // byte 3 & 4 combine is packet length.
117 int packetLength = channelBuffer.readShort(); 108 int packetLength = channelBuffer.readShort();
118 109
119 - if (packetLength > channelBuffer.readableBytes() + OspfUtil.FOUR_BYTES) {
120 - log.error("Packet should have minimum length...");
121 - throw new OspfParseException(OspfErrorType.MESSAGE_HEADER_ERROR, OspfErrorType.BAD_MESSAGE_LENGTH);
122 - }
123 -
124 byte[] tempByteArray = new byte[OspfUtil.FOUR_BYTES]; 110 byte[] tempByteArray = new byte[OspfUtil.FOUR_BYTES];
125 channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES); 111 channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES);
126 Ip4Address routerId = Ip4Address.valueOf(tempByteArray); 112 Ip4Address routerId = Ip4Address.valueOf(tempByteArray);
...@@ -133,7 +119,6 @@ public class OspfMessageReader { ...@@ -133,7 +119,6 @@ public class OspfMessageReader {
133 int auType = channelBuffer.readUnsignedShort(); 119 int auType = channelBuffer.readUnsignedShort();
134 int authentication = (int) channelBuffer.readLong(); 120 int authentication = (int) channelBuffer.readLong();
135 121
136 - ospfPacketHeader.setSourceIp(sourceIP);
137 ospfPacketHeader.setOspfVer(version); 122 ospfPacketHeader.setOspfVer(version);
138 ospfPacketHeader.setOspftype(packetType); 123 ospfPacketHeader.setOspftype(packetType);
139 ospfPacketHeader.setOspfPacLength(packetLength); 124 ospfPacketHeader.setOspfPacLength(packetLength);
......
1 /* 1 /*
2 -* Copyright 2016-present Open Networking Laboratory 2 +* Copyright 2016 Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -15,41 +15,36 @@ ...@@ -15,41 +15,36 @@
15 */ 15 */
16 package org.onosproject.ospf.protocol.ospfpacket; 16 package org.onosproject.ospf.protocol.ospfpacket;
17 17
18 -import org.jboss.netty.buffer.ChannelBuffer; 18 +import org.onosproject.ospf.controller.OspfMessage;
19 -import org.jboss.netty.buffer.ChannelBuffers;
20 import org.onosproject.ospf.protocol.util.OspfParameters; 19 import org.onosproject.ospf.protocol.util.OspfParameters;
21 import org.onosproject.ospf.protocol.util.OspfUtil; 20 import org.onosproject.ospf.protocol.util.OspfUtil;
22 import org.slf4j.Logger; 21 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory; 22 import org.slf4j.LoggerFactory;
24 23
25 /** 24 /**
26 - * A message writer which writes an OspfMessage to ChannelBuffer. 25 + * A message writer which writes an OSPF message to byte array.
27 */ 26 */
28 public class OspfMessageWriter { 27 public class OspfMessageWriter {
29 private static final Logger log = LoggerFactory.getLogger(OspfMessageWriter.class); 28 private static final Logger log = LoggerFactory.getLogger(OspfMessageWriter.class);
30 29
31 /** 30 /**
32 - * Writes OSPF message to ChannelBuffer. 31 + * Writes OSPF message to byte array.
33 * 32 *
34 * @param ospfMessage OSPF message 33 * @param ospfMessage OSPF message
34 + * @param interfaceIndex interface index
35 * @param interfaceState interface state 35 * @param interfaceState interface state
36 - * @param interfaceType interface type 36 + * @return message as byte array
37 - * @return channelBuffer channel buffer instance
38 - * @throws Exception might throws exception while parsing message
39 */ 37 */
40 - public ChannelBuffer writeToBuffer(OspfMessage ospfMessage, int interfaceState, 38 + public byte[] getMessage(OspfMessage ospfMessage, int interfaceIndex, int interfaceState) {
41 - int interfaceType) throws Exception {
42 39
43 - ChannelBuffer buf = null; 40 + byte[] buf = null;
44 switch (ospfMessage.ospfMessageType().value()) { 41 switch (ospfMessage.ospfMessageType().value()) {
45 case OspfParameters.HELLO: 42 case OspfParameters.HELLO:
46 case OspfParameters.LSACK: 43 case OspfParameters.LSACK:
47 - buf = writeMessageToBuffer(ospfMessage, interfaceState);
48 - break;
49 case OspfParameters.DD: 44 case OspfParameters.DD:
50 case OspfParameters.LSREQUEST: 45 case OspfParameters.LSREQUEST:
51 case OspfParameters.LSUPDATE: 46 case OspfParameters.LSUPDATE:
52 - buf = writeMessageToBuffer(ospfMessage, interfaceState); 47 + buf = writeMessageToBytes(ospfMessage, interfaceIndex, interfaceState);
53 break; 48 break;
54 default: 49 default:
55 log.debug("Message Writer[Encoder] - Unknown Message to encode..!!!"); 50 log.debug("Message Writer[Encoder] - Unknown Message to encode..!!!");
...@@ -60,14 +55,13 @@ public class OspfMessageWriter { ...@@ -60,14 +55,13 @@ public class OspfMessageWriter {
60 } 55 }
61 56
62 /** 57 /**
63 - * Writes an OSPF Message to channel buffer. 58 + * Writes an OSPF Message to byte array.
64 * 59 *
65 * @param ospfMessage OSPF Message instance 60 * @param ospfMessage OSPF Message instance
66 * @param interfaceState interface state 61 * @param interfaceState interface state
67 - * @return channelBuffer instance 62 + * @return message as byte array
68 */ 63 */
69 - private ChannelBuffer writeMessageToBuffer(OspfMessage ospfMessage, int interfaceState) throws Exception { 64 + private byte[] writeMessageToBytes(OspfMessage ospfMessage, int interfaceIndex, int interfaceState) {
70 - ChannelBuffer channelBuffer = null;
71 byte[] ospfMessageAsByte = ospfMessage.asBytes(); 65 byte[] ospfMessageAsByte = ospfMessage.asBytes();
72 //Add the length and checksum in byte array at length position 2 & 3 and Checksum position 66 //Add the length and checksum in byte array at length position 2 & 3 and Checksum position
73 ospfMessageAsByte = OspfUtil.addLengthAndCheckSum(ospfMessageAsByte, OspfUtil.OSPFPACKET_LENGTH_POS1, 67 ospfMessageAsByte = OspfUtil.addLengthAndCheckSum(ospfMessageAsByte, OspfUtil.OSPFPACKET_LENGTH_POS1,
...@@ -76,16 +70,13 @@ public class OspfMessageWriter { ...@@ -76,16 +70,13 @@ public class OspfMessageWriter {
76 OspfUtil.OSPFPACKET_CHECKSUM_POS2); 70 OspfUtil.OSPFPACKET_CHECKSUM_POS2);
77 //Add Interface State Info and destination IP as metadata 71 //Add Interface State Info and destination IP as metadata
78 if (interfaceState == OspfParameters.DR || interfaceState == OspfParameters.BDR) { 72 if (interfaceState == OspfParameters.DR || interfaceState == OspfParameters.BDR) {
79 - ospfMessageAsByte = OspfUtil.addMetadata(ospfMessageAsByte, OspfUtil.JOIN_ALL_DROUTERS, 73 + ospfMessageAsByte = OspfUtil.addMetadata(interfaceIndex, ospfMessageAsByte, OspfUtil.JOIN_ALL_DROUTERS,
80 ospfMessage.destinationIp()); 74 ospfMessage.destinationIp());
81 } else { 75 } else {
82 - ospfMessageAsByte = OspfUtil.addMetadata(ospfMessageAsByte, OspfUtil.ONLY_ALL_SPF_ROUTERS, 76 + ospfMessageAsByte = OspfUtil.addMetadata(interfaceIndex, ospfMessageAsByte, OspfUtil.ONLY_ALL_SPF_ROUTERS,
83 ospfMessage.destinationIp()); 77 ospfMessage.destinationIp());
84 } 78 }
85 79
86 - channelBuffer = ChannelBuffers.buffer(ospfMessageAsByte.length); 80 + return ospfMessageAsByte;
87 - channelBuffer.writeBytes(ospfMessageAsByte);
88 -
89 - return channelBuffer;
90 } 81 }
91 } 82 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -18,8 +18,9 @@ package org.onosproject.ospf.protocol.ospfpacket; ...@@ -18,8 +18,9 @@ package org.onosproject.ospf.protocol.ospfpacket;
18 import com.google.common.base.MoreObjects; 18 import com.google.common.base.MoreObjects;
19 import org.jboss.netty.buffer.ChannelBuffer; 19 import org.jboss.netty.buffer.ChannelBuffer;
20 import org.onlab.packet.Ip4Address; 20 import org.onlab.packet.Ip4Address;
21 +import org.onosproject.ospf.controller.OspfMessage;
22 +import org.onosproject.ospf.controller.OspfPacketType;
21 import org.onosproject.ospf.exceptions.OspfParseException; 23 import org.onosproject.ospf.exceptions.OspfParseException;
22 -import org.onosproject.ospf.protocol.util.OspfPacketType;
23 24
24 /** 25 /**
25 * Defines the OSPF Packet Header, fields and access methods. 26 * Defines the OSPF Packet Header, fields and access methods.
...@@ -57,6 +58,7 @@ public class OspfPacketHeader implements OspfMessage { ...@@ -57,6 +58,7 @@ public class OspfPacketHeader implements OspfMessage {
57 private int authentication; 58 private int authentication;
58 private Ip4Address destinationIp; 59 private Ip4Address destinationIp;
59 private Ip4Address sourceIp; 60 private Ip4Address sourceIp;
61 + private int interfaceIndex;
60 62
61 /** 63 /**
62 * Gets the source IP. 64 * Gets the source IP.
...@@ -256,11 +258,30 @@ public class OspfPacketHeader implements OspfMessage { ...@@ -256,11 +258,30 @@ public class OspfPacketHeader implements OspfMessage {
256 } 258 }
257 259
258 /** 260 /**
261 + * 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 + /**
259 * Populates the header from the packetHeader instance. 279 * Populates the header from the packetHeader instance.
260 * 280 *
261 * @param ospfPacketHeader packet header instance. 281 * @param ospfPacketHeader packet header instance.
262 */ 282 */
263 public void populateHeader(OspfPacketHeader ospfPacketHeader) { 283 public void populateHeader(OspfPacketHeader ospfPacketHeader) {
284 + this.setInterfaceIndex(ospfPacketHeader.interfaceIndex());
264 this.setSourceIp(ospfPacketHeader.sourceIp()); 285 this.setSourceIp(ospfPacketHeader.sourceIp());
265 this.setOspfVer(ospfPacketHeader.ospfVersion()); 286 this.setOspfVer(ospfPacketHeader.ospfVersion());
266 this.setOspftype(ospfPacketHeader.ospfType()); 287 this.setOspftype(ospfPacketHeader.ospfType());
......
...@@ -23,7 +23,7 @@ import org.onosproject.ospf.exceptions.OspfParseException; ...@@ -23,7 +23,7 @@ import org.onosproject.ospf.exceptions.OspfParseException;
23 import org.onosproject.ospf.protocol.lsa.LsaHeader; 23 import org.onosproject.ospf.protocol.lsa.LsaHeader;
24 import org.onosproject.ospf.protocol.lsa.OpaqueLsaHeader; 24 import org.onosproject.ospf.protocol.lsa.OpaqueLsaHeader;
25 import org.onosproject.ospf.protocol.ospfpacket.OspfPacketHeader; 25 import org.onosproject.ospf.protocol.ospfpacket.OspfPacketHeader;
26 -import org.onosproject.ospf.protocol.util.OspfPacketType; 26 +import org.onosproject.ospf.controller.OspfPacketType;
27 import org.onosproject.ospf.protocol.util.OspfParameters; 27 import org.onosproject.ospf.protocol.util.OspfParameters;
28 import org.onosproject.ospf.protocol.util.OspfUtil; 28 import org.onosproject.ospf.protocol.util.OspfUtil;
29 import org.slf4j.Logger; 29 import org.slf4j.Logger;
......
...@@ -22,7 +22,7 @@ import org.onlab.packet.Ip4Address; ...@@ -22,7 +22,7 @@ import org.onlab.packet.Ip4Address;
22 import org.onosproject.ospf.exceptions.OspfErrorType; 22 import org.onosproject.ospf.exceptions.OspfErrorType;
23 import org.onosproject.ospf.exceptions.OspfParseException; 23 import org.onosproject.ospf.exceptions.OspfParseException;
24 import org.onosproject.ospf.protocol.ospfpacket.OspfPacketHeader; 24 import org.onosproject.ospf.protocol.ospfpacket.OspfPacketHeader;
25 -import org.onosproject.ospf.protocol.util.OspfPacketType; 25 +import org.onosproject.ospf.controller.OspfPacketType;
26 import org.onosproject.ospf.protocol.util.OspfUtil; 26 import org.onosproject.ospf.protocol.util.OspfUtil;
27 import org.slf4j.Logger; 27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory; 28 import org.slf4j.LoggerFactory;
......
...@@ -23,7 +23,7 @@ import org.onosproject.ospf.exceptions.OspfParseException; ...@@ -23,7 +23,7 @@ import org.onosproject.ospf.exceptions.OspfParseException;
23 import org.onosproject.ospf.protocol.lsa.LsaHeader; 23 import org.onosproject.ospf.protocol.lsa.LsaHeader;
24 import org.onosproject.ospf.protocol.lsa.OpaqueLsaHeader; 24 import org.onosproject.ospf.protocol.lsa.OpaqueLsaHeader;
25 import org.onosproject.ospf.protocol.ospfpacket.OspfPacketHeader; 25 import org.onosproject.ospf.protocol.ospfpacket.OspfPacketHeader;
26 -import org.onosproject.ospf.protocol.util.OspfPacketType; 26 +import org.onosproject.ospf.controller.OspfPacketType;
27 import org.onosproject.ospf.protocol.util.OspfParameters; 27 import org.onosproject.ospf.protocol.util.OspfParameters;
28 import org.onosproject.ospf.protocol.util.OspfUtil; 28 import org.onosproject.ospf.protocol.util.OspfUtil;
29 import org.slf4j.Logger; 29 import org.slf4j.Logger;
......
...@@ -22,7 +22,7 @@ import org.onlab.packet.Ip4Address; ...@@ -22,7 +22,7 @@ import org.onlab.packet.Ip4Address;
22 import org.onosproject.ospf.exceptions.OspfParseException; 22 import org.onosproject.ospf.exceptions.OspfParseException;
23 import org.onosproject.ospf.protocol.ospfpacket.OspfPacketHeader; 23 import org.onosproject.ospf.protocol.ospfpacket.OspfPacketHeader;
24 import org.onosproject.ospf.protocol.ospfpacket.subtype.LsRequestPacket; 24 import org.onosproject.ospf.protocol.ospfpacket.subtype.LsRequestPacket;
25 -import org.onosproject.ospf.protocol.util.OspfPacketType; 25 +import org.onosproject.ospf.controller.OspfPacketType;
26 import org.onosproject.ospf.protocol.util.OspfUtil; 26 import org.onosproject.ospf.protocol.util.OspfUtil;
27 import org.slf4j.Logger; 27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory; 28 import org.slf4j.LoggerFactory;
......
...@@ -32,7 +32,7 @@ import org.onosproject.ospf.protocol.lsa.types.OpaqueLsa9; ...@@ -32,7 +32,7 @@ import org.onosproject.ospf.protocol.lsa.types.OpaqueLsa9;
32 import org.onosproject.ospf.protocol.lsa.types.RouterLsa; 32 import org.onosproject.ospf.protocol.lsa.types.RouterLsa;
33 import org.onosproject.ospf.protocol.lsa.types.SummaryLsa; 33 import org.onosproject.ospf.protocol.lsa.types.SummaryLsa;
34 import org.onosproject.ospf.protocol.ospfpacket.OspfPacketHeader; 34 import org.onosproject.ospf.protocol.ospfpacket.OspfPacketHeader;
35 -import org.onosproject.ospf.protocol.util.OspfPacketType; 35 +import org.onosproject.ospf.controller.OspfPacketType;
36 import org.onosproject.ospf.protocol.util.OspfParameters; 36 import org.onosproject.ospf.protocol.util.OspfParameters;
37 import org.onosproject.ospf.protocol.util.OspfUtil; 37 import org.onosproject.ospf.protocol.util.OspfUtil;
38 import org.slf4j.Logger; 38 import org.slf4j.Logger;
......
...@@ -25,7 +25,7 @@ import org.onosproject.ospf.protocol.lsa.types.OpaqueLsa11; ...@@ -25,7 +25,7 @@ import org.onosproject.ospf.protocol.lsa.types.OpaqueLsa11;
25 import org.onosproject.ospf.protocol.lsa.types.OpaqueLsa9; 25 import org.onosproject.ospf.protocol.lsa.types.OpaqueLsa9;
26 import org.onosproject.ospf.protocol.lsa.types.RouterLsa; 26 import org.onosproject.ospf.protocol.lsa.types.RouterLsa;
27 import org.onosproject.ospf.protocol.lsa.types.SummaryLsa; 27 import org.onosproject.ospf.protocol.lsa.types.SummaryLsa;
28 -import org.onosproject.ospf.protocol.ospfpacket.OspfMessage; 28 +import org.onosproject.ospf.controller.OspfMessage;
29 import org.onosproject.ospf.protocol.ospfpacket.types.DdPacket; 29 import org.onosproject.ospf.protocol.ospfpacket.types.DdPacket;
30 import org.onosproject.ospf.protocol.ospfpacket.types.HelloPacket; 30 import org.onosproject.ospf.protocol.ospfpacket.types.HelloPacket;
31 import org.onosproject.ospf.protocol.ospfpacket.types.LsAcknowledge; 31 import org.onosproject.ospf.protocol.ospfpacket.types.LsAcknowledge;
......
...@@ -31,20 +31,55 @@ public enum OspfInterfaceState { ...@@ -31,20 +31,55 @@ public enum OspfInterfaceState {
31 private int value; 31 private int value;
32 32
33 /** 33 /**
34 - * Creates an instance of Interface State. 34 + * Creates an instance of interface state.
35 * 35 *
36 - * @param value Interface State value 36 + * @param value Interface state value
37 */ 37 */
38 OspfInterfaceState(int value) { 38 OspfInterfaceState(int value) {
39 this.value = value; 39 this.value = value;
40 } 40 }
41 41
42 /** 42 /**
43 - * Gets value for Interface State. 43 + * Gets value for Interface state.
44 * 44 *
45 - * @return value Interface State 45 + * @return value Interface state
46 */ 46 */
47 public int value() { 47 public int value() {
48 return value; 48 return value;
49 } 49 }
50 +
51 + /**
52 + * Gets interface state.
53 + *
54 + * @return interface state
55 + */
56 + public String interfaceState() {
57 + String state = null;
58 + switch (value) {
59 + case 1:
60 + state = "DOWN";
61 + break;
62 + case 2:
63 + state = "LOOPBACK";
64 + break;
65 + case 3:
66 + state = "WAITING";
67 + break;
68 + case 4:
69 + state = "POINT2POINT";
70 + break;
71 + case 5:
72 + state = "DROTHER";
73 + break;
74 + case 6:
75 + state = "BDR";
76 + break;
77 + case 7:
78 + state = "DR";
79 + break;
80 + default:
81 + break;
82 + }
83 + return state;
84 + }
50 } 85 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -36,10 +36,11 @@ import java.util.StringTokenizer; ...@@ -36,10 +36,11 @@ import java.util.StringTokenizer;
36 * Representation of an OSPF constants and utility methods. 36 * Representation of an OSPF constants and utility methods.
37 */ 37 */
38 public final class OspfUtil { 38 public final class OspfUtil {
39 -
40 public static final int OSPF_VERSION_2 = 2; 39 public static final int OSPF_VERSION_2 = 2;
41 public static final int OSPF_VERSION = OSPF_VERSION_2; 40 public static final int OSPF_VERSION = OSPF_VERSION_2;
42 public static final int PACKET_MINIMUM_LENGTH = 24; 41 public static final int PACKET_MINIMUM_LENGTH = 24;
42 + public static final int METADATA_LEN = 5;
43 + public static final int MINIMUM_FRAME_LEN = 1487;
43 public static final int OSPF_HEADER_LENGTH = 24; 44 public static final int OSPF_HEADER_LENGTH = 24;
44 public static final int LSA_HEADER_LENGTH = 20; 45 public static final int LSA_HEADER_LENGTH = 20;
45 public static final int DD_HEADER_LENGTH = OSPF_HEADER_LENGTH + 8; 46 public static final int DD_HEADER_LENGTH = OSPF_HEADER_LENGTH + 8;
...@@ -52,6 +53,8 @@ public final class OspfUtil { ...@@ -52,6 +53,8 @@ public final class OspfUtil {
52 public static final int LSAPACKET_CHECKSUM_POS2 = 17; 53 public static final int LSAPACKET_CHECKSUM_POS2 = 17;
53 public static final Ip4Address ALL_SPF_ROUTERS = Ip4Address.valueOf("224.0.0.5"); 54 public static final Ip4Address ALL_SPF_ROUTERS = Ip4Address.valueOf("224.0.0.5");
54 public static final Ip4Address ALL_DROUTERS = Ip4Address.valueOf("224.0.0.6"); 55 public static final Ip4Address ALL_DROUTERS = Ip4Address.valueOf("224.0.0.6");
56 + public static final Ip4Address DEFAULTIP = Ip4Address.valueOf("0.0.0.0");
57 + public static final int RETRANSMITINTERVAL = 5;
55 public static final int ONLY_ALL_SPF_ROUTERS = 1; 58 public static final int ONLY_ALL_SPF_ROUTERS = 1;
56 public static final int JOIN_ALL_DROUTERS = 2; 59 public static final int JOIN_ALL_DROUTERS = 2;
57 public static final int INITIALIZE_SET = 1; 60 public static final int INITIALIZE_SET = 1;
...@@ -62,9 +65,16 @@ public final class OspfUtil { ...@@ -62,9 +65,16 @@ public final class OspfUtil {
62 public static final int NOT_MASTER = 0; 65 public static final int NOT_MASTER = 0;
63 public static final int NOT_ASSIGNED = 0; 66 public static final int NOT_ASSIGNED = 0;
64 public static final int FOUR_BYTES = 4; 67 public static final int FOUR_BYTES = 4;
68 + public static final int FIVE_BYTES = 5;
65 public static final int EIGHT_BYTES = 8; 69 public static final int EIGHT_BYTES = 8;
66 public static final int TWELVE_BYTES = 12; 70 public static final int TWELVE_BYTES = 12;
67 public static final int EXTERNAL_DESTINATION_LENGTH = 12; 71 public static final int EXTERNAL_DESTINATION_LENGTH = 12;
72 + public static final String SHOST = "127.0.0.1";
73 + public static final int SPORT = 7000;
74 + public static final int MTU = 1500;
75 + public static final char CONFIG_LENGTH = 1498;
76 + public static final char ROUTER_PRIORITY = 0;
77 + public static final int HELLO_PACKET_OPTIONS = 2;
68 private static final Logger log = 78 private static final Logger log =
69 LoggerFactory.getLogger(OspfUtil.class); 79 LoggerFactory.getLogger(OspfUtil.class);
70 80
...@@ -398,18 +408,21 @@ public final class OspfUtil { ...@@ -398,18 +408,21 @@ public final class OspfUtil {
398 /** 408 /**
399 * Adds metadata to ospf packet like whether to join multi cast group and destination IP. 409 * Adds metadata to ospf packet like whether to join multi cast group and destination IP.
400 * 410 *
411 + * @param interfaceIndex interface index
401 * @param ospfPacket OSPF packet 412 * @param ospfPacket OSPF packet
402 * @param allDroutersValue whether to join multi cast or not 413 * @param allDroutersValue whether to join multi cast or not
403 * @param destinationIp destination ip address 414 * @param destinationIp destination ip address
404 * @return byte array 415 * @return byte array
405 */ 416 */
406 - public static byte[] addMetadata(byte[] ospfPacket, int allDroutersValue, Ip4Address destinationIp) { 417 + public static byte[] addMetadata(int interfaceIndex, byte[] ospfPacket, int allDroutersValue,
418 + Ip4Address destinationIp) {
407 byte[] packet; 419 byte[] packet;
420 + byte[] interfaceIndexByteVal = {(byte) interfaceIndex};
408 byte[] allDroutersByteVal = {(byte) allDroutersValue}; 421 byte[] allDroutersByteVal = {(byte) allDroutersValue};
409 byte[] destIpAsBytes = destinationIp.toOctets(); 422 byte[] destIpAsBytes = destinationIp.toOctets();
410 - byte[] metadata = Bytes.concat(allDroutersByteVal, destIpAsBytes); 423 + byte[] metadata = Bytes.concat(interfaceIndexByteVal, allDroutersByteVal);
411 - 424 + metadata = Bytes.concat(metadata, destIpAsBytes);
412 - packet = Bytes.concat(metadata, ospfPacket); 425 + packet = Bytes.concat(ospfPacket, metadata);
413 426
414 return packet; 427 return packet;
415 } 428 }
......
...@@ -20,6 +20,7 @@ import org.jboss.netty.buffer.ChannelBuffers; ...@@ -20,6 +20,7 @@ import org.jboss.netty.buffer.ChannelBuffers;
20 import org.junit.After; 20 import org.junit.After;
21 import org.junit.Before; 21 import org.junit.Before;
22 import org.junit.Test; 22 import org.junit.Test;
23 +import org.onosproject.ospf.protocol.util.OspfUtil;
23 24
24 import static org.hamcrest.CoreMatchers.is; 25 import static org.hamcrest.CoreMatchers.is;
25 import static org.hamcrest.CoreMatchers.notNullValue; 26 import static org.hamcrest.CoreMatchers.notNullValue;
...@@ -31,17 +32,17 @@ import static org.hamcrest.MatcherAssert.assertThat; ...@@ -31,17 +32,17 @@ import static org.hamcrest.MatcherAssert.assertThat;
31 32
32 public class OspfMessageReaderTest { 33 public class OspfMessageReaderTest {
33 34
34 - private final byte[] packet1 = {1, 1, 1, 1, 2, 1, 0, 44, -64, -88, -86, 8, 35 + private final byte[] packet1 = {2, 1, 0, 44, -64, -88, -86, 8,
35 0, 0, 0, 1, 39, 59, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, 0, 0, 36 0, 0, 0, 1, 39, 59, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, 0, 0,
36 10, 2, 1, 0, 0, 0, 40, -64, -88, -86, 8, 0, 0, 0, 0}; 37 10, 2, 1, 0, 0, 0, 40, -64, -88, -86, 8, 0, 0, 0, 0};
37 - private final byte[] packet2 = {1, 1, 1, 1, 2, 2, 0, 52, -64, -88, -86, 8, 0, 38 + private final byte[] packet2 = {2, 2, 0, 52, -64, -88, -86, 8, 0,
38 0, 0, 1, -96, 82, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, -36, 2, 7, 65, 119, 39 0, 0, 1, -96, 82, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, -36, 2, 7, 65, 119,
39 -87, 126, 0, 23, 2, 1, 10, 10, 10, 10, 10, 10, 10, 10, -128, 0, 0, 6, 40 -87, 126, 0, 23, 2, 1, 10, 10, 10, 10, 10, 10, 10, 10, -128, 0, 0, 6,
40 -69, 26, 0, 36}; 41 -69, 26, 0, 36};
41 - private final byte[] packet3 = {1, 1, 1, 1, 2, 3, 0, 36, -64, -88, -86, 3, 0, 42 + private final byte[] packet3 = {2, 3, 0, 36, -64, -88, -86, 3, 0,
42 0, 0, 1, -67, -57, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -64, -88, 43 0, 0, 1, -67, -57, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -64, -88,
43 -86, 8, -64, -88, -86, 8}; 44 -86, 8, -64, -88, -86, 8};
44 - private final byte[] packet4 = {1, 1, 1, 1, 2, 4, 1, 36, -64, -88, -86, 3, 0, 45 + private final byte[] packet4 = {2, 4, 1, 36, -64, -88, -86, 3, 0,
45 0, 0, 1, 54, 107, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 46 0, 0, 1, 54, 107, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0,
46 2, 2, 1, -64, -88, -86, 3, -64, -88, -86, 3, -128, 0, 47 2, 2, 1, -64, -88, -86, 3, -64, -88, -86, 3, -128, 0,
47 0, 1, 58, -100, 0, 48, 2, 0, 0, 2, -64, -88, -86, 48 0, 1, 58, -100, 0, 48, 2, 0, 0, 2, -64, -88, -86,
...@@ -62,7 +63,7 @@ public class OspfMessageReaderTest { ...@@ -62,7 +63,7 @@ public class OspfMessageReaderTest {
62 0, 0, 0, 0, 0, 0, 0, 3, 2, 5, -64, -88, -84, 0, -64, 63 0, 0, 0, 0, 0, 0, 0, 3, 2, 5, -64, -88, -84, 0, -64,
63 -88, -86, 2, -128, 0, 0, 1, 51, 65, 0, 36, -1, -1, -1, 0, 64 -88, -86, 2, -128, 0, 0, 1, 51, 65, 0, 36, -1, -1, -1, 0,
64 -128, 0, 0, 20, -64, -88, -86, 10, 0, 0, 0, 0}; 65 -128, 0, 0, 20, -64, -88, -86, 10, 0, 0, 0, 0};
65 - private final byte[] packet5 = {1, 1, 1, 1, 2, 5, 0, 44, -64, -88, -86, 8, 0, 0, 66 + private final byte[] packet5 = {2, 5, 0, 44, -64, -88, -86, 8, 0, 0,
66 0, 1, -30, -12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 16, 2, 1, -64, -88, -86, 67 0, 1, -30, -12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 16, 2, 1, -64, -88, -86,
67 2, -64, -88, -86, 2, -128, 0, 0, 1, 74, -114, 0, 48}; 68 2, -64, -88, -86, 2, -128, 0, 0, 1, 74, -114, 0, 48};
68 private OspfMessageReader ospfMessageReader; 69 private OspfMessageReader ospfMessageReader;
...@@ -84,21 +85,39 @@ public class OspfMessageReaderTest { ...@@ -84,21 +85,39 @@ public class OspfMessageReaderTest {
84 */ 85 */
85 @Test 86 @Test
86 public void testReadFromBuffer() throws Exception { 87 public void testReadFromBuffer() throws Exception {
87 - channelBuffer = ChannelBuffers.copiedBuffer(packet1); 88 + channelBuffer = ChannelBuffers.copiedBuffer(framePacket(packet1));
88 ospfMessageReader.readFromBuffer(channelBuffer); 89 ospfMessageReader.readFromBuffer(channelBuffer);
89 90
90 - channelBuffer = ChannelBuffers.copiedBuffer(packet2); 91 + channelBuffer = ChannelBuffers.copiedBuffer(framePacket(packet2));
91 ospfMessageReader.readFromBuffer(channelBuffer); 92 ospfMessageReader.readFromBuffer(channelBuffer);
92 93
93 - channelBuffer = ChannelBuffers.copiedBuffer(packet3); 94 + channelBuffer = ChannelBuffers.copiedBuffer(framePacket(packet3));
94 ospfMessageReader.readFromBuffer(channelBuffer); 95 ospfMessageReader.readFromBuffer(channelBuffer);
95 96
96 - channelBuffer = ChannelBuffers.copiedBuffer(packet4); 97 + channelBuffer = ChannelBuffers.copiedBuffer(framePacket(packet4));
97 ospfMessageReader.readFromBuffer(channelBuffer); 98 ospfMessageReader.readFromBuffer(channelBuffer);
98 99
99 - channelBuffer = ChannelBuffers.copiedBuffer(packet5); 100 + channelBuffer = ChannelBuffers.copiedBuffer(framePacket(packet5));
100 ospfMessageReader.readFromBuffer(channelBuffer); 101 ospfMessageReader.readFromBuffer(channelBuffer);
101 assertThat(ospfMessageReader, is(notNullValue())); 102 assertThat(ospfMessageReader, is(notNullValue()));
103 + }
102 104
105 + /**
106 + * Frames the packet to min frame length.
107 + *
108 + * @param ospfPacket OSPF packet
109 + * @return OSPF packet as byte array
110 + */
111 + private byte[] framePacket(byte[] ospfPacket) {
112 + //Set the length of the packet
113 + //Get the total length of the packet
114 + int length = ospfPacket.length;
115 + //PDU_LENGTH + 1 byte for interface index
116 + if (length < OspfUtil.MINIMUM_FRAME_LEN) {
117 + byte[] bytes = new byte[OspfUtil.MINIMUM_FRAME_LEN + 5];
118 + System.arraycopy(ospfPacket, 0, bytes, 0, length);
119 + return bytes;
120 + }
121 + return ospfPacket;
103 } 122 }
104 } 123 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -57,10 +57,10 @@ public class OspfMessageWriterTest { ...@@ -57,10 +57,10 @@ public class OspfMessageWriterTest {
57 } 57 }
58 58
59 /** 59 /**
60 - * Tests writeToBuffer() method. 60 + * Tests getMessage() method.
61 */ 61 */
62 @Test 62 @Test
63 - public void testWriteToBuffer() throws Exception { 63 + public void testGetMessage() throws Exception {
64 helloPacket = new HelloPacket(); 64 helloPacket = new HelloPacket();
65 helloPacket.setAuthType(1); 65 helloPacket.setAuthType(1);
66 helloPacket.setOspftype(1); 66 helloPacket.setOspftype(1);
...@@ -79,12 +79,12 @@ public class OspfMessageWriterTest { ...@@ -79,12 +79,12 @@ public class OspfMessageWriterTest {
79 helloPacket.setBdr(Ip4Address.valueOf("2.2.2.2")); 79 helloPacket.setBdr(Ip4Address.valueOf("2.2.2.2"));
80 helloPacket.addNeighbor(Ip4Address.valueOf("8.8.8.8")); 80 helloPacket.addNeighbor(Ip4Address.valueOf("8.8.8.8"));
81 helloPacket.setDestinationIp(Ip4Address.valueOf("5.5.5.5")); 81 helloPacket.setDestinationIp(Ip4Address.valueOf("5.5.5.5"));
82 - ospfMessageWriter.writeToBuffer(helloPacket, 7, 1); 82 + ospfMessageWriter.getMessage(helloPacket, 7, 1);
83 assertThat(ospfMessageWriter, is(notNullValue())); 83 assertThat(ospfMessageWriter, is(notNullValue()));
84 } 84 }
85 85
86 @Test(expected = Exception.class) 86 @Test(expected = Exception.class)
87 - public void testWriteToBuffer1() throws Exception { 87 + public void testGetMessage1() throws Exception {
88 88
89 ddPacket = new DdPacket(); 89 ddPacket = new DdPacket();
90 ddPacket.setAuthType(1); 90 ddPacket.setAuthType(1);
...@@ -95,12 +95,12 @@ public class OspfMessageWriterTest { ...@@ -95,12 +95,12 @@ public class OspfMessageWriterTest {
95 ddPacket.setAuthentication(2); 95 ddPacket.setAuthentication(2);
96 ddPacket.setOspfPacLength(48); 96 ddPacket.setOspfPacLength(48);
97 ddPacket.setOspfVer(2); 97 ddPacket.setOspfVer(2);
98 - ospfMessageWriter.writeToBuffer(ddPacket, 1, 1); 98 + ospfMessageWriter.getMessage(ddPacket, 1, 1);
99 assertThat(ospfMessageWriter, is(notNullValue())); 99 assertThat(ospfMessageWriter, is(notNullValue()));
100 } 100 }
101 101
102 @Test(expected = Exception.class) 102 @Test(expected = Exception.class)
103 - public void testWriteToBuffer2() throws Exception { 103 + public void testGetMessage2() throws Exception {
104 104
105 lsAck = new LsAcknowledge(); 105 lsAck = new LsAcknowledge();
106 lsAck.setAuthType(1); 106 lsAck.setAuthType(1);
...@@ -111,12 +111,12 @@ public class OspfMessageWriterTest { ...@@ -111,12 +111,12 @@ public class OspfMessageWriterTest {
111 lsAck.setAuthentication(2); 111 lsAck.setAuthentication(2);
112 lsAck.setOspfPacLength(48); 112 lsAck.setOspfPacLength(48);
113 lsAck.setOspfVer(2); 113 lsAck.setOspfVer(2);
114 - ospfMessageWriter.writeToBuffer(lsAck, 1, 1); 114 + ospfMessageWriter.getMessage(lsAck, 1, 1);
115 assertThat(ospfMessageWriter, is(notNullValue())); 115 assertThat(ospfMessageWriter, is(notNullValue()));
116 } 116 }
117 117
118 @Test(expected = Exception.class) 118 @Test(expected = Exception.class)
119 - public void testWriteToBuffer3() throws Exception { 119 + public void testGetMessage3() throws Exception {
120 lsReq = new LsRequest(); 120 lsReq = new LsRequest();
121 lsReq.setAuthType(1); 121 lsReq.setAuthType(1);
122 lsReq.setOspftype(3); 122 lsReq.setOspftype(3);
...@@ -126,12 +126,15 @@ public class OspfMessageWriterTest { ...@@ -126,12 +126,15 @@ public class OspfMessageWriterTest {
126 lsReq.setAuthentication(2); 126 lsReq.setAuthentication(2);
127 lsReq.setOspfPacLength(48); 127 lsReq.setOspfPacLength(48);
128 lsReq.setOspfVer(2); 128 lsReq.setOspfVer(2);
129 - ospfMessageWriter.writeToBuffer(lsReq, 1, 1); 129 + ospfMessageWriter.getMessage(lsReq, 1, 1);
130 assertThat(ospfMessageWriter, is(notNullValue())); 130 assertThat(ospfMessageWriter, is(notNullValue()));
131 } 131 }
132 132
133 + /**
134 + * Tests getMessage() method.
135 + */
133 @Test(expected = Exception.class) 136 @Test(expected = Exception.class)
134 - public void testWriteToBuffer4() throws Exception { 137 + public void testGetMessage4() throws Exception {
135 lsUpdate = new LsUpdate(); 138 lsUpdate = new LsUpdate();
136 lsUpdate.setAuthType(1); 139 lsUpdate.setAuthType(1);
137 lsUpdate.setOspftype(3); 140 lsUpdate.setOspftype(3);
...@@ -141,15 +144,15 @@ public class OspfMessageWriterTest { ...@@ -141,15 +144,15 @@ public class OspfMessageWriterTest {
141 lsUpdate.setAuthentication(2); 144 lsUpdate.setAuthentication(2);
142 lsUpdate.setOspfPacLength(48); 145 lsUpdate.setOspfPacLength(48);
143 lsUpdate.setOspfVer(2); 146 lsUpdate.setOspfVer(2);
144 - ospfMessageWriter.writeToBuffer(lsUpdate, 1, 1); 147 + ospfMessageWriter.getMessage(lsUpdate, 1, 1);
145 assertThat(ospfMessageWriter, is(notNullValue())); 148 assertThat(ospfMessageWriter, is(notNullValue()));
146 } 149 }
147 150
148 /** 151 /**
149 - * Tests writeToBuffer() method. 152 + * Tests getMessage() method.
150 */ 153 */
151 @Test(expected = Exception.class) 154 @Test(expected = Exception.class)
152 - public void testWriteToBuffer5() throws Exception { 155 + public void testGetMessage5() throws Exception {
153 lsAck = new LsAcknowledge(); 156 lsAck = new LsAcknowledge();
154 lsAck.setAuthType(1); 157 lsAck.setAuthType(1);
155 lsAck.setOspftype(5); 158 lsAck.setOspftype(5);
...@@ -159,6 +162,6 @@ public class OspfMessageWriterTest { ...@@ -159,6 +162,6 @@ public class OspfMessageWriterTest {
159 lsAck.setAuthentication(2); 162 lsAck.setAuthentication(2);
160 lsAck.setOspfPacLength(48); 163 lsAck.setOspfPacLength(48);
161 lsAck.setOspfVer(2); 164 lsAck.setOspfVer(2);
162 - ospfMessageWriter.writeToBuffer(lsAck, 1, 1); 165 + ospfMessageWriter.getMessage(lsAck, 1, 1);
163 } 166 }
164 } 167 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -22,10 +22,10 @@ import org.junit.Assert; ...@@ -22,10 +22,10 @@ import org.junit.Assert;
22 import org.junit.Before; 22 import org.junit.Before;
23 import org.junit.Test; 23 import org.junit.Test;
24 import org.onlab.packet.Ip4Address; 24 import org.onlab.packet.Ip4Address;
25 +import org.onosproject.ospf.controller.OspfPacketType;
25 import org.onosproject.ospf.protocol.lsa.LsaHeader; 26 import org.onosproject.ospf.protocol.lsa.LsaHeader;
26 import org.onosproject.ospf.protocol.lsa.OpaqueLsaHeader; 27 import org.onosproject.ospf.protocol.lsa.OpaqueLsaHeader;
27 import org.onosproject.ospf.protocol.ospfpacket.OspfPacketHeader; 28 import org.onosproject.ospf.protocol.ospfpacket.OspfPacketHeader;
28 -import org.onosproject.ospf.protocol.util.OspfPacketType;
29 29
30 import java.util.List; 30 import java.util.List;
31 import java.util.Vector; 31 import java.util.Vector;
......
...@@ -21,8 +21,8 @@ import org.junit.After; ...@@ -21,8 +21,8 @@ import org.junit.After;
21 import org.junit.Before; 21 import org.junit.Before;
22 import org.junit.Test; 22 import org.junit.Test;
23 import org.onlab.packet.Ip4Address; 23 import org.onlab.packet.Ip4Address;
24 +import org.onosproject.ospf.controller.OspfPacketType;
24 import org.onosproject.ospf.protocol.ospfpacket.OspfPacketHeader; 25 import org.onosproject.ospf.protocol.ospfpacket.OspfPacketHeader;
25 -import org.onosproject.ospf.protocol.util.OspfPacketType;
26 26
27 import java.util.Vector; 27 import java.util.Vector;
28 28
......
...@@ -22,10 +22,10 @@ import org.junit.After; ...@@ -22,10 +22,10 @@ import org.junit.After;
22 import org.junit.Before; 22 import org.junit.Before;
23 import org.junit.Test; 23 import org.junit.Test;
24 import org.onlab.packet.Ip4Address; 24 import org.onlab.packet.Ip4Address;
25 +import org.onosproject.ospf.controller.OspfPacketType;
25 import org.onosproject.ospf.protocol.lsa.LsaHeader; 26 import org.onosproject.ospf.protocol.lsa.LsaHeader;
26 import org.onosproject.ospf.protocol.lsa.OpaqueLsaHeader; 27 import org.onosproject.ospf.protocol.lsa.OpaqueLsaHeader;
27 import org.onosproject.ospf.protocol.ospfpacket.OspfPacketHeader; 28 import org.onosproject.ospf.protocol.ospfpacket.OspfPacketHeader;
28 -import org.onosproject.ospf.protocol.util.OspfPacketType;
29 29
30 import java.util.List; 30 import java.util.List;
31 31
......
...@@ -21,9 +21,9 @@ import org.junit.After; ...@@ -21,9 +21,9 @@ import org.junit.After;
21 import org.junit.Before; 21 import org.junit.Before;
22 import org.junit.Test; 22 import org.junit.Test;
23 import org.onlab.packet.Ip4Address; 23 import org.onlab.packet.Ip4Address;
24 +import org.onosproject.ospf.controller.OspfPacketType;
24 import org.onosproject.ospf.protocol.ospfpacket.OspfPacketHeader; 25 import org.onosproject.ospf.protocol.ospfpacket.OspfPacketHeader;
25 import org.onosproject.ospf.protocol.ospfpacket.subtype.LsRequestPacket; 26 import org.onosproject.ospf.protocol.ospfpacket.subtype.LsRequestPacket;
26 -import org.onosproject.ospf.protocol.util.OspfPacketType;
27 27
28 import java.net.UnknownHostException; 28 import java.net.UnknownHostException;
29 import java.util.List; 29 import java.util.List;
......
...@@ -22,6 +22,7 @@ import org.junit.Before; ...@@ -22,6 +22,7 @@ import org.junit.Before;
22 import org.junit.Test; 22 import org.junit.Test;
23 import org.onlab.packet.Ip4Address; 23 import org.onlab.packet.Ip4Address;
24 import org.onosproject.ospf.controller.OspfLsa; 24 import org.onosproject.ospf.controller.OspfLsa;
25 +import org.onosproject.ospf.controller.OspfPacketType;
25 import org.onosproject.ospf.protocol.lsa.LsaHeader; 26 import org.onosproject.ospf.protocol.lsa.LsaHeader;
26 import org.onosproject.ospf.protocol.lsa.OpaqueLsaHeader; 27 import org.onosproject.ospf.protocol.lsa.OpaqueLsaHeader;
27 import org.onosproject.ospf.protocol.lsa.types.AsbrSummaryLsa; 28 import org.onosproject.ospf.protocol.lsa.types.AsbrSummaryLsa;
...@@ -33,7 +34,6 @@ import org.onosproject.ospf.protocol.lsa.types.OpaqueLsa9; ...@@ -33,7 +34,6 @@ import org.onosproject.ospf.protocol.lsa.types.OpaqueLsa9;
33 import org.onosproject.ospf.protocol.lsa.types.RouterLsa; 34 import org.onosproject.ospf.protocol.lsa.types.RouterLsa;
34 import org.onosproject.ospf.protocol.lsa.types.SummaryLsa; 35 import org.onosproject.ospf.protocol.lsa.types.SummaryLsa;
35 import org.onosproject.ospf.protocol.ospfpacket.OspfPacketHeader; 36 import org.onosproject.ospf.protocol.ospfpacket.OspfPacketHeader;
36 -import org.onosproject.ospf.protocol.util.OspfPacketType;
37 37
38 import java.util.List; 38 import java.util.List;
39 import java.util.Vector; 39 import java.util.Vector;
......
...@@ -229,7 +229,7 @@ public class OspfUtilTest { ...@@ -229,7 +229,7 @@ public class OspfUtilTest {
229 */ 229 */
230 @Test 230 @Test
231 public void testAddMetadata() throws Exception { 231 public void testAddMetadata() throws Exception {
232 - result1 = OspfUtil.addMetadata(packet, 123, Ip4Address.valueOf("1.1.1.1")); 232 + result1 = OspfUtil.addMetadata(2, packet, 1, Ip4Address.valueOf("1.1.1.1"));
233 assertThat(result1, is(notNullValue())); 233 assertThat(result1, is(notNullValue()));
234 } 234 }
235 235
...@@ -251,7 +251,7 @@ public class OspfUtilTest { ...@@ -251,7 +251,7 @@ public class OspfUtilTest {
251 */ 251 */
252 @Test 252 @Test
253 public void testAddMetaData() throws Exception { 253 public void testAddMetaData() throws Exception {
254 - result1 = OspfUtil.addMetadata(packet, 1, Ip4Address.valueOf("2.2.2.2")); 254 + result1 = OspfUtil.addMetadata(2, packet, 1, Ip4Address.valueOf("2.2.2.2"));
255 assertThat(result1, is(notNullValue())); 255 assertThat(result1, is(notNullValue()));
256 } 256 }
257 257
......