Committed by
Gerrit Code Review
[Emu][ONOS-2593, ONOS-2594] BGP SBI controller and session handler
Change-Id: Ia95717ff173b2e3e1198bdd0fafef7cb0aa8f734
Showing
20 changed files
with
1526 additions
and
96 deletions
... | @@ -47,288 +47,251 @@ public interface BGPCfg { | ... | @@ -47,288 +47,251 @@ public interface BGPCfg { |
47 | /** | 47 | /** |
48 | * Returns the status of the configuration based on this state certain operations like connection is handled. | 48 | * Returns the status of the configuration based on this state certain operations like connection is handled. |
49 | * | 49 | * |
50 | - * @return | 50 | + * @return State of the configuration |
51 | - * State of the configuration | ||
52 | */ | 51 | */ |
53 | State getState(); | 52 | State getState(); |
54 | 53 | ||
55 | /** | 54 | /** |
56 | * To set the current state of the configuration. | 55 | * To set the current state of the configuration. |
57 | * | 56 | * |
58 | - * @param state | 57 | + * @param state Configuration State enum |
59 | - * Configuration State enum | ||
60 | */ | 58 | */ |
61 | void setState(State state); | 59 | void setState(State state); |
62 | 60 | ||
63 | /** | 61 | /** |
64 | * Get the status of the link state support for this BGP speaker. | 62 | * Get the status of the link state support for this BGP speaker. |
65 | * | 63 | * |
66 | - * @return | 64 | + * @return true if the link state is supported else false |
67 | - * true if the link state is supported else false | ||
68 | */ | 65 | */ |
69 | boolean getLsCapability(); | 66 | boolean getLsCapability(); |
70 | 67 | ||
71 | /** | 68 | /** |
72 | * Set the link state support to this BGP speaker. | 69 | * Set the link state support to this BGP speaker. |
73 | * | 70 | * |
74 | - * @param lscapability | 71 | + * @param lscapability true value if link state is supported else false |
75 | - * true value if link state is supported else false | ||
76 | */ | 72 | */ |
77 | void setLsCapability(boolean lscapability); | 73 | void setLsCapability(boolean lscapability); |
78 | 74 | ||
79 | /** | 75 | /** |
80 | * Get the status of the 32 bit AS support for this BGP speaker. | 76 | * Get the status of the 32 bit AS support for this BGP speaker. |
81 | * | 77 | * |
82 | - * @return | 78 | + * @return true if the 32 bit AS number is supported else false |
83 | - * true if the 32 bit AS number is supported else false | ||
84 | */ | 79 | */ |
85 | boolean getLargeASCapability(); | 80 | boolean getLargeASCapability(); |
86 | 81 | ||
87 | /** | 82 | /** |
88 | * Set the 32 bit AS support capability to this BGP speaker. | 83 | * Set the 32 bit AS support capability to this BGP speaker. |
89 | * | 84 | * |
90 | - * @param largeAs | 85 | + * @param largeAs true value if the 32 bit AS is supported else false |
91 | - * true value if the 32 bit AS is supported else false | ||
92 | */ | 86 | */ |
93 | void setLargeASCapability(boolean largeAs); | 87 | void setLargeASCapability(boolean largeAs); |
94 | 88 | ||
95 | /** | 89 | /** |
96 | * Set the AS number to which this BGP speaker belongs. | 90 | * Set the AS number to which this BGP speaker belongs. |
97 | * | 91 | * |
98 | - * @param localAs | 92 | + * @param localAs 16 or 32 bit AS number, length is dependent on the capability |
99 | - * 16 or 32 bit AS number, length is dependent on the capability | ||
100 | */ | 93 | */ |
101 | void setAsNumber(int localAs); | 94 | void setAsNumber(int localAs); |
102 | 95 | ||
103 | /** | 96 | /** |
104 | * Get the AS number to which this BGP speaker belongs. | 97 | * Get the AS number to which this BGP speaker belongs. |
105 | * | 98 | * |
106 | - * @return | 99 | + * @return 16 or 32 bit AS number, length is dependent on the capability |
107 | - * 16 or 32 bit AS number, length is dependent on the capability | ||
108 | */ | 100 | */ |
109 | int getAsNumber(); | 101 | int getAsNumber(); |
110 | 102 | ||
111 | /** | 103 | /** |
112 | * Get the connection retry count number. | 104 | * Get the connection retry count number. |
113 | * | 105 | * |
114 | - * @return | 106 | + * @return connection retry count if there is a connection error |
115 | - * connection retry count if there is a connection error | ||
116 | */ | 107 | */ |
117 | int getMaxConnRetryCount(); | 108 | int getMaxConnRetryCount(); |
118 | 109 | ||
119 | /** | 110 | /** |
120 | * Set the connection retry count. | 111 | * Set the connection retry count. |
121 | * | 112 | * |
122 | - * @param retryCount | 113 | + * @param retryCount number of times to try to connect if there is any error |
123 | - * number of times to try to connect if there is any error | ||
124 | */ | 114 | */ |
125 | void setMaxConnRetryCout(int retryCount); | 115 | void setMaxConnRetryCout(int retryCount); |
126 | 116 | ||
127 | /** | 117 | /** |
128 | * Get the connection retry time in seconds. | 118 | * Get the connection retry time in seconds. |
129 | * | 119 | * |
130 | - * @return | 120 | + * @return connection retry time in seconds |
131 | - * connection retry time in seconds | ||
132 | */ | 121 | */ |
133 | int getMaxConnRetryTime(); | 122 | int getMaxConnRetryTime(); |
134 | 123 | ||
135 | /** | 124 | /** |
136 | * Set the connection retry time in seconds. | 125 | * Set the connection retry time in seconds. |
137 | * | 126 | * |
138 | - * @param retryTime | 127 | + * @param retryTime connection retry times in seconds |
139 | - * connection retry times in seconds | ||
140 | */ | 128 | */ |
141 | void setMaxConnRetryTime(int retryTime); | 129 | void setMaxConnRetryTime(int retryTime); |
142 | 130 | ||
143 | /** | 131 | /** |
144 | * Set the keep alive timer for the connection. | 132 | * Set the keep alive timer for the connection. |
145 | * | 133 | * |
146 | - * @param holdTime | 134 | + * @param holdTime connection hold timer in seconds |
147 | - * connection hold timer in seconds | ||
148 | */ | 135 | */ |
149 | void setHoldTime(short holdTime); | 136 | void setHoldTime(short holdTime); |
150 | 137 | ||
151 | /** | 138 | /** |
152 | * Returns the connection hold timer in seconds. | 139 | * Returns the connection hold timer in seconds. |
153 | * | 140 | * |
154 | - * @return | 141 | + * @return connection hold timer in seconds |
155 | - * connection hold timer in seconds | ||
156 | */ | 142 | */ |
157 | short getHoldTime(); | 143 | short getHoldTime(); |
158 | 144 | ||
159 | /** | 145 | /** |
160 | * Returns the maximum number of session supported. | 146 | * Returns the maximum number of session supported. |
161 | * | 147 | * |
162 | - * @return | 148 | + * @return maximum number of session supported |
163 | - * maximum number of session supported | ||
164 | */ | 149 | */ |
165 | int getMaxSession(); | 150 | int getMaxSession(); |
166 | 151 | ||
167 | /** | 152 | /** |
168 | * Set the maximum number of sessions to support. | 153 | * Set the maximum number of sessions to support. |
169 | * | 154 | * |
170 | - * @param maxsession | 155 | + * @param maxsession maximum number of session |
171 | - * maximum number of session | ||
172 | */ | 156 | */ |
173 | void setMaxSession(int maxsession); | 157 | void setMaxSession(int maxsession); |
174 | 158 | ||
175 | /** | 159 | /** |
176 | * Returns the Router ID of this BGP speaker. | 160 | * Returns the Router ID of this BGP speaker. |
177 | * | 161 | * |
178 | - * @return | 162 | + * @return IP address in string format |
179 | - * IP address in string format | ||
180 | */ | 163 | */ |
181 | String getRouterId(); | 164 | String getRouterId(); |
182 | 165 | ||
183 | /** | 166 | /** |
184 | * Set the Router ID of this BGP speaker. | 167 | * Set the Router ID of this BGP speaker. |
185 | * | 168 | * |
186 | - * @param routerid | 169 | + * @param routerid IP address in string format |
187 | - * IP address in string format | ||
188 | */ | 170 | */ |
189 | void setRouterId(String routerid); | 171 | void setRouterId(String routerid); |
190 | 172 | ||
191 | /** | 173 | /** |
192 | * Add the BGP peer IP address and the AS number to which it belongs. | 174 | * Add the BGP peer IP address and the AS number to which it belongs. |
193 | * | 175 | * |
194 | - * @param routerid | 176 | + * @param routerid IP address in string format |
195 | - * IP address in string format | 177 | + * @param remoteAs AS number to which it belongs |
196 | - * @param remoteAs | 178 | + * |
197 | - * AS number to which it belongs | 179 | + * @return true if added successfully else false |
198 | - * @return | ||
199 | - * true if added successfully else false | ||
200 | */ | 180 | */ |
201 | boolean addPeer(String routerid, int remoteAs); | 181 | boolean addPeer(String routerid, int remoteAs); |
202 | 182 | ||
203 | /** | 183 | /** |
204 | * Add the BGP peer IP address and the keep alive time. | 184 | * Add the BGP peer IP address and the keep alive time. |
205 | * | 185 | * |
206 | - * @param routerid | 186 | + * @param routerid IP address in string format |
207 | - * IP address in string format | 187 | + * @param holdTime keep alive time for the connection |
208 | - * @param holdTime | 188 | + * |
209 | - * keep alive time for the connection | 189 | + * @return true if added successfully else false |
210 | - * @return | ||
211 | - * true if added successfully else false | ||
212 | */ | 190 | */ |
213 | boolean addPeer(String routerid, short holdTime); | 191 | boolean addPeer(String routerid, short holdTime); |
214 | 192 | ||
215 | /** | 193 | /** |
216 | * Add the BGP peer IP address, the AS number to which it belongs and keep alive time. | 194 | * Add the BGP peer IP address, the AS number to which it belongs and keep alive time. |
217 | * | 195 | * |
218 | - * @param routerid | 196 | + * @param routerid IP address in string format |
219 | - * IP address in string format | 197 | + * @param remoteAs AS number to which it belongs |
220 | - * @param remoteAs | 198 | + * @param holdTime keep alive time for the connection |
221 | - * AS number to which it belongs | 199 | + * |
222 | - * @param holdTime | 200 | + * @return true if added successfully else false |
223 | - * keep alive time for the connection | ||
224 | - * @return | ||
225 | - * true if added successfully else false | ||
226 | */ | 201 | */ |
227 | boolean addPeer(String routerid, int remoteAs, short holdTime); | 202 | boolean addPeer(String routerid, int remoteAs, short holdTime); |
228 | 203 | ||
229 | /** | 204 | /** |
230 | * Remove the BGP peer with this IP address. | 205 | * Remove the BGP peer with this IP address. |
231 | * | 206 | * |
232 | - * @param routerid | 207 | + * @param routerid router IP address |
233 | - * router IP address | 208 | + * |
234 | - * @return | 209 | + * @return true if removed successfully else false |
235 | - * true if removed successfully else false | ||
236 | */ | 210 | */ |
237 | boolean removePeer(String routerid); | 211 | boolean removePeer(String routerid); |
238 | 212 | ||
239 | /** | 213 | /** |
240 | * Connect to BGP peer with this IP address. | 214 | * Connect to BGP peer with this IP address. |
241 | * | 215 | * |
242 | - * @param routerid | 216 | + * @param routerid router IP address |
243 | - * router IP address | 217 | + * |
244 | - * @return | 218 | + * @return true of the configuration is found and able to connect else false |
245 | - * true of the configuration is found and able to connect else false | ||
246 | */ | 219 | */ |
247 | boolean connectPeer(String routerid); | 220 | boolean connectPeer(String routerid); |
248 | 221 | ||
249 | /** | 222 | /** |
250 | * Disconnect this BGP peer with this IP address. | 223 | * Disconnect this BGP peer with this IP address. |
251 | * | 224 | * |
252 | - * @param routerid | 225 | + * @param routerid router IP address in string format |
253 | - * router IP address in string format | 226 | + * |
254 | - * @return | 227 | + * @return true if the configuration is found and able to disconnect else false |
255 | - * true if the configuration is found and able to disconnect else false | ||
256 | */ | 228 | */ |
257 | boolean disconnectPeer(String routerid); | 229 | boolean disconnectPeer(String routerid); |
258 | 230 | ||
259 | /** | 231 | /** |
260 | * Returns the peer tree information. | 232 | * Returns the peer tree information. |
261 | * | 233 | * |
262 | - * @return | 234 | + * @return return the tree map with IP as key and BGPPeerCfg as object |
263 | - * return the tree map with IP as key and BGPPeerCfg as object | ||
264 | */ | 235 | */ |
265 | TreeMap<String, BGPPeerCfg> displayPeers(); | 236 | TreeMap<String, BGPPeerCfg> displayPeers(); |
266 | 237 | ||
267 | /** | 238 | /** |
268 | * Return the BGP Peer information with this matching IP. | 239 | * Return the BGP Peer information with this matching IP. |
269 | * | 240 | * |
270 | - * @param routerid | 241 | + * @param routerid router IP address in string format |
271 | - * router IP address in string format | 242 | + * |
272 | - * @return | 243 | + * @return BGPPeerCfg object |
273 | - * BGPPeerCfg object | ||
274 | */ | 244 | */ |
275 | BGPPeerCfg displayPeers(String routerid); | 245 | BGPPeerCfg displayPeers(String routerid); |
276 | 246 | ||
277 | /** | 247 | /** |
278 | * Check if this BGP peer is configured. | 248 | * Check if this BGP peer is configured. |
279 | * | 249 | * |
280 | - * @param routerid | 250 | + * @param routerid router IP address in string format |
281 | - * router IP address in string format | 251 | + * |
282 | - * @return | 252 | + * @return true if configured exists else false |
283 | - * true if configured exists else false | ||
284 | */ | 253 | */ |
285 | boolean isPeerConfigured(String routerid); | 254 | boolean isPeerConfigured(String routerid); |
286 | 255 | ||
287 | /** | 256 | /** |
288 | * Check if this BGP speaker is having connection with the peer. | 257 | * Check if this BGP speaker is having connection with the peer. |
289 | * | 258 | * |
290 | - * @param routerid | 259 | + * @param routerid router IP address in string format |
291 | - * router IP address in string format | 260 | + * |
292 | - * @return | 261 | + * @return true if the connection exists else false |
293 | - * true if the connection exists else false | ||
294 | */ | 262 | */ |
295 | boolean isPeerConnected(String routerid); | 263 | boolean isPeerConnected(String routerid); |
296 | 264 | ||
297 | /** | 265 | /** |
298 | * Return the peer tree map. | 266 | * Return the peer tree map. |
299 | * | 267 | * |
300 | - * @return | 268 | + * @return return the tree map with IP as key and BGPPeerCfg as object |
301 | - * return the tree map with IP as key and BGPPeerCfg as object | ||
302 | */ | 269 | */ |
303 | TreeMap<String, BGPPeerCfg> getPeerTree(); | 270 | TreeMap<String, BGPPeerCfg> getPeerTree(); |
304 | 271 | ||
305 | /** | 272 | /** |
306 | * Set the current connection state information. | 273 | * Set the current connection state information. |
307 | * | 274 | * |
308 | - * @param routerid | 275 | + * @param routerid router IP address in string format |
309 | - * router IP address in string format | 276 | + * @param state state information |
310 | - * @param state | ||
311 | - * state information | ||
312 | */ | 277 | */ |
313 | void setPeerConnState(String routerid, BGPPeerCfg.State state); | 278 | void setPeerConnState(String routerid, BGPPeerCfg.State state); |
314 | 279 | ||
315 | /** | 280 | /** |
316 | * Check if the peer can be connected or not. | 281 | * Check if the peer can be connected or not. |
317 | * | 282 | * |
318 | - * @param routerid | 283 | + * @param routerid router IP address in string format |
319 | - * router IP address in string format | 284 | + * |
320 | - * @return | 285 | + * @return true if the peer can be connected else false |
321 | - * true if the peer can be connected else false | ||
322 | */ | 286 | */ |
323 | boolean isPeerConnectable(String routerid); | 287 | boolean isPeerConnectable(String routerid); |
324 | 288 | ||
325 | /** | 289 | /** |
326 | * Get the current peer connection state information. | 290 | * Get the current peer connection state information. |
327 | * | 291 | * |
328 | - * @param routerid | 292 | + * @param routerid router IP address in string format |
329 | - * router IP address in string format | 293 | + * |
330 | - * @return | 294 | + * @return state information |
331 | - * state information | ||
332 | */ | 295 | */ |
333 | BGPPeerCfg.State getPeerConnState(String routerid); | 296 | BGPPeerCfg.State getPeerConnState(String routerid); |
334 | } | 297 | } | ... | ... |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.bgp.controller; | ||
18 | + | ||
19 | +import org.onosproject.bgpio.protocol.BGPMessage; | ||
20 | + | ||
21 | +/** | ||
22 | + * Abstraction of an BGP controller. Serves as a one stop shop for obtaining BGP devices and (un)register listeners | ||
23 | + * on bgp events | ||
24 | + */ | ||
25 | +public interface BGPController { | ||
26 | + | ||
27 | + /** | ||
28 | + * Send a message to a particular bgp peer. | ||
29 | + * | ||
30 | + * @param bgpId the id of the peer to send message. | ||
31 | + * @param msg the message to send | ||
32 | + */ | ||
33 | + void writeMsg(BGPId bgpId, BGPMessage msg); | ||
34 | + | ||
35 | + /** | ||
36 | + * Process a message and notify the appropriate listeners. | ||
37 | + * | ||
38 | + * @param bgpId id of the peer the message arrived on | ||
39 | + * @param msg the message to process. | ||
40 | + */ | ||
41 | + void processBGPPacket(BGPId bgpId, BGPMessage msg); | ||
42 | + | ||
43 | + /** | ||
44 | + * Get the BGPConfig class to the caller. | ||
45 | + * | ||
46 | + * @return configuration object | ||
47 | + */ | ||
48 | + BGPCfg getConfig(); | ||
49 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.bgp.controller; | ||
18 | + | ||
19 | +import org.onlab.packet.IpAddress; | ||
20 | +import java.net.URI; | ||
21 | +import java.net.URISyntaxException; | ||
22 | +import java.util.Objects; | ||
23 | + | ||
24 | +import static com.google.common.base.Preconditions.checkArgument; | ||
25 | + | ||
26 | +/** | ||
27 | + * The class representing a network peer bgp ip. | ||
28 | + * This class is immutable. | ||
29 | + */ | ||
30 | +public final class BGPId { | ||
31 | + | ||
32 | + private static final String SCHEME = "bgp"; | ||
33 | + private static final long UNKNOWN = 0; | ||
34 | + private final IpAddress ipAddress; | ||
35 | + | ||
36 | + /** | ||
37 | + * Private constructor. | ||
38 | + */ | ||
39 | + private BGPId(IpAddress ipAddress) { | ||
40 | + this.ipAddress = ipAddress; | ||
41 | + } | ||
42 | + | ||
43 | + /** | ||
44 | + * Create a BGPId from ip address. | ||
45 | + * | ||
46 | + * @param ipAddress IP address | ||
47 | + * @return object of BGPId | ||
48 | + */ | ||
49 | + public static BGPId bgpId(IpAddress ipAddress) { | ||
50 | + return new BGPId(ipAddress); | ||
51 | + } | ||
52 | + | ||
53 | + /** | ||
54 | + * Returns the ip address. | ||
55 | + * | ||
56 | + * @return ipAddress | ||
57 | + */ | ||
58 | + public IpAddress ipAddress() { | ||
59 | + return ipAddress; | ||
60 | + } | ||
61 | + | ||
62 | + /** | ||
63 | + * Convert the BGPId value to a ':' separated hexadecimal string. | ||
64 | + * | ||
65 | + * @return the BGPId value as a ':' separated hexadecimal string. | ||
66 | + */ | ||
67 | + @Override | ||
68 | + public String toString() { | ||
69 | + return ipAddress.toString(); | ||
70 | + } | ||
71 | + | ||
72 | + @Override | ||
73 | + public boolean equals(Object other) { | ||
74 | + if (!(other instanceof BGPId)) { | ||
75 | + return false; | ||
76 | + } | ||
77 | + | ||
78 | + BGPId otherBGPid = (BGPId) other; | ||
79 | + return Objects.equals(ipAddress, otherBGPid.ipAddress); | ||
80 | + } | ||
81 | + | ||
82 | + @Override | ||
83 | + public int hashCode() { | ||
84 | + return Objects.hash(ipAddress); | ||
85 | + } | ||
86 | + | ||
87 | + /** | ||
88 | + * Returns BGPId created from the given device URI. | ||
89 | + * | ||
90 | + * @param uri device URI | ||
91 | + * @return object of BGPId | ||
92 | + */ | ||
93 | + public static BGPId bgpId(URI uri) { | ||
94 | + checkArgument(uri.getScheme().equals(SCHEME), "Unsupported URI scheme"); | ||
95 | + return new BGPId(IpAddress.valueOf(uri.getSchemeSpecificPart())); | ||
96 | + } | ||
97 | + | ||
98 | + /** | ||
99 | + * Produces device URI from the given DPID. | ||
100 | + * | ||
101 | + * @param bgpId device bgpId | ||
102 | + * @return device URI | ||
103 | + */ | ||
104 | + public static URI uri(BGPId bgpId) { | ||
105 | + return uri(bgpId.ipAddress()); | ||
106 | + } | ||
107 | + | ||
108 | + /** | ||
109 | + * Produces device URI from the given DPID long. | ||
110 | + * | ||
111 | + * @param ipAddress device ip address | ||
112 | + * @return device URI | ||
113 | + */ | ||
114 | + public static URI uri(IpAddress ipAddress) { | ||
115 | + try { | ||
116 | + return new URI(SCHEME, ipAddress.toString(), null); | ||
117 | + } catch (URISyntaxException e) { | ||
118 | + return null; | ||
119 | + } | ||
120 | + } | ||
121 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.bgp.controller; | ||
18 | + | ||
19 | +/** | ||
20 | + * A representation of a packet context which allows any provider to view a packet in event, but may block the response | ||
21 | + * to the event if blocked has been called. This packet context can be used to react to the packet in event with a | ||
22 | + * packet out. | ||
23 | + */ | ||
24 | +public interface BGPPacketStats { | ||
25 | + /** | ||
26 | + * Returns the count for no of packets sent out. | ||
27 | + * | ||
28 | + * @return int value of no of packets sent | ||
29 | + */ | ||
30 | + int outPacketCount(); | ||
31 | + | ||
32 | + /** | ||
33 | + * Returns the count for no of packets received. | ||
34 | + * | ||
35 | + * @return int value of no of packets sent | ||
36 | + */ | ||
37 | + int inPacketCount(); | ||
38 | + | ||
39 | + /** | ||
40 | + * Returns the count for no of wrong packets received. | ||
41 | + * | ||
42 | + * @return int value of no of wrong packets received | ||
43 | + */ | ||
44 | + int wrongPacketCount(); | ||
45 | + | ||
46 | + /** | ||
47 | + * Returns the time. | ||
48 | + * | ||
49 | + * @return the time | ||
50 | + */ | ||
51 | + long getTime(); | ||
52 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.bgpio.exceptions; | ||
18 | + | ||
19 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
20 | + | ||
21 | +/** | ||
22 | + * Custom Exception for BGP IO. | ||
23 | + */ | ||
24 | +public class BGPParseException extends Exception { | ||
25 | + | ||
26 | + private static final long serialVersionUID = 1L; | ||
27 | + private byte errorCode; | ||
28 | + private byte errorSubCode; | ||
29 | + private ChannelBuffer data; | ||
30 | + | ||
31 | + /** | ||
32 | + * Default constructor to create a new exception. | ||
33 | + */ | ||
34 | + public BGPParseException() { | ||
35 | + super(); | ||
36 | + } | ||
37 | + | ||
38 | + /** | ||
39 | + * Constructor to create exception from message and cause. | ||
40 | + * | ||
41 | + * @param message the detail of exception in string | ||
42 | + * @param cause underlying cause of the error | ||
43 | + */ | ||
44 | + public BGPParseException(final String message, final Throwable cause) { | ||
45 | + super(message, cause); | ||
46 | + } | ||
47 | + | ||
48 | + /** | ||
49 | + * Constructor to create exception from message. | ||
50 | + * | ||
51 | + * @param message the detail of exception in string | ||
52 | + */ | ||
53 | + public BGPParseException(final String message) { | ||
54 | + super(message); | ||
55 | + } | ||
56 | + | ||
57 | + /** | ||
58 | + * Constructor to create exception from cause. | ||
59 | + * | ||
60 | + * @param cause underlying cause of the error | ||
61 | + */ | ||
62 | + public BGPParseException(final Throwable cause) { | ||
63 | + super(cause); | ||
64 | + } | ||
65 | + | ||
66 | + /** | ||
67 | + * Constructor to create exception from error code and error subcode. | ||
68 | + * | ||
69 | + * @param errorCode error code of BGP message | ||
70 | + * @param errorSubCode error subcode of BGP message | ||
71 | + * @param data error data of BGP message | ||
72 | + */ | ||
73 | + public BGPParseException(final byte errorCode, final byte errorSubCode, final ChannelBuffer data) { | ||
74 | + super(); | ||
75 | + this.errorCode = errorCode; | ||
76 | + this.errorSubCode = errorSubCode; | ||
77 | + this.data = data; | ||
78 | + } | ||
79 | + | ||
80 | + /** | ||
81 | + * Returns errorcode for this exception. | ||
82 | + * | ||
83 | + * @return errorcode for this exception | ||
84 | + */ | ||
85 | + public byte getErrorCode() { | ||
86 | + return this.errorCode; | ||
87 | + } | ||
88 | + | ||
89 | + /** | ||
90 | + * Returns error Subcode for this exception. | ||
91 | + * | ||
92 | + * @return error Subcode for this exception | ||
93 | + */ | ||
94 | + public byte getErrorSubCode() { | ||
95 | + return this.errorSubCode; | ||
96 | + } | ||
97 | + | ||
98 | + /** | ||
99 | + * Returns error data for this exception. | ||
100 | + * | ||
101 | + * @return error data for this exception | ||
102 | + */ | ||
103 | + public ChannelBuffer getData() { | ||
104 | + return this.data; | ||
105 | + } | ||
106 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.bgpio.protocol; | ||
18 | + | ||
19 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
20 | +import org.onosproject.bgpio.exceptions.BGPParseException; | ||
21 | +import org.onosproject.bgpio.types.BGPHeader; | ||
22 | + | ||
23 | +/** | ||
24 | + * Abstraction of an entity providing BGP Messages. | ||
25 | + */ | ||
26 | +public interface BGPMessage extends Writeable { | ||
27 | + /** | ||
28 | + * Returns BGP Header of BGP Message. | ||
29 | + * | ||
30 | + * @return BGP Header of BGP Message | ||
31 | + */ | ||
32 | + BGPHeader getHeader(); | ||
33 | + | ||
34 | + /** | ||
35 | + * Returns version of BGP Message. | ||
36 | + * | ||
37 | + * @return version of BGP Message | ||
38 | + */ | ||
39 | + BGPVersion getVersion(); | ||
40 | + | ||
41 | + /** | ||
42 | + * Returns BGP Type of BGP Message. | ||
43 | + * | ||
44 | + * @return BGP Type of BGP Message | ||
45 | + */ | ||
46 | + BGPType getType(); | ||
47 | + | ||
48 | + @Override | ||
49 | + void writeTo(ChannelBuffer cb) throws BGPParseException; | ||
50 | + | ||
51 | + /** | ||
52 | + * Builder interface with get and set functions to build BGP Message. | ||
53 | + */ | ||
54 | + interface Builder { | ||
55 | + /** | ||
56 | + * Builds BGP Message. | ||
57 | + * | ||
58 | + * @return BGP Message | ||
59 | + * @throws BGPParseException while building bgp message | ||
60 | + */ | ||
61 | + BGPMessage build() throws BGPParseException; | ||
62 | + | ||
63 | + /** | ||
64 | + * Returns BGP Version of BGP Message. | ||
65 | + * | ||
66 | + * @return BGP Version of BGP Message | ||
67 | + */ | ||
68 | + BGPVersion getVersion(); | ||
69 | + | ||
70 | + /** | ||
71 | + * Returns BGP Type of BGP Message. | ||
72 | + * | ||
73 | + * @return BGP Type of BGP Message | ||
74 | + */ | ||
75 | + BGPType getType(); | ||
76 | + | ||
77 | + /** | ||
78 | + * Returns BGP Header of BGP Message. | ||
79 | + * | ||
80 | + * @return BGP Header of BGP Message | ||
81 | + */ | ||
82 | + BGPHeader getHeader(); | ||
83 | + | ||
84 | + /** | ||
85 | + * Sets BgpHeader and return its builder. | ||
86 | + * | ||
87 | + * @param bgpMsgHeader BGP Message Header | ||
88 | + * @return builder by setting BGP message header | ||
89 | + */ | ||
90 | + Builder setHeader(BGPHeader bgpMsgHeader); | ||
91 | + } | ||
92 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.bgpio.protocol; | ||
17 | + | ||
18 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
19 | +import org.onosproject.bgpio.exceptions.BGPParseException; | ||
20 | +import org.onosproject.bgpio.types.BGPHeader; | ||
21 | + | ||
22 | +/** | ||
23 | + * Abstraction of an entity providing BGP Message Reader. | ||
24 | + */ | ||
25 | +public interface BGPMessageReader<T> { | ||
26 | + | ||
27 | + /** | ||
28 | + * Reads the Objects in the BGP Message and Returns BGP Message. | ||
29 | + * | ||
30 | + * @param cb Channel Buffer | ||
31 | + * @param bgpHeader BGP message header | ||
32 | + * @return BGP Message | ||
33 | + * @throws BGPParseException while parsing BGP message. | ||
34 | + */ | ||
35 | + T readFrom(ChannelBuffer cb, BGPHeader bgpHeader) throws BGPParseException; | ||
36 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.bgpio.protocol; | ||
18 | + | ||
19 | +/** | ||
20 | + * Enum to Provide the Different types of BGP messages. | ||
21 | + */ | ||
22 | +public enum BGPType { | ||
23 | + | ||
24 | + NONE(0), OPEN(1), UPDATE(2), NOTIFICATION(3), KEEP_ALIVE(4); | ||
25 | + | ||
26 | + int value; | ||
27 | + | ||
28 | + /** | ||
29 | + * Assign value with the value val as the types of BGP message. | ||
30 | + * | ||
31 | + * @param val type of BGP message | ||
32 | + */ | ||
33 | + BGPType(int val) { | ||
34 | + value = val; | ||
35 | + } | ||
36 | + | ||
37 | + /** | ||
38 | + * Returns value as type of BGP message. | ||
39 | + * | ||
40 | + * @return value type of BGP message | ||
41 | + */ | ||
42 | + public byte getType() { | ||
43 | + return (byte) value; | ||
44 | + } | ||
45 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.bgpio.protocol; | ||
18 | + | ||
19 | +/** | ||
20 | + * Enum to provide BGP Message Version. | ||
21 | + */ | ||
22 | +public enum BGPVersion { | ||
23 | + | ||
24 | + BGP_4(4); | ||
25 | + | ||
26 | + public final int packetVersion; | ||
27 | + | ||
28 | + /** | ||
29 | + * Assign BGP PacketVersion with specified packetVersion. | ||
30 | + * | ||
31 | + * @param packetVersion version of BGP | ||
32 | + */ | ||
33 | + BGPVersion(final int packetVersion) { | ||
34 | + this.packetVersion = packetVersion; | ||
35 | + } | ||
36 | + | ||
37 | + /** | ||
38 | + * Returns Packet version of BGP Message. | ||
39 | + * | ||
40 | + * @return packetVersion | ||
41 | + */ | ||
42 | + public int getPacketVersion() { | ||
43 | + return packetVersion; | ||
44 | + } | ||
45 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.bgpio.protocol; | ||
18 | + | ||
19 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
20 | +import org.onosproject.bgpio.exceptions.BGPParseException; | ||
21 | + | ||
22 | +/** | ||
23 | + * Abstraction of an entity providing functionality to write byte streams of | ||
24 | + * Messages to channel buffer. | ||
25 | + */ | ||
26 | +public interface Writeable { | ||
27 | + | ||
28 | + /** | ||
29 | + * Writes byte streams of messages to channel buffer. | ||
30 | + * | ||
31 | + * @param cb channelBuffer | ||
32 | + * @throws BGPParseException when error occurs while writing BGP message to channel buffer | ||
33 | + */ | ||
34 | + void writeTo(ChannelBuffer cb) throws BGPParseException; | ||
35 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.bgpio.types; | ||
17 | + | ||
18 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
19 | +import org.slf4j.Logger; | ||
20 | +import org.slf4j.LoggerFactory; | ||
21 | + | ||
22 | +/** | ||
23 | + * Provides BGP Message Header which is common for all the Messages. | ||
24 | + */ | ||
25 | + | ||
26 | +public class BGPHeader { | ||
27 | + | ||
28 | + /* 0 1 2 3 | ||
29 | + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 | ||
30 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
31 | + | | | ||
32 | + + + | ||
33 | + | | | ||
34 | + + + | ||
35 | + | Marker | | ||
36 | + + + | ||
37 | + | | | ||
38 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
39 | + | Length | Type | | ||
40 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
41 | + */ | ||
42 | + | ||
43 | + protected static final Logger log = LoggerFactory.getLogger(BGPHeader.class); | ||
44 | + | ||
45 | + public static final int MARKER_LENGTH = 16; | ||
46 | + public static final short DEFAULT_HEADER_LENGTH = 19; | ||
47 | + | ||
48 | + private byte[] marker; | ||
49 | + private byte type; | ||
50 | + private short length; | ||
51 | + | ||
52 | + /** | ||
53 | + * Reset fields. | ||
54 | + */ | ||
55 | + public BGPHeader() { | ||
56 | + this.marker = null; | ||
57 | + this.length = 0; | ||
58 | + this.type = 0; | ||
59 | + } | ||
60 | + | ||
61 | + /** | ||
62 | + * Constructors to initialize parameters. | ||
63 | + * | ||
64 | + * @param marker field in BGP header | ||
65 | + * @param length message length | ||
66 | + * @param type message type | ||
67 | + */ | ||
68 | + public BGPHeader(byte[] marker, short length, byte type) { | ||
69 | + this.marker = marker; | ||
70 | + this.length = length; | ||
71 | + this.type = type; | ||
72 | + } | ||
73 | + | ||
74 | + /** | ||
75 | + * Sets marker field. | ||
76 | + * | ||
77 | + * @param value marker field | ||
78 | + */ | ||
79 | + public void setMarker(byte[] value) { | ||
80 | + this.marker = value; | ||
81 | + } | ||
82 | + | ||
83 | + /** | ||
84 | + * Sets message type. | ||
85 | + * | ||
86 | + * @param value message type | ||
87 | + */ | ||
88 | + public void setType(byte value) { | ||
89 | + this.type = value; | ||
90 | + } | ||
91 | + | ||
92 | + /** | ||
93 | + * Sets message length. | ||
94 | + * | ||
95 | + * @param value message length | ||
96 | + */ | ||
97 | + public void setLength(short value) { | ||
98 | + this.length = value; | ||
99 | + } | ||
100 | + | ||
101 | + /** | ||
102 | + * Returns message length. | ||
103 | + * | ||
104 | + * @return message length | ||
105 | + */ | ||
106 | + public short getLength() { | ||
107 | + return this.length; | ||
108 | + } | ||
109 | + | ||
110 | + /** | ||
111 | + * Returns message marker. | ||
112 | + * | ||
113 | + * @return message marker | ||
114 | + */ | ||
115 | + public byte[] getMarker() { | ||
116 | + return this.marker; | ||
117 | + } | ||
118 | + | ||
119 | + /** | ||
120 | + * Returns message type. | ||
121 | + * | ||
122 | + * @return message type | ||
123 | + */ | ||
124 | + public byte getType() { | ||
125 | + return this.type; | ||
126 | + } | ||
127 | + | ||
128 | + /** | ||
129 | + * Writes Byte stream of BGP header to channel buffer. | ||
130 | + * | ||
131 | + * @param cb ChannelBuffer | ||
132 | + * @return length index of message header | ||
133 | + */ | ||
134 | + public int write(ChannelBuffer cb) { | ||
135 | + | ||
136 | + cb.writeBytes(getMarker(), 0, MARKER_LENGTH); | ||
137 | + | ||
138 | + int headerLenIndex = cb.writerIndex(); | ||
139 | + cb.writeShort((short) 0); | ||
140 | + cb.writeByte(type); | ||
141 | + | ||
142 | + return headerLenIndex; | ||
143 | + } | ||
144 | + | ||
145 | + /** | ||
146 | + * Read from channel buffer and Returns BGP header. | ||
147 | + * | ||
148 | + * @param cb ChannelBuffer | ||
149 | + * @return object of BGPHeader | ||
150 | + */ | ||
151 | + public static BGPHeader read(ChannelBuffer cb) { | ||
152 | + | ||
153 | + byte[] marker = new byte[MARKER_LENGTH]; | ||
154 | + byte type; | ||
155 | + short length; | ||
156 | + cb.readBytes(marker, 0, MARKER_LENGTH); | ||
157 | + length = cb.readShort(); | ||
158 | + type = cb.readByte(); | ||
159 | + return new BGPHeader(marker, length, type); | ||
160 | + } | ||
161 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.bgpio.types; | ||
18 | + | ||
19 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
20 | + | ||
21 | +/** | ||
22 | + * Abstraction which Provides the BGP of TLV format. | ||
23 | + */ | ||
24 | +public interface BGPValueType { | ||
25 | + /** | ||
26 | + * Returns the Type of BGP Message. | ||
27 | + * | ||
28 | + * @return short value of type | ||
29 | + */ | ||
30 | + short getType(); | ||
31 | + | ||
32 | + /** | ||
33 | + * Writes the byte Stream of BGP Message to channel buffer. | ||
34 | + * | ||
35 | + * @param cb channel buffer | ||
36 | + * @return length written to channel buffer | ||
37 | + */ | ||
38 | + int write(ChannelBuffer cb); | ||
39 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.bgp.controller.impl; | ||
18 | + | ||
19 | +import org.jboss.netty.handler.timeout.IdleStateAwareChannelHandler; | ||
20 | + | ||
21 | +/** | ||
22 | + * Channel handler deals with the bgp peer connection and dispatches messages from peer to the appropriate locations. | ||
23 | + */ | ||
24 | +class BGPChannelHandler extends IdleStateAwareChannelHandler { | ||
25 | + | ||
26 | + // TODO: implement FSM and session handling mechanism | ||
27 | + /** | ||
28 | + * Create a new unconnected BGPChannelHandler. | ||
29 | + * | ||
30 | + * @param bgpCtrlImpl bgp controller implementation object | ||
31 | + */ | ||
32 | + BGPChannelHandler(BGPControllerImpl bgpCtrlImpl) { | ||
33 | + } | ||
34 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.bgp.controller.impl; | ||
18 | + | ||
19 | +import static org.onlab.util.Tools.groupedThreads; | ||
20 | +import java.util.concurrent.ExecutorService; | ||
21 | +import java.util.concurrent.Executors; | ||
22 | +import org.apache.felix.scr.annotations.Activate; | ||
23 | +import org.apache.felix.scr.annotations.Component; | ||
24 | +import org.apache.felix.scr.annotations.Deactivate; | ||
25 | +import org.apache.felix.scr.annotations.Service; | ||
26 | +import org.onosproject.bgp.controller.BGPCfg; | ||
27 | +import org.onosproject.bgp.controller.BGPController; | ||
28 | +import org.onosproject.bgp.controller.BGPId; | ||
29 | +import org.onosproject.bgpio.protocol.BGPMessage; | ||
30 | +import org.slf4j.Logger; | ||
31 | +import org.slf4j.LoggerFactory; | ||
32 | + | ||
33 | +@Component(immediate = true) | ||
34 | +@Service | ||
35 | +public class BGPControllerImpl implements BGPController { | ||
36 | + | ||
37 | + private static final Logger log = LoggerFactory.getLogger(BGPControllerImpl.class); | ||
38 | + | ||
39 | + private final ExecutorService executorMsgs = Executors.newFixedThreadPool(32, | ||
40 | + groupedThreads("onos/bgp", | ||
41 | + "event-stats-%d")); | ||
42 | + | ||
43 | + private final ExecutorService executorBarrier = Executors.newFixedThreadPool(4, | ||
44 | + groupedThreads("onos/bgp", | ||
45 | + "event-barrier-%d")); | ||
46 | + | ||
47 | + final Controller ctrl = new Controller(this); | ||
48 | + | ||
49 | + private BGPConfig bgpconfig = new BGPConfig(); | ||
50 | + | ||
51 | + @Activate | ||
52 | + public void activate() { | ||
53 | + this.ctrl.start(); | ||
54 | + log.info("Started"); | ||
55 | + } | ||
56 | + | ||
57 | + @Deactivate | ||
58 | + public void deactivate() { | ||
59 | + // Close all connected peers | ||
60 | + this.ctrl.stop(); | ||
61 | + log.info("Stopped"); | ||
62 | + } | ||
63 | + | ||
64 | + @Override | ||
65 | + public void writeMsg(BGPId bgpId, BGPMessage msg) { | ||
66 | + // TODO: Send message | ||
67 | + } | ||
68 | + | ||
69 | + @Override | ||
70 | + public void processBGPPacket(BGPId bgpId, BGPMessage msg) { | ||
71 | + | ||
72 | + switch (msg.getType()) { | ||
73 | + case OPEN: | ||
74 | + // TODO: Process Open message | ||
75 | + break; | ||
76 | + case KEEP_ALIVE: | ||
77 | + // TODO: Process keepalive message | ||
78 | + break; | ||
79 | + case NOTIFICATION: | ||
80 | + // TODO: Process notificatoin message | ||
81 | + break; | ||
82 | + case UPDATE: | ||
83 | + // TODO: Process update message | ||
84 | + break; | ||
85 | + default: | ||
86 | + // TODO: Process other message | ||
87 | + break; | ||
88 | + } | ||
89 | + } | ||
90 | + | ||
91 | + /** | ||
92 | + * Get controller instance. | ||
93 | + * | ||
94 | + * @return ctrl the controller. | ||
95 | + */ | ||
96 | + public Controller getController() { | ||
97 | + return ctrl; | ||
98 | + } | ||
99 | + | ||
100 | + @Override | ||
101 | + public BGPCfg getConfig() { | ||
102 | + return this.bgpconfig; | ||
103 | + } | ||
104 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.bgp.controller.impl; | ||
17 | + | ||
18 | +import java.util.LinkedList; | ||
19 | +import java.util.List; | ||
20 | + | ||
21 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
22 | +import org.jboss.netty.channel.Channel; | ||
23 | +import org.jboss.netty.channel.ChannelHandlerContext; | ||
24 | +import org.jboss.netty.handler.codec.frame.FrameDecoder; | ||
25 | +import org.onosproject.bgpio.protocol.BGPMessage; | ||
26 | +import org.onlab.util.HexDump; | ||
27 | +import org.slf4j.Logger; | ||
28 | +import org.slf4j.LoggerFactory; | ||
29 | + | ||
30 | +/** | ||
31 | + * Decode an bgp message from a Channel, for use in a netty pipeline. | ||
32 | + */ | ||
33 | +public class BGPMessageDecoder extends FrameDecoder { | ||
34 | + | ||
35 | + protected static final Logger log = LoggerFactory.getLogger(BGPMessageDecoder.class); | ||
36 | + | ||
37 | + @Override | ||
38 | + protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception { | ||
39 | + | ||
40 | + List<BGPMessage> msgList = new LinkedList<BGPMessage>(); | ||
41 | + | ||
42 | + log.debug("MESSAGE IS RECEIVED."); | ||
43 | + if (!channel.isConnected()) { | ||
44 | + log.info("Channel is not connected."); | ||
45 | + return null; | ||
46 | + } | ||
47 | + | ||
48 | + HexDump.dump(buffer); | ||
49 | + | ||
50 | + // TODO: decode bgp messages | ||
51 | + return msgList; | ||
52 | + } | ||
53 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.bgp.controller.impl; | ||
17 | + | ||
18 | +import java.util.List; | ||
19 | + | ||
20 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
21 | +import org.jboss.netty.buffer.ChannelBuffers; | ||
22 | +import org.jboss.netty.channel.Channel; | ||
23 | +import org.jboss.netty.channel.ChannelHandlerContext; | ||
24 | +import org.jboss.netty.handler.codec.oneone.OneToOneEncoder; | ||
25 | +import org.onosproject.bgpio.protocol.BGPMessage; | ||
26 | +import org.onlab.util.HexDump; | ||
27 | + | ||
28 | +import org.slf4j.Logger; | ||
29 | +import org.slf4j.LoggerFactory; | ||
30 | + | ||
31 | +/** | ||
32 | + * Encode an bgp message for output into a ChannelBuffer, for use in a | ||
33 | + * netty pipeline. | ||
34 | + */ | ||
35 | +public class BGPMessageEncoder extends OneToOneEncoder { | ||
36 | + protected static final Logger log = LoggerFactory.getLogger(BGPMessageEncoder.class); | ||
37 | + | ||
38 | + @Override | ||
39 | + protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { | ||
40 | + log.debug("BGPMessageEncoder::encode"); | ||
41 | + if (!(msg instanceof List)) { | ||
42 | + log.debug("Invalid msg."); | ||
43 | + return msg; | ||
44 | + } | ||
45 | + | ||
46 | + @SuppressWarnings("unchecked") | ||
47 | + List<BGPMessage> msglist = (List<BGPMessage>) msg; | ||
48 | + | ||
49 | + ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); | ||
50 | + | ||
51 | + log.debug("SENDING MESSAGE"); | ||
52 | + for (BGPMessage pm : msglist) { | ||
53 | + pm.writeTo(buf); | ||
54 | + } | ||
55 | + | ||
56 | + HexDump.dump(buf); | ||
57 | + | ||
58 | + return buf; | ||
59 | + } | ||
60 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.bgp.controller.impl; | ||
17 | + | ||
18 | +import org.onosproject.bgp.controller.BGPPacketStats; | ||
19 | + | ||
20 | +/** | ||
21 | + * A representation of a packet context which allows any provider | ||
22 | + * to view a packet in event, but may block the response to the | ||
23 | + * event if blocked has been called. This packet context can be used | ||
24 | + * to react to the packet in event with a packet out. | ||
25 | + */ | ||
26 | +public class BGPPacketStatsImpl implements BGPPacketStats { | ||
27 | + | ||
28 | + private int inPacketCount; | ||
29 | + private int outPacketCount; | ||
30 | + private int wrongPacketCount; | ||
31 | + private long time; | ||
32 | + | ||
33 | + /** | ||
34 | + * Resets parameter. | ||
35 | + */ | ||
36 | + public BGPPacketStatsImpl() { | ||
37 | + this.inPacketCount = 0; | ||
38 | + this.outPacketCount = 0; | ||
39 | + this.wrongPacketCount = 0; | ||
40 | + this.time = 0; | ||
41 | + } | ||
42 | + | ||
43 | + /** | ||
44 | + * Get the outgoing packet count number. | ||
45 | + * | ||
46 | + * @return | ||
47 | + * packet count | ||
48 | + */ | ||
49 | + public int outPacketCount() { | ||
50 | + return outPacketCount; | ||
51 | + } | ||
52 | + | ||
53 | + /** | ||
54 | + * Get the incoming packet count number. | ||
55 | + * | ||
56 | + * @return | ||
57 | + * packet count | ||
58 | + */ | ||
59 | + public int inPacketCount() { | ||
60 | + return inPacketCount; | ||
61 | + } | ||
62 | + | ||
63 | + /** | ||
64 | + * Get the wrong packet count number. | ||
65 | + * | ||
66 | + * @return | ||
67 | + * packet count | ||
68 | + */ | ||
69 | + public int wrongPacketCount() { | ||
70 | + return wrongPacketCount; | ||
71 | + } | ||
72 | + | ||
73 | + /** | ||
74 | + * Increments the received packet counter. | ||
75 | + */ | ||
76 | + public void addInPacket() { | ||
77 | + this.inPacketCount++; | ||
78 | + } | ||
79 | + | ||
80 | + /** | ||
81 | + * Increments the sent packet counter. | ||
82 | + */ | ||
83 | + public void addOutPacket() { | ||
84 | + this.outPacketCount++; | ||
85 | + } | ||
86 | + | ||
87 | + /** | ||
88 | + * Increments the sent packet counter by specified value. | ||
89 | + * | ||
90 | + * @param value of no of packets sent | ||
91 | + */ | ||
92 | + public void addOutPacket(int value) { | ||
93 | + this.outPacketCount = this.outPacketCount + value; | ||
94 | + } | ||
95 | + | ||
96 | + /** | ||
97 | + * Increments the wrong packet counter. | ||
98 | + */ | ||
99 | + public void addWrongPacket() { | ||
100 | + this.wrongPacketCount++; | ||
101 | + } | ||
102 | + | ||
103 | + /** | ||
104 | + * Resets wrong packet count. | ||
105 | + */ | ||
106 | + public void resetWrongPacket() { | ||
107 | + this.wrongPacketCount = 0; | ||
108 | + } | ||
109 | + | ||
110 | + /** | ||
111 | + * Get the time. | ||
112 | + * | ||
113 | + * @return | ||
114 | + * time | ||
115 | + */ | ||
116 | + public long getTime() { | ||
117 | + return this.time; | ||
118 | + } | ||
119 | + | ||
120 | + /** | ||
121 | + * Sets the time. | ||
122 | + * | ||
123 | + * @param time value to set | ||
124 | + */ | ||
125 | + public void setTime(long time) { | ||
126 | + this.time = time; | ||
127 | + } | ||
128 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.bgp.controller.impl; | ||
18 | + | ||
19 | +import org.jboss.netty.channel.ChannelPipeline; | ||
20 | +import org.jboss.netty.channel.ChannelPipelineFactory; | ||
21 | +import org.jboss.netty.channel.Channels; | ||
22 | +import org.jboss.netty.handler.timeout.ReadTimeoutHandler; | ||
23 | +import org.jboss.netty.util.ExternalResourceReleasable; | ||
24 | +import org.jboss.netty.util.HashedWheelTimer; | ||
25 | +import org.jboss.netty.util.Timer; | ||
26 | + | ||
27 | +/** | ||
28 | + * Creates a ChannelPipeline for a server-side bgp channel. | ||
29 | + */ | ||
30 | +public class BGPPipelineFactory | ||
31 | + implements ChannelPipelineFactory, ExternalResourceReleasable { | ||
32 | + | ||
33 | + static final Timer TIMER = new HashedWheelTimer(); | ||
34 | + protected ReadTimeoutHandler readTimeoutHandler; | ||
35 | + BGPControllerImpl bgpCtrlImpl; | ||
36 | + | ||
37 | + /** | ||
38 | + * Constructor to initialize the values. | ||
39 | + * | ||
40 | + * @param ctrlImpl parent ctrlImpl | ||
41 | + * @param isServBgp if it is a server or not | ||
42 | + */ | ||
43 | + public BGPPipelineFactory(BGPControllerImpl ctrlImpl, boolean isServBgp) { | ||
44 | + super(); | ||
45 | + bgpCtrlImpl = ctrlImpl; | ||
46 | + /* hold time*/ | ||
47 | + readTimeoutHandler = new ReadTimeoutHandler(TIMER, bgpCtrlImpl.getConfig().getHoldTime()); | ||
48 | + } | ||
49 | + | ||
50 | + @Override | ||
51 | + public ChannelPipeline getPipeline() throws Exception { | ||
52 | + BGPChannelHandler handler = new BGPChannelHandler(bgpCtrlImpl); | ||
53 | + | ||
54 | + ChannelPipeline pipeline = Channels.pipeline(); | ||
55 | + pipeline.addLast("bgpmessagedecoder", new BGPMessageDecoder()); | ||
56 | + pipeline.addLast("bgpmessageencoder", new BGPMessageEncoder()); | ||
57 | + pipeline.addLast("holdTime", readTimeoutHandler); | ||
58 | + pipeline.addLast("PassiveHandler", handler); | ||
59 | + | ||
60 | + return pipeline; | ||
61 | + } | ||
62 | + | ||
63 | + @Override | ||
64 | + public void releaseExternalResources() { | ||
65 | + TIMER.stop(); | ||
66 | + } | ||
67 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.bgp.controller.impl; | ||
17 | + | ||
18 | +import static org.onlab.util.Tools.groupedThreads; | ||
19 | + | ||
20 | +import java.lang.management.ManagementFactory; | ||
21 | +import java.lang.management.RuntimeMXBean; | ||
22 | +import java.net.InetSocketAddress; | ||
23 | +import java.util.HashMap; | ||
24 | +import java.util.Map; | ||
25 | +import java.util.concurrent.Executors; | ||
26 | + | ||
27 | +import org.jboss.netty.bootstrap.ServerBootstrap; | ||
28 | +import org.jboss.netty.channel.ChannelPipelineFactory; | ||
29 | +import org.jboss.netty.channel.group.ChannelGroup; | ||
30 | +import org.jboss.netty.channel.group.DefaultChannelGroup; | ||
31 | +import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; | ||
32 | +import org.slf4j.Logger; | ||
33 | +import org.slf4j.LoggerFactory; | ||
34 | + | ||
35 | +/** | ||
36 | + * The main controller class. Handles all setup and network listeners - Distributed ownership control of bgp peer | ||
37 | + * through IControllerRegistryService | ||
38 | + */ | ||
39 | +public class Controller { | ||
40 | + | ||
41 | + protected static final Logger log = LoggerFactory.getLogger(Controller.class); | ||
42 | + | ||
43 | + private ChannelGroup cg; | ||
44 | + | ||
45 | + // Configuration options | ||
46 | + private static final short BGP_PORT_NUM = 179; | ||
47 | + private int workerThreads = 16; | ||
48 | + | ||
49 | + // Start time of the controller | ||
50 | + protected long systemStartTime; | ||
51 | + | ||
52 | + private NioServerSocketChannelFactory serverExecFactory; | ||
53 | + | ||
54 | + // Perf. related configuration | ||
55 | + protected static final int SEND_BUFFER_SIZE = 4 * 1024 * 1024; | ||
56 | + | ||
57 | + BGPControllerImpl bgpCtrlImpl; | ||
58 | + | ||
59 | + /** | ||
60 | + * Constructor to initialize parameter. | ||
61 | + * | ||
62 | + * @param bgpCtrlImpl BGP controller Impl instance | ||
63 | + */ | ||
64 | + public Controller(BGPControllerImpl bgpCtrlImpl) { | ||
65 | + this.bgpCtrlImpl = bgpCtrlImpl; | ||
66 | + } | ||
67 | + | ||
68 | + // *************** | ||
69 | + // Getters/Setters | ||
70 | + // *************** | ||
71 | + | ||
72 | + /** | ||
73 | + * To get system start time. | ||
74 | + * | ||
75 | + * @return system start time in milliseconds | ||
76 | + */ | ||
77 | + public long getSystemStartTime() { | ||
78 | + return (this.systemStartTime); | ||
79 | + } | ||
80 | + | ||
81 | + // ************** | ||
82 | + // Initialization | ||
83 | + // ************** | ||
84 | + | ||
85 | + /** | ||
86 | + * Tell controller that we're ready to accept bgp peer connections. | ||
87 | + */ | ||
88 | + public void run() { | ||
89 | + | ||
90 | + try { | ||
91 | + final ServerBootstrap bootstrap = createServerBootStrap(); | ||
92 | + | ||
93 | + bootstrap.setOption("reuseAddr", true); | ||
94 | + bootstrap.setOption("child.keepAlive", true); | ||
95 | + bootstrap.setOption("child.tcpNoDelay", true); | ||
96 | + bootstrap.setOption("child.sendBufferSize", Controller.SEND_BUFFER_SIZE); | ||
97 | + | ||
98 | + ChannelPipelineFactory pfact = new BGPPipelineFactory(bgpCtrlImpl, true); | ||
99 | + | ||
100 | + bootstrap.setPipelineFactory(pfact); | ||
101 | + InetSocketAddress sa = new InetSocketAddress(getBgpPortNum()); | ||
102 | + cg = new DefaultChannelGroup(); | ||
103 | + cg.add(bootstrap.bind(sa)); | ||
104 | + log.info("Listening for Peer connection on {}", sa); | ||
105 | + } catch (Exception e) { | ||
106 | + throw new RuntimeException(e); | ||
107 | + } | ||
108 | + } | ||
109 | + | ||
110 | + /** | ||
111 | + * Creates server boot strap. | ||
112 | + * | ||
113 | + * @return ServerBootStrap | ||
114 | + */ | ||
115 | + private ServerBootstrap createServerBootStrap() { | ||
116 | + | ||
117 | + if (workerThreads == 0) { | ||
118 | + serverExecFactory = new NioServerSocketChannelFactory( | ||
119 | + Executors.newCachedThreadPool(groupedThreads("onos/bgp", "boss-%d")), | ||
120 | + Executors.newCachedThreadPool(groupedThreads("onos/bgp", "worker-%d"))); | ||
121 | + return new ServerBootstrap(serverExecFactory); | ||
122 | + } else { | ||
123 | + serverExecFactory = new NioServerSocketChannelFactory( | ||
124 | + Executors.newCachedThreadPool(groupedThreads("onos/bgp", "boss-%d")), | ||
125 | + Executors.newCachedThreadPool(groupedThreads("onos/bgp", "worker-%d")), | ||
126 | + workerThreads); | ||
127 | + return new ServerBootstrap(serverExecFactory); | ||
128 | + } | ||
129 | + } | ||
130 | + | ||
131 | + /** | ||
132 | + * Initialize internal data structures. | ||
133 | + */ | ||
134 | + public void init() { | ||
135 | + // These data structures are initialized here because other | ||
136 | + // module's startUp() might be called before ours | ||
137 | + this.systemStartTime = System.currentTimeMillis(); | ||
138 | + } | ||
139 | + | ||
140 | + // ************** | ||
141 | + // Utility methods | ||
142 | + // ************** | ||
143 | + | ||
144 | + public Map<String, Long> getMemory() { | ||
145 | + Map<String, Long> m = new HashMap<>(); | ||
146 | + Runtime runtime = Runtime.getRuntime(); | ||
147 | + m.put("total", runtime.totalMemory()); | ||
148 | + m.put("free", runtime.freeMemory()); | ||
149 | + return m; | ||
150 | + } | ||
151 | + | ||
152 | + public Long getUptime() { | ||
153 | + RuntimeMXBean rb = ManagementFactory.getRuntimeMXBean(); | ||
154 | + return rb.getUptime(); | ||
155 | + } | ||
156 | + | ||
157 | + /** | ||
158 | + * Starts the BGP controller. | ||
159 | + */ | ||
160 | + public void start() { | ||
161 | + log.info("Started"); | ||
162 | + this.init(); | ||
163 | + this.run(); | ||
164 | + } | ||
165 | + | ||
166 | + /** | ||
167 | + * Stops the BGP controller. | ||
168 | + */ | ||
169 | + public void stop() { | ||
170 | + log.info("Stopped"); | ||
171 | + serverExecFactory.shutdown(); | ||
172 | + cg.close(); | ||
173 | + } | ||
174 | + | ||
175 | + /** | ||
176 | + * Returns port number. | ||
177 | + * | ||
178 | + * @return port number | ||
179 | + */ | ||
180 | + public static short getBgpPortNum() { | ||
181 | + return BGP_PORT_NUM; | ||
182 | + } | ||
183 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onlab.util; | ||
17 | + | ||
18 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
19 | +import org.slf4j.Logger; | ||
20 | +import org.slf4j.LoggerFactory; | ||
21 | + | ||
22 | +/** | ||
23 | + * HexDump class an utility to dump buffer in hex format. | ||
24 | + */ | ||
25 | +public final class HexDump { | ||
26 | + protected static final Logger log = LoggerFactory.getLogger(HexDump.class); | ||
27 | + | ||
28 | + private HexDump() { | ||
29 | + } | ||
30 | + | ||
31 | + /** | ||
32 | + * Dump the buffer content in hex format. | ||
33 | + * | ||
34 | + * @param buff buffer content to dump in hex format | ||
35 | + */ | ||
36 | + public static void dump(ChannelBuffer buff) { | ||
37 | + try { | ||
38 | + byte[] yTemp; | ||
39 | + yTemp = buff.array(); | ||
40 | + | ||
41 | + int iStartIndex = buff.readerIndex(); | ||
42 | + int iEndIndex = buff.writerIndex(); | ||
43 | + do { | ||
44 | + StringBuilder sb = new StringBuilder(); | ||
45 | + for (int k = 0; (k < 16) && (iStartIndex < iEndIndex); ++k) { | ||
46 | + if (0 == k % 4) { | ||
47 | + sb.append(String.format(" ")); // blank after 4 bytes | ||
48 | + } | ||
49 | + sb.append(String.format("%02X ", yTemp[iStartIndex++])); | ||
50 | + } | ||
51 | + log.debug(sb.toString()); | ||
52 | + } while (iStartIndex < iEndIndex); | ||
53 | + } catch (Exception e) { | ||
54 | + log.error("[HexDump] Invalid buffer: " + e.toString()); | ||
55 | + } | ||
56 | + } | ||
57 | +} |
-
Please register or login to post a comment