Committed by
Gerrit Code Review
BGP Route policy distribution and flow spec
Change-Id: I8903efd225a24db6ccc85a4a3148a4dd6076e042
Showing
94 changed files
with
7415 additions
and
3 deletions
apps/bgpflowspec/BUCK
0 → 100755
1 | +BUNDLES = [ | ||
2 | + '//apps/bgpflowspec/flowapi:onos-apps-bgpflowspec-flowapi', | ||
3 | + '//apps/bgpflowspec/flowmgr:onos-apps-bgpflowspec-flowmgr', | ||
4 | + '//apps/bgpflowspec/bgpweb:onos-apps-bgpflowspec-web', | ||
5 | +] | ||
6 | + | ||
7 | +onos_app ( | ||
8 | + title = 'BGP App', | ||
9 | + url = 'http://onosproject.org', | ||
10 | + included_bundles = BUNDLES, | ||
11 | + description = 'ONOS framework applications', | ||
12 | +) |
apps/bgpflowspec/app/app.xml
0 → 100755
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<!-- | ||
3 | + ~ Copyright 2016-present Open Networking Laboratory | ||
4 | + ~ | ||
5 | + ~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
6 | + ~ you may not use this file except in compliance with the License. | ||
7 | + ~ You may obtain a copy of the License at | ||
8 | + ~ | ||
9 | + ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
10 | + ~ | ||
11 | + ~ Unless required by applicable law or agreed to in writing, software | ||
12 | + ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
13 | + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
14 | + ~ See the License for the specific language governing permissions and | ||
15 | + ~ limitations under the License. | ||
16 | + --> | ||
17 | +<app name="org.onosproject.bgpflow" origin="ON.Lab" version="${project.version}" | ||
18 | + category="default" url="http://onosproject.org" | ||
19 | + featuresRepo="mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features" | ||
20 | + features="${project.artifactId}"> | ||
21 | + <description>${project.description}</description> | ||
22 | + <artifact>mvn:${project.groupId}/onos-app-bgp-flowmgr/${project.version}</artifact> | ||
23 | + <artifact>mvn:${project.groupId}/onos-app-bgp-web/${project.version}</artifact> | ||
24 | + <artifact>mvn:${project.groupId}/onos-app-bgp-flowapi/${project.version}</artifact> | ||
25 | +</app> |
apps/bgpflowspec/app/features.xml
0 → 100755
1 | +<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
2 | +<!-- | ||
3 | + ~ Copyright 2016-present Open Networking Laboratory | ||
4 | + ~ | ||
5 | + ~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
6 | + ~ you may not use this file except in compliance with the License. | ||
7 | + ~ You may obtain a copy of the License at | ||
8 | + ~ | ||
9 | + ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
10 | + ~ | ||
11 | + ~ Unless required by applicable law or agreed to in writing, software | ||
12 | + ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
13 | + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
14 | + ~ See the License for the specific language governing permissions and | ||
15 | + ~ limitations under the License. | ||
16 | + --> | ||
17 | +<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}"> | ||
18 | + <feature name="${project.artifactId}" version="${project.version}" | ||
19 | + description="${project.description}"> | ||
20 | + <feature>onos-api</feature> | ||
21 | + <feature>onos-drivers</feature> | ||
22 | + <bundle>mvn:${project.groupId}/onos-app-bgp-flowapi/${project.version}</bundle> | ||
23 | + <bundle>mvn:${project.groupId}/onos-app-bgp-flowmgr/${project.version}</bundle> | ||
24 | + <bundle>mvn:${project.groupId}/onos-app-bgp-web/${project.version}</bundle> | ||
25 | + </feature> | ||
26 | +</features> |
apps/bgpflowspec/app/pom.xml
0 → 100755
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<!-- | ||
3 | + ~ Copyright 2016-present Open Networking Laboratory | ||
4 | + ~ | ||
5 | + ~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
6 | + ~ you may not use this file except in compliance with the License. | ||
7 | + ~ You may obtain a copy of the License at | ||
8 | + ~ | ||
9 | + ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
10 | + ~ | ||
11 | + ~ Unless required by applicable law or agreed to in writing, software | ||
12 | + ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
13 | + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
14 | + ~ See the License for the specific language governing permissions and | ||
15 | + ~ limitations under the License. | ||
16 | + --> | ||
17 | +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
18 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
19 | + <modelVersion>4.0.0</modelVersion> | ||
20 | + | ||
21 | + <parent> | ||
22 | + <groupId>org.onosproject</groupId> | ||
23 | + <artifactId>onos-app-bgpflow</artifactId> | ||
24 | + <version>1.6.0-SNAPSHOT</version> | ||
25 | + <relativePath>../pom.xml</relativePath> | ||
26 | + </parent> | ||
27 | + | ||
28 | + <artifactId>onos-app-bgp-flow</artifactId> | ||
29 | + <packaging>pom</packaging> | ||
30 | + | ||
31 | + <description>ONOS framework applications</description> | ||
32 | + | ||
33 | + <dependencies> | ||
34 | + <dependency> | ||
35 | + <groupId>org.onosproject</groupId> | ||
36 | + <artifactId>onos-app-bgp-flowapi</artifactId> | ||
37 | + <version>${project.version}</version> | ||
38 | + </dependency> | ||
39 | + <dependency> | ||
40 | + <groupId>org.onosproject</groupId> | ||
41 | + <artifactId>onos-app-bgp-flowmgr</artifactId> | ||
42 | + <version>${project.version}</version> | ||
43 | + </dependency> | ||
44 | + <dependency> | ||
45 | + <groupId>org.onosproject</groupId> | ||
46 | + <artifactId>onos-app-bgp-web</artifactId> | ||
47 | + <version>${project.version}</version> | ||
48 | + </dependency> | ||
49 | + </dependencies> | ||
50 | + | ||
51 | +</project> |
apps/bgpflowspec/bgpweb/BUCK
0 → 100755
1 | +COMPILE_DEPS = [ | ||
2 | + '//lib:CORE_DEPS', | ||
3 | + '//lib:javax.ws.rs-api', | ||
4 | + '//utils/rest:onlab-rest', | ||
5 | + '//apps/bgpflowspec/flowapi:onos-apps-bgpflowspec-flowapi', | ||
6 | + '//apps/bgpflowspec/flowmgr:onos-apps-bgpflowspec-flowmgr', | ||
7 | +] | ||
8 | + | ||
9 | +osgi_jar_with_tests ( | ||
10 | + name = 'onos-apps-bgpflowspec-web', | ||
11 | + deps = COMPILE_DEPS, | ||
12 | +) |
apps/bgpflowspec/bgpweb/pom.xml
0 → 100755
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<!-- | ||
3 | + ~ Copyright 2016-present Open Networking Laboratory | ||
4 | + ~ | ||
5 | + ~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
6 | + ~ you may not use this file except in compliance with the License. | ||
7 | + ~ You may obtain a copy of the License at | ||
8 | + ~ | ||
9 | + ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
10 | + ~ | ||
11 | + ~ Unless required by applicable law or agreed to in writing, software | ||
12 | + ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
13 | + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
14 | + ~ See the License for the specific language governing permissions and | ||
15 | + ~ limitations under the License. | ||
16 | + --> | ||
17 | +<project | ||
18 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" | ||
19 | + xmlns="http://maven.apache.org/POM/4.0.0" | ||
20 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
21 | + <modelVersion>4.0.0</modelVersion> | ||
22 | + <parent> | ||
23 | + <groupId>org.onosproject</groupId> | ||
24 | + <artifactId>onos-app-bgpflow</artifactId> | ||
25 | + <version>1.6.0-SNAPSHOT</version> | ||
26 | + <relativePath>../pom.xml</relativePath> | ||
27 | + </parent> | ||
28 | + | ||
29 | + <artifactId>onos-app-bgp-web</artifactId> | ||
30 | + <packaging>bundle</packaging> | ||
31 | + <properties> | ||
32 | + <web.context>/onos/bgp</web.context> | ||
33 | + </properties> | ||
34 | + | ||
35 | + <dependencies> | ||
36 | + <dependency> | ||
37 | + <groupId>javax.ws.rs</groupId> | ||
38 | + <artifactId>javax.ws.rs-api</artifactId> | ||
39 | + <version>2.0.1</version> | ||
40 | + </dependency> | ||
41 | + <dependency> | ||
42 | + <groupId>org.onosproject</groupId> | ||
43 | + <artifactId>onos-app-bgp-flowmgr</artifactId> | ||
44 | + <version>${project.version}</version> | ||
45 | + </dependency> | ||
46 | + <dependency> | ||
47 | + <groupId>org.onosproject</groupId> | ||
48 | + <artifactId>onos-rest</artifactId> | ||
49 | + <version>${project.version}</version> | ||
50 | + </dependency> | ||
51 | + <dependency> | ||
52 | + <groupId>com.google.guava</groupId> | ||
53 | + <artifactId>guava-testlib</artifactId> | ||
54 | + </dependency> | ||
55 | + </dependencies> | ||
56 | + <build> | ||
57 | + <plugins> | ||
58 | + <plugin> | ||
59 | + <groupId>org.apache.felix</groupId> | ||
60 | + <artifactId>maven-bundle-plugin</artifactId> | ||
61 | + <extensions>true</extensions> | ||
62 | + <configuration> | ||
63 | + <instructions> | ||
64 | + <_wab>src/main/webapp/</_wab> | ||
65 | + <Bundle-SymbolicName> | ||
66 | + ${project.groupId}.${project.artifactId} | ||
67 | + </Bundle-SymbolicName> | ||
68 | + <Import-Package> | ||
69 | + *,org.glassfish.jersey.servlet | ||
70 | + </Import-Package> | ||
71 | + <Web-ContextPath>${web.context}</Web-ContextPath> | ||
72 | + </instructions> | ||
73 | + </configuration> | ||
74 | + </plugin> | ||
75 | + </plugins> | ||
76 | + </build> | ||
77 | + | ||
78 | +</project> |
apps/bgpflowspec/bgpweb/src/main/java/org/onosproject/bgpweb/resources/BgpFlowWebResource.java
0 → 100755
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.bgpweb.resources; | ||
17 | + | ||
18 | +import com.fasterxml.jackson.databind.JsonNode; | ||
19 | +import com.fasterxml.jackson.databind.node.ArrayNode; | ||
20 | +import com.fasterxml.jackson.databind.node.ObjectNode; | ||
21 | +import org.onosproject.flow.manager.BgpFlowService; | ||
22 | +import org.onosproject.flowapi.DefaultExtWideCommunityInt; | ||
23 | +import org.onosproject.flowapi.ExtFlowContainer; | ||
24 | +import org.onosproject.flowapi.ExtFlowTypes; | ||
25 | +import org.onosproject.flowapi.ExtTrafficAction; | ||
26 | +import org.onosproject.flowapi.ExtWideCommunityInt; | ||
27 | +import org.onosproject.rest.AbstractWebResource; | ||
28 | +import org.slf4j.Logger; | ||
29 | +import org.slf4j.LoggerFactory; | ||
30 | + | ||
31 | +import javax.ws.rs.Consumes; | ||
32 | +import javax.ws.rs.DELETE; | ||
33 | +import javax.ws.rs.GET; | ||
34 | +import javax.ws.rs.POST; | ||
35 | +import javax.ws.rs.Path; | ||
36 | +import javax.ws.rs.Produces; | ||
37 | +import javax.ws.rs.core.MediaType; | ||
38 | +import javax.ws.rs.core.Response; | ||
39 | +import java.io.IOException; | ||
40 | +import java.io.InputStream; | ||
41 | +import java.util.List; | ||
42 | +import java.util.ListIterator; | ||
43 | + | ||
44 | +import static javax.ws.rs.core.Response.Status.NOT_ACCEPTABLE; | ||
45 | +import static javax.ws.rs.core.Response.Status.OK; | ||
46 | + | ||
47 | +/** | ||
48 | + * Bgp flow web resource. | ||
49 | + */ | ||
50 | + | ||
51 | +@Path("flow") | ||
52 | +public class BgpFlowWebResource extends AbstractWebResource { | ||
53 | + | ||
54 | + private BgpFlowService flowService = get(BgpFlowService.class); | ||
55 | + protected static final String BGPFLOW = "bgp_flow"; | ||
56 | + protected static final String DEVICEID = "deviceId"; | ||
57 | + protected static final int LOCAL_PERF = 20; | ||
58 | + private final Logger log = LoggerFactory.getLogger(BgpFlowWebResource.class); | ||
59 | + | ||
60 | + /** | ||
61 | + * Get the Bgp flow. | ||
62 | + * | ||
63 | + * @return 200 OK | ||
64 | + */ | ||
65 | + @GET | ||
66 | + @Produces(MediaType.APPLICATION_JSON) | ||
67 | + public Response getBgpFlow() { | ||
68 | + Boolean result = true; | ||
69 | + //TODO | ||
70 | + return ok(result.toString()).build(); | ||
71 | + } | ||
72 | + | ||
73 | + /** | ||
74 | + * Push the the Bgp flow spec. | ||
75 | + * | ||
76 | + * @param stream bgp flow spec in JSON | ||
77 | + * @return status of the request - CREATED if the JSON is correct, | ||
78 | + * BAD_REQUEST if the JSON is invalid | ||
79 | + */ | ||
80 | + @POST | ||
81 | + @Consumes(MediaType.APPLICATION_JSON) | ||
82 | + @Produces(MediaType.APPLICATION_JSON) | ||
83 | + public Response createBgpFlow(InputStream stream) { | ||
84 | + try { | ||
85 | + ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream); | ||
86 | + JsonNode flow = jsonTree.get(BGPFLOW); | ||
87 | + String devId = jsonTree.get(DEVICEID).asText(); | ||
88 | + boolean status; | ||
89 | + | ||
90 | + List<ExtFlowTypes> list; | ||
91 | + ExtFlowContainer container; | ||
92 | + | ||
93 | + list = codec(ExtFlowTypes.class).decode((ArrayNode) flow, this); | ||
94 | + | ||
95 | + if (!validateRpd(list)) { | ||
96 | + return Response.status(NOT_ACCEPTABLE).entity(Boolean.FALSE.toString()).build(); | ||
97 | + } | ||
98 | + | ||
99 | + container = new ExtFlowContainer(list); | ||
100 | + container.setDeviceId(devId); | ||
101 | + | ||
102 | + | ||
103 | + status = flowService.onBgpFlowCreated(container); | ||
104 | + Boolean isSuccess = Boolean.valueOf(status); | ||
105 | + if (!status) { | ||
106 | + return Response.status(NOT_ACCEPTABLE).entity(isSuccess.toString()).build(); | ||
107 | + } | ||
108 | + | ||
109 | + return Response.status(OK).entity(isSuccess.toString()).build(); | ||
110 | + } catch (IOException e) { | ||
111 | + log.error("Exception while parsing bgp flow.", e.toString()); | ||
112 | + throw new IllegalArgumentException(e); | ||
113 | + } | ||
114 | + } | ||
115 | + | ||
116 | + /** | ||
117 | + * Validates the rpd and flow spec classes. | ||
118 | + * | ||
119 | + * @param list list of types | ||
120 | + * @return a true if the validation succeeds else false | ||
121 | + */ | ||
122 | + boolean validateRpd(List<ExtFlowTypes> list) { | ||
123 | + ListIterator<ExtFlowTypes> iterator = list.listIterator(); | ||
124 | + ExtFlowTypes flow; | ||
125 | + boolean key = false; | ||
126 | + boolean rpd = false; | ||
127 | + boolean nonRpd = false; | ||
128 | + ExtTrafficAction flowAction = null; | ||
129 | + boolean dstPfx = false; | ||
130 | + boolean wcFlg = false; | ||
131 | + boolean wcHop = false; | ||
132 | + boolean wcWc = false; | ||
133 | + boolean wcCAs = false; | ||
134 | + boolean wcLAs = false; | ||
135 | + boolean wcTarget = false; | ||
136 | + boolean wcETarget = false; | ||
137 | + boolean wcParm = false; | ||
138 | + | ||
139 | + while (iterator.hasNext()) { | ||
140 | + flow = iterator.next(); | ||
141 | + switch (flow.type()) { | ||
142 | + case EXT_FLOW_RULE_KEY: | ||
143 | + key = true; | ||
144 | + break; | ||
145 | + case IPV4_DST_PFX: | ||
146 | + dstPfx = true; | ||
147 | + break; | ||
148 | + case IPV4_SRC_PFX: | ||
149 | + nonRpd = true; | ||
150 | + break; | ||
151 | + case IP_PROTO_LIST: | ||
152 | + nonRpd = true; | ||
153 | + break; | ||
154 | + case IN_PORT_LIST: | ||
155 | + nonRpd = true; | ||
156 | + break; | ||
157 | + case DST_PORT_LIST: | ||
158 | + nonRpd = true; | ||
159 | + break; | ||
160 | + case SRC_PORT_LIST: | ||
161 | + nonRpd = true; | ||
162 | + break; | ||
163 | + case ICMP_TYPE_LIST: | ||
164 | + nonRpd = true; | ||
165 | + break; | ||
166 | + case ICMP_CODE_LIST: | ||
167 | + nonRpd = true; | ||
168 | + break; | ||
169 | + case TCP_FLAG_LIST: | ||
170 | + nonRpd = true; | ||
171 | + break; | ||
172 | + case PACKET_LENGTH_LIST: | ||
173 | + nonRpd = true; | ||
174 | + break; | ||
175 | + case DSCP_VALUE_LIST: | ||
176 | + nonRpd = true; | ||
177 | + break; | ||
178 | + case FRAGMENT_LIST: | ||
179 | + nonRpd = true; | ||
180 | + break; | ||
181 | + case TRAFFIC_ACTION: | ||
182 | + flowAction = (ExtTrafficAction) flow; | ||
183 | + if (flowAction.rpd()) { | ||
184 | + rpd = true; | ||
185 | + } | ||
186 | + break; | ||
187 | + case TRAFFIC_RATE: | ||
188 | + nonRpd = true; | ||
189 | + break; | ||
190 | + case TRAFFIC_REDIRECT: | ||
191 | + nonRpd = true; | ||
192 | + break; | ||
193 | + case TRAFFIC_MARKING: | ||
194 | + nonRpd = true; | ||
195 | + break; | ||
196 | + case WIDE_COMM_FLAGS: | ||
197 | + wcFlg = true; | ||
198 | + break; | ||
199 | + case WIDE_COMM_HOP_COUNT: | ||
200 | + wcHop = true; | ||
201 | + break; | ||
202 | + case WIDE_COMM_COMMUNITY: | ||
203 | + wcWc = true; | ||
204 | + break; | ||
205 | + case WIDE_COMM_CONTEXT_AS: | ||
206 | + wcCAs = true; | ||
207 | + break; | ||
208 | + case WIDE_COMM_LOCAL_AS: | ||
209 | + wcLAs = true; | ||
210 | + break; | ||
211 | + case WIDE_COMM_TARGET: | ||
212 | + wcTarget = true; | ||
213 | + break; | ||
214 | + case WIDE_COMM_EXT_TARGET: | ||
215 | + wcETarget = true; | ||
216 | + break; | ||
217 | + case WIDE_COMM_PARAMETER: | ||
218 | + wcParm = true; | ||
219 | + break; | ||
220 | + default: | ||
221 | + log.error("error: this type is not supported"); | ||
222 | + break; | ||
223 | + } | ||
224 | + } | ||
225 | + | ||
226 | + if (!key) { | ||
227 | + return false; | ||
228 | + } | ||
229 | + | ||
230 | + /** checking for non Rpd. */ | ||
231 | + if (!rpd) { | ||
232 | + if (wcFlg || wcHop || wcWc | ||
233 | + || wcCAs || wcLAs || wcParm) { | ||
234 | + return false; | ||
235 | + } | ||
236 | + } | ||
237 | + | ||
238 | + /** checking for Rpd. */ | ||
239 | + if (nonRpd || !dstPfx || !wcFlg || !wcHop | ||
240 | + || !wcWc || !wcCAs || !wcLAs || !wcParm) { | ||
241 | + return false; | ||
242 | + } | ||
243 | + | ||
244 | + /** If it is rpd then either of these two or both should be present.*/ | ||
245 | + if (!wcTarget && !wcETarget) { | ||
246 | + rpd = false; | ||
247 | + } | ||
248 | + | ||
249 | + if (!handleRpdLocalPerf(list)) { | ||
250 | + return false; | ||
251 | + } | ||
252 | + | ||
253 | + return rpd; | ||
254 | + } | ||
255 | + | ||
256 | + /** | ||
257 | + * Validate and format the rpd local perf. | ||
258 | + * | ||
259 | + * @param list list of types | ||
260 | + * @return a true if the validation succeeds else false | ||
261 | + */ | ||
262 | + boolean handleRpdLocalPerf(List<ExtFlowTypes> list) { | ||
263 | + ListIterator<ExtFlowTypes> iterator = list.listIterator(); | ||
264 | + ExtFlowTypes flow; | ||
265 | + | ||
266 | + ExtWideCommunityInt wcComm = null; | ||
267 | + ExtWideCommunityInt wcParam = null; | ||
268 | + ListIterator<Integer> wcInt = null; | ||
269 | + int community = 0; | ||
270 | + int param = 0; | ||
271 | + | ||
272 | + while (iterator.hasNext()) { | ||
273 | + flow = iterator.next(); | ||
274 | + switch (flow.type()) { | ||
275 | + case WIDE_COMM_COMMUNITY: | ||
276 | + wcComm = (ExtWideCommunityInt) flow; | ||
277 | + wcInt = wcComm.communityInt().listIterator(); | ||
278 | + community = wcInt.next().intValue(); | ||
279 | + break; | ||
280 | + | ||
281 | + case WIDE_COMM_PARAMETER: | ||
282 | + wcParam = (ExtWideCommunityInt) flow; | ||
283 | + wcInt = wcParam.communityInt().listIterator(); | ||
284 | + param = wcInt.next().intValue(); | ||
285 | + break; | ||
286 | + default: | ||
287 | + log.error("error: this type is not supported"); | ||
288 | + break; | ||
289 | + } | ||
290 | + } | ||
291 | + | ||
292 | + if (community == LOCAL_PERF) { | ||
293 | + if (param > 127 || param < -127) { | ||
294 | + return false; | ||
295 | + } | ||
296 | + | ||
297 | + /** if -ve then make it 1 bye value and set it, if it is positive then no issue.*/ | ||
298 | + if (param < 0) { | ||
299 | + param = ~param + 129; | ||
300 | + list.remove(wcParam); | ||
301 | + ExtWideCommunityInt.Builder resultBuilder = new DefaultExtWideCommunityInt.Builder(); | ||
302 | + resultBuilder.setwCommInt(Integer.valueOf(param)); | ||
303 | + resultBuilder.setType(ExtFlowTypes.ExtType.WIDE_COMM_PARAMETER); | ||
304 | + list.add(resultBuilder.build()); | ||
305 | + } | ||
306 | + } | ||
307 | + | ||
308 | + return true; | ||
309 | + } | ||
310 | + | ||
311 | + /** | ||
312 | + * Delete the the Bgp flow spec. | ||
313 | + * | ||
314 | + * @param stream bgp flow spec in JSON | ||
315 | + * @return status of the request - CREATED if the JSON is correct, | ||
316 | + * BAD_REQUEST if the JSON is invalid | ||
317 | + */ | ||
318 | + @DELETE | ||
319 | + @Consumes(MediaType.APPLICATION_JSON) | ||
320 | + @Produces(MediaType.APPLICATION_JSON) | ||
321 | + public Response deleteBgpFlow(InputStream stream) { | ||
322 | + try { | ||
323 | + ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream); | ||
324 | + JsonNode flow = jsonTree.get(BGPFLOW); | ||
325 | + String devId = jsonTree.get(DEVICEID).asText(); | ||
326 | + boolean status; | ||
327 | + | ||
328 | + List<ExtFlowTypes> list; | ||
329 | + ExtFlowContainer container; | ||
330 | + | ||
331 | + list = codec(ExtFlowTypes.class).decode((ArrayNode) flow, this); | ||
332 | + | ||
333 | + if (!validateRpd(list)) { | ||
334 | + return Response.status(NOT_ACCEPTABLE).entity(Boolean.FALSE.toString()).build(); | ||
335 | + } | ||
336 | + | ||
337 | + container = new ExtFlowContainer(list); | ||
338 | + container.setDeviceId(devId); | ||
339 | + | ||
340 | + | ||
341 | + status = flowService.onBgpFlowDeleted(container); | ||
342 | + Boolean isSuccess = Boolean.valueOf(status); | ||
343 | + if (!status) { | ||
344 | + return Response.status(NOT_ACCEPTABLE).entity(isSuccess.toString()).build(); | ||
345 | + } | ||
346 | + return Response.status(OK).entity(isSuccess.toString()).build(); | ||
347 | + } catch (IOException e) { | ||
348 | + log.error("Exception while parsing bgp flow.", e.toString()); | ||
349 | + throw new IllegalArgumentException(e); | ||
350 | + } | ||
351 | + } | ||
352 | +} |
apps/bgpflowspec/bgpweb/src/main/java/org/onosproject/bgpweb/resources/BgpWebApplication.java
0 → 100755
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 | + | ||
17 | +package org.onosproject.bgpweb.resources; | ||
18 | + | ||
19 | +import org.onlab.rest.AbstractWebApplication; | ||
20 | +import java.util.Set; | ||
21 | + | ||
22 | +/** | ||
23 | + * BGP REST API web application. | ||
24 | + */ | ||
25 | +public class BgpWebApplication extends AbstractWebApplication { | ||
26 | + @Override | ||
27 | + public Set<Class<?>> getClasses() { | ||
28 | + return getClasses(BgpFlowWebResource.class); | ||
29 | + } | ||
30 | +} | ||
31 | + |
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 | + | ||
17 | +/** | ||
18 | + * BGP web that used rest to create BGP resources. | ||
19 | + */ | ||
20 | +package org.onosproject.bgpweb.resources; |
apps/bgpflowspec/bgpweb/src/main/java/org/onosproject/bgpweb/web/BgpCodecRegistrator.java
0 → 100755
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.bgpweb.web; | ||
17 | + | ||
18 | +import org.apache.felix.scr.annotations.Activate; | ||
19 | +import org.apache.felix.scr.annotations.Component; | ||
20 | +import org.apache.felix.scr.annotations.Deactivate; | ||
21 | +import org.apache.felix.scr.annotations.Reference; | ||
22 | +import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
23 | +import org.onosproject.codec.CodecService; | ||
24 | +import org.onosproject.flowapi.ExtFlowTypes; | ||
25 | +import org.slf4j.Logger; | ||
26 | +import org.slf4j.LoggerFactory; | ||
27 | + | ||
28 | +/** | ||
29 | + * Implementation of the JSON codec brokering service for BGP app. | ||
30 | + */ | ||
31 | +@Component(immediate = true) | ||
32 | +public class BgpCodecRegistrator { | ||
33 | + | ||
34 | + private static Logger log = LoggerFactory.getLogger(BgpCodecRegistrator.class); | ||
35 | + | ||
36 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
37 | + protected CodecService codecService; | ||
38 | + | ||
39 | + @Activate | ||
40 | + public void activate() { | ||
41 | + codecService.registerCodec(ExtFlowTypes.class, new BgpFlowExtensionCodec()); | ||
42 | + System.out.print("BgpCodecRegistrator started"); | ||
43 | + log.info("Started"); | ||
44 | + } | ||
45 | + | ||
46 | + @Deactivate | ||
47 | + public void deactivate() { | ||
48 | + log.info("Stopped"); | ||
49 | + } | ||
50 | +} |
apps/bgpflowspec/bgpweb/src/main/java/org/onosproject/bgpweb/web/BgpFlowExtensionCodec.java
0 → 100755
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.bgpweb.web; | ||
17 | + | ||
18 | +import com.fasterxml.jackson.databind.node.ObjectNode; | ||
19 | +import org.onosproject.codec.CodecContext; | ||
20 | +import org.onosproject.codec.JsonCodec; | ||
21 | +import org.onosproject.flowapi.ExtFlowTypes; | ||
22 | +import org.slf4j.Logger; | ||
23 | +import org.slf4j.LoggerFactory; | ||
24 | + | ||
25 | +public final class BgpFlowExtensionCodec extends JsonCodec<ExtFlowTypes> { | ||
26 | + | ||
27 | + protected static final Logger log = | ||
28 | + LoggerFactory.getLogger(BgpFlowExtensionCodec.class); | ||
29 | + | ||
30 | + protected static final String TYPE = "type"; | ||
31 | + protected static final String NAME = "name"; | ||
32 | + protected static final String PREFIX = "prefix"; | ||
33 | + protected static final String PROTOCOLS = "protocols"; | ||
34 | + protected static final String PORT = "port"; | ||
35 | + protected static final String DST_PORT = "destinationPort"; | ||
36 | + protected static final String SRC_PORT = "sourcePort"; | ||
37 | + protected static final String ICMP_TYPE = "icmpType"; | ||
38 | + protected static final String ICMP_CODE = "icmpCode"; | ||
39 | + protected static final String TCP_FLAG = "tcpFlag"; | ||
40 | + protected static final String PACKET_LENGTH = "packetLength"; | ||
41 | + protected static final String DSCP_VALUE = "dscpValue"; | ||
42 | + protected static final String FRAGMENT = "fragment"; | ||
43 | + | ||
44 | + protected static final String TRAFFIC_RATE = "trafficRate"; | ||
45 | + protected static final String TRAFFIC_ACTION = "trafficAction"; | ||
46 | + protected static final String TRAFFIC_REDIRECTION = "trafficRedirection"; | ||
47 | + protected static final String TRAFFIC_MARKING = "trafficMarking"; | ||
48 | + | ||
49 | + protected static final String TRAFFIC_RATE_ASN = "asn"; | ||
50 | + protected static final String TRAFFIC_RATE_RATE = "rate"; | ||
51 | + protected static final String TRAFFIC_ACTION_TERMINAL = "terminal"; | ||
52 | + protected static final String TRAFFIC_ACTION_SAMPLE = "sample"; | ||
53 | + protected static final String TRAFFIC_ACTION_RPD = "rpd"; | ||
54 | + | ||
55 | + protected static final String WIDE_COMM_FLAGS = "widecommunityFlags"; | ||
56 | + protected static final String WIDE_COMM_HOP_COUNT = "widecommunityHopCount"; | ||
57 | + protected static final String WIDE_COMM_COMMUNITY = "widecommunityCommunity"; | ||
58 | + protected static final String WIDE_COMM_CONTEXT_AS = "widecommunityContextAs"; | ||
59 | + protected static final String WIDE_COMM_LOCAL_AS = "widecommunityLocalAs"; | ||
60 | + protected static final String WIDE_COMM_TARGET = "widecommunityTarget"; | ||
61 | + protected static final String WIDE_COMM_EXT_TARGET = "widecommunityExtTarget"; | ||
62 | + protected static final String WIDE_COMM_PARAMETER = "widecommunityParameter"; | ||
63 | + | ||
64 | + protected static final String WIDE_COMM_TGT_LOCAL_SP = "localSpeaker"; | ||
65 | + protected static final String WIDE_COMM_TGT_REMOTE_SP = "remoteSpeaker"; | ||
66 | + | ||
67 | + @Override | ||
68 | + public ObjectNode encode(ExtFlowTypes flowTypes, CodecContext context) { | ||
69 | + return null; | ||
70 | + } | ||
71 | + | ||
72 | + @Override | ||
73 | + public ExtFlowTypes decode(ObjectNode json, CodecContext context) { | ||
74 | + DecodeBgpFlowExtnCodecHelper decoder = new DecodeBgpFlowExtnCodecHelper(json); | ||
75 | + return decoder.decode(); | ||
76 | + } | ||
77 | +} |
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.bgpweb.web; | ||
17 | + | ||
18 | +import org.onosproject.flowapi.ExtOperatorValue; | ||
19 | +import org.slf4j.Logger; | ||
20 | + | ||
21 | +import java.util.ArrayList; | ||
22 | +import java.util.List; | ||
23 | + | ||
24 | +import static org.slf4j.LoggerFactory.getLogger; | ||
25 | + | ||
26 | +public class BgpParseAttributes { | ||
27 | + | ||
28 | + private final Logger log = getLogger(getClass()); | ||
29 | + | ||
30 | + /** Bits as per flow spec rfc 5575.*/ | ||
31 | + final byte endBit = (byte) 0x80; | ||
32 | + final byte andBit = 0x40; | ||
33 | + final byte twoByteLen = (byte) (0x01 << 4); | ||
34 | + final byte fourByteLen = (byte) (0x02 << 4); | ||
35 | + final byte lessThan = 0x04; | ||
36 | + final byte greaterThan = 0x02; | ||
37 | + final byte equal = 0x01; | ||
38 | + | ||
39 | + /** Protocol types.*/ | ||
40 | + protected static final byte ICMP = 1; | ||
41 | + protected static final byte IGMP = 2; | ||
42 | + protected static final byte TCP = 6; | ||
43 | + protected static final byte UDP = 17; | ||
44 | + protected static final byte IPV4 = 4; | ||
45 | + protected static final byte IPV6 = 41; | ||
46 | + | ||
47 | + /** TCP Flags.*/ | ||
48 | + static final byte FIN = (1 << 0); | ||
49 | + static final byte SYN = (1 << 1); | ||
50 | + static final byte RST = (1 << 2); | ||
51 | + static final byte PSH = (1 << 3); | ||
52 | + static final byte ACK = (1 << 4); | ||
53 | + static final byte URG = (1 << 5); | ||
54 | + | ||
55 | + final byte notBit = 0x02; | ||
56 | + final byte matchBit = 0x01; | ||
57 | + | ||
58 | + /** Fragment Flags.*/ | ||
59 | + static final byte DF = (1 << 0); | ||
60 | + static final byte IF = (1 << 1); | ||
61 | + static final byte FF = (1 << 2); | ||
62 | + static final byte LF = (1 << 3); | ||
63 | + | ||
64 | + List<ExtOperatorValue> parsePort(String string) { | ||
65 | + List<ExtOperatorValue> operatorValue = null; | ||
66 | + | ||
67 | + operatorValue = createOperatorValue(string); | ||
68 | + | ||
69 | + return operatorValue; | ||
70 | + } | ||
71 | + | ||
72 | + List<ExtOperatorValue> parseIpProtocol(String string) { | ||
73 | + List<ExtOperatorValue> operatorValue = null; | ||
74 | + | ||
75 | + string = string.replaceAll("ICMP", Byte.valueOf(ICMP).toString()); | ||
76 | + string = string.replaceAll("icmp", Byte.valueOf(ICMP).toString()); | ||
77 | + string = string.replaceAll("IPv4", Byte.valueOf(IPV4).toString()); | ||
78 | + string = string.replaceAll("ipv4", Byte.valueOf(IPV4).toString()); | ||
79 | + string = string.replaceAll("TCP", Byte.valueOf(TCP).toString()); | ||
80 | + string = string.replaceAll("tcp", Byte.valueOf(TCP).toString()); | ||
81 | + string = string.replaceAll("UDP", Byte.valueOf(UDP).toString()); | ||
82 | + string = string.replaceAll("udp", Byte.valueOf(UDP).toString()); | ||
83 | + string = string.replaceAll("IPv6", Byte.valueOf(IPV6).toString()); | ||
84 | + string = string.replaceAll("ipv6", Byte.valueOf(IPV6).toString()); | ||
85 | + string = string.replaceAll("igmp", Byte.valueOf(IGMP).toString()); | ||
86 | + string = string.replaceAll("IGMP", Byte.valueOf(IGMP).toString()); | ||
87 | + | ||
88 | + operatorValue = createOperatorValue(string); | ||
89 | + | ||
90 | + return operatorValue; | ||
91 | + } | ||
92 | + | ||
93 | + List<ExtOperatorValue> parseIcmpType(String string) { | ||
94 | + List<ExtOperatorValue> operatorValue = null; | ||
95 | + | ||
96 | + operatorValue = createOperatorValue(string); | ||
97 | + | ||
98 | + return operatorValue; | ||
99 | + } | ||
100 | + | ||
101 | + List<ExtOperatorValue> parseIcmpCode(String string) { | ||
102 | + List<ExtOperatorValue> operatorValue = null; | ||
103 | + | ||
104 | + operatorValue = createOperatorValue(string); | ||
105 | + | ||
106 | + return operatorValue; | ||
107 | + } | ||
108 | + | ||
109 | + | ||
110 | + List<ExtOperatorValue> parseTcpFlags(String string) { | ||
111 | + List<ExtOperatorValue> operatorValue = new ArrayList<>(); | ||
112 | + Token token; | ||
113 | + int index = 0; | ||
114 | + | ||
115 | + string = string.replaceAll("FIN", Byte.valueOf(FIN).toString()); | ||
116 | + string = string.replaceAll("fin", Byte.valueOf(FIN).toString()); | ||
117 | + string = string.replaceAll("SYN", Byte.valueOf(SYN).toString()); | ||
118 | + string = string.replaceAll("syn", Byte.valueOf(SYN).toString()); | ||
119 | + string = string.replaceAll("RST", Byte.valueOf(RST).toString()); | ||
120 | + string = string.replaceAll("rst", Byte.valueOf(RST).toString()); | ||
121 | + string = string.replaceAll("PSH", Byte.valueOf(PSH).toString()); | ||
122 | + string = string.replaceAll("psh", Byte.valueOf(PSH).toString()); | ||
123 | + string = string.replaceAll("ACK", Byte.valueOf(ACK).toString()); | ||
124 | + string = string.replaceAll("ack", Byte.valueOf(ACK).toString()); | ||
125 | + string = string.replaceAll("URG", Byte.valueOf(URG).toString()); | ||
126 | + string = string.replaceAll("urg", Byte.valueOf(URG).toString()); | ||
127 | + | ||
128 | + do { | ||
129 | + token = parseTcpTokenValue(string, index); | ||
130 | + if (token.error) { | ||
131 | + log.error("Error in parsing the TCP value list"); | ||
132 | + return null; | ||
133 | + } | ||
134 | + operatorValue.add(new ExtOperatorValue(token.operator, token.value)); | ||
135 | + index = token.index; | ||
136 | + } while ((token.operator & endBit) != endBit); | ||
137 | + | ||
138 | + return operatorValue; | ||
139 | + } | ||
140 | + | ||
141 | + List<ExtOperatorValue> parsePacketLength(String string) { | ||
142 | + List<ExtOperatorValue> operatorValue = null; | ||
143 | + operatorValue = createOperatorValue(string); | ||
144 | + | ||
145 | + return operatorValue; | ||
146 | + } | ||
147 | + | ||
148 | + List<ExtOperatorValue> parseDscp(String string) { | ||
149 | + List<ExtOperatorValue> operatorValue = null; | ||
150 | + | ||
151 | + operatorValue = createOperatorValue(string); | ||
152 | + | ||
153 | + return operatorValue; | ||
154 | + } | ||
155 | + | ||
156 | + List<ExtOperatorValue> parseFragment(String string) { | ||
157 | + | ||
158 | + List<ExtOperatorValue> operatorValue = null; | ||
159 | + | ||
160 | + string = string.replaceAll("DF", Byte.valueOf(DF).toString()); | ||
161 | + string = string.replaceAll("df", Byte.valueOf(DF).toString()); | ||
162 | + string = string.replaceAll("IF", Byte.valueOf(IF).toString()); | ||
163 | + string = string.replaceAll("if", Byte.valueOf(IF).toString()); | ||
164 | + string = string.replaceAll("FF", Byte.valueOf(FF).toString()); | ||
165 | + string = string.replaceAll("ff", Byte.valueOf(FF).toString()); | ||
166 | + string = string.replaceAll("LF", Byte.valueOf(LF).toString()); | ||
167 | + string = string.replaceAll("lf", Byte.valueOf(LF).toString()); | ||
168 | + | ||
169 | + operatorValue = createOperatorValue(string); | ||
170 | + return operatorValue; | ||
171 | + } | ||
172 | + | ||
173 | + private class Token { | ||
174 | + byte operator; | ||
175 | + byte[] value; | ||
176 | + int index; | ||
177 | + boolean error; | ||
178 | + } | ||
179 | + | ||
180 | + List<ExtOperatorValue> createOperatorValue(String string) { | ||
181 | + List<ExtOperatorValue> operatorValue = new ArrayList<>(); | ||
182 | + Token token; | ||
183 | + int index = 0; | ||
184 | + | ||
185 | + do { | ||
186 | + token = parseMultiTokenValue(string, index); | ||
187 | + if (token.error) { | ||
188 | + log.error("Error in parsing the operator value list"); | ||
189 | + return null; | ||
190 | + } | ||
191 | + operatorValue.add(new ExtOperatorValue(token.operator, token.value)); | ||
192 | + index = token.index; | ||
193 | + } while ((token.operator & endBit) != endBit); | ||
194 | + | ||
195 | + return operatorValue; | ||
196 | + } | ||
197 | + | ||
198 | + | ||
199 | + Token parseMultiTokenValue(String str, int index) { | ||
200 | + Token token = new Token(); | ||
201 | + token.error = true; | ||
202 | + int number = 0; | ||
203 | + int cur = 0; | ||
204 | + byte operator = 0; | ||
205 | + boolean prevNumber = false; | ||
206 | + boolean bLess = false; | ||
207 | + boolean bGreater = false; | ||
208 | + boolean bAnd = false; | ||
209 | + boolean bEqual = false; | ||
210 | + | ||
211 | + while (str.length() > index) { | ||
212 | + | ||
213 | + switch (str.charAt(index)) { | ||
214 | + case '=': | ||
215 | + if (bEqual) { | ||
216 | + return token; | ||
217 | + } | ||
218 | + bEqual = true; | ||
219 | + if (prevNumber) { | ||
220 | + return windUp(str, index, number, operator); | ||
221 | + } | ||
222 | + operator = (byte) (operator | equal); | ||
223 | + break; | ||
224 | + case '>': | ||
225 | + if (bGreater) { | ||
226 | + return token; | ||
227 | + } | ||
228 | + bGreater = true; | ||
229 | + if (prevNumber) { | ||
230 | + return windUp(str, index, number, operator); | ||
231 | + } | ||
232 | + operator = (byte) (operator | greaterThan); | ||
233 | + break; | ||
234 | + case '<': | ||
235 | + if (bLess) { | ||
236 | + return token; | ||
237 | + } | ||
238 | + bLess = true; | ||
239 | + if (prevNumber) { | ||
240 | + return windUp(str, index, number, operator); | ||
241 | + } | ||
242 | + operator = (byte) (operator | lessThan); | ||
243 | + break; | ||
244 | + case '&': | ||
245 | + if (bAnd) { | ||
246 | + return token; | ||
247 | + } | ||
248 | + bAnd = true; | ||
249 | + if (prevNumber) { | ||
250 | + return windUp(str, index, number, operator); | ||
251 | + } | ||
252 | + operator = (byte) (operator | andBit); | ||
253 | + break; | ||
254 | + case '0': | ||
255 | + case '1': | ||
256 | + case '2': | ||
257 | + case '3': | ||
258 | + case '4': | ||
259 | + case '5': | ||
260 | + case '6': | ||
261 | + case '7': | ||
262 | + case '8': | ||
263 | + case '9': | ||
264 | + prevNumber = true; | ||
265 | + bLess = false; | ||
266 | + bGreater = false; | ||
267 | + bAnd = false; | ||
268 | + bEqual = false; | ||
269 | + cur = str.charAt(index); | ||
270 | + number = (number * 10) + cur - '0'; | ||
271 | + break; | ||
272 | + | ||
273 | + default: | ||
274 | + log.error("Error in parsing the token character" + str.charAt(index)); | ||
275 | + return token; | ||
276 | + } | ||
277 | + index++; | ||
278 | + } | ||
279 | + | ||
280 | + if (prevNumber) { | ||
281 | + return windUp(str, index, number, operator); | ||
282 | + } | ||
283 | + | ||
284 | + return token; | ||
285 | + } | ||
286 | + | ||
287 | + Token windUp(String str, int index, int number, byte operator) { | ||
288 | + Token token = new Token(); | ||
289 | + byte[] array = new byte[1]; | ||
290 | + | ||
291 | + if (str.length() == index) { | ||
292 | + operator = (byte) (operator | endBit); | ||
293 | + } | ||
294 | + | ||
295 | + if (number <= 255) { | ||
296 | + array[0] = (byte) number; | ||
297 | + } else if (number > 255 && number <= Short.MAX_VALUE) { | ||
298 | + operator = (byte) (operator | twoByteLen); | ||
299 | + array = shortToByteStream((short) number); | ||
300 | + } else if (number > Short.MAX_VALUE) { | ||
301 | + operator = (byte) (operator | fourByteLen); | ||
302 | + array = intToByteStream(number); | ||
303 | + } | ||
304 | + | ||
305 | + token.value = array; | ||
306 | + token.operator = operator; | ||
307 | + token.index = index; | ||
308 | + token.error = false; | ||
309 | + return token; | ||
310 | + } | ||
311 | + | ||
312 | + byte[] intToByteStream(int val) { | ||
313 | + return new byte[] { | ||
314 | + (byte) (val >>> 24), | ||
315 | + (byte) (val >>> 16), | ||
316 | + (byte) (val >>> 8), | ||
317 | + (byte) val}; | ||
318 | + } | ||
319 | + | ||
320 | + byte[] shortToByteStream(short val) { | ||
321 | + return new byte[] { | ||
322 | + (byte) (val >>> 8), | ||
323 | + (byte) val}; | ||
324 | + } | ||
325 | + | ||
326 | + Token parseTcpTokenValue(String str, int index) { | ||
327 | + Token token = new Token(); | ||
328 | + token.error = true; | ||
329 | + int number = 0; | ||
330 | + int cur = 0; | ||
331 | + byte operator = 0; | ||
332 | + boolean prevNumber = false; | ||
333 | + | ||
334 | + boolean bNotBit = false; | ||
335 | + boolean bAnd = false; | ||
336 | + boolean bMatchBit = false; | ||
337 | + | ||
338 | + while (str.length() > index) { | ||
339 | + | ||
340 | + switch (str.charAt(index)) { | ||
341 | + case '=': | ||
342 | + if (bMatchBit) { | ||
343 | + return token; | ||
344 | + } | ||
345 | + bMatchBit = true; | ||
346 | + if (prevNumber) { | ||
347 | + return windUp(str, index, number, operator); | ||
348 | + } | ||
349 | + operator = (byte) (operator | matchBit); | ||
350 | + break; | ||
351 | + case '!': | ||
352 | + if (bNotBit) { | ||
353 | + return token; | ||
354 | + } | ||
355 | + bNotBit = true; | ||
356 | + if (prevNumber) { | ||
357 | + return windUp(str, index, number, operator); | ||
358 | + } | ||
359 | + operator = (byte) (operator | notBit); | ||
360 | + break; | ||
361 | + case '&': | ||
362 | + if (bAnd) { | ||
363 | + return token; | ||
364 | + } | ||
365 | + bAnd = true; | ||
366 | + if (prevNumber) { | ||
367 | + return windUp(str, index, number, operator); | ||
368 | + } | ||
369 | + operator = (byte) (operator | andBit); | ||
370 | + break; | ||
371 | + case '0': | ||
372 | + case '1': | ||
373 | + case '2': | ||
374 | + case '3': | ||
375 | + case '4': | ||
376 | + case '5': | ||
377 | + case '6': | ||
378 | + case '7': | ||
379 | + case '8': | ||
380 | + case '9': | ||
381 | + prevNumber = true; | ||
382 | + bNotBit = false; | ||
383 | + bAnd = false; | ||
384 | + bMatchBit = false; | ||
385 | + cur = str.charAt(index); | ||
386 | + number = (number * 10) + cur - '0'; | ||
387 | + break; | ||
388 | + | ||
389 | + default: | ||
390 | + log.error("Error in parsing the TCP token character" + str.charAt(index)); | ||
391 | + return token; | ||
392 | + } | ||
393 | + index++; | ||
394 | + } | ||
395 | + | ||
396 | + if (prevNumber) { | ||
397 | + return windUp(str, index, number, operator); | ||
398 | + } | ||
399 | + | ||
400 | + return token; | ||
401 | + } | ||
402 | +} |
apps/bgpflowspec/bgpweb/src/main/java/org/onosproject/bgpweb/web/DecodeBgpFlowExtnCodecHelper.java
0 → 100755
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.bgpweb.web; | ||
17 | + | ||
18 | +import com.fasterxml.jackson.databind.JsonNode; | ||
19 | +import com.fasterxml.jackson.databind.node.ObjectNode; | ||
20 | +import org.onlab.packet.IpAddress; | ||
21 | +import org.onlab.packet.IpPrefix; | ||
22 | +import org.onosproject.flowapi.DefaultExtDscpValue; | ||
23 | +import org.onosproject.flowapi.DefaultExtFragment; | ||
24 | +import org.onosproject.flowapi.DefaultExtIcmpCode; | ||
25 | +import org.onosproject.flowapi.DefaultExtIcmpType; | ||
26 | +import org.onosproject.flowapi.DefaultExtIpProtocol; | ||
27 | +import org.onosproject.flowapi.DefaultExtKeyName; | ||
28 | +import org.onosproject.flowapi.DefaultExtPacketLength; | ||
29 | +import org.onosproject.flowapi.DefaultExtPort; | ||
30 | +import org.onosproject.flowapi.DefaultExtPrefix; | ||
31 | +import org.onosproject.flowapi.DefaultExtTarget; | ||
32 | +import org.onosproject.flowapi.DefaultExtTcpFlag; | ||
33 | +import org.onosproject.flowapi.DefaultExtTrafficAction; | ||
34 | +import org.onosproject.flowapi.DefaultExtTrafficMarking; | ||
35 | +import org.onosproject.flowapi.DefaultExtTrafficRate; | ||
36 | +import org.onosproject.flowapi.DefaultExtTrafficRedirect; | ||
37 | +import org.onosproject.flowapi.DefaultExtWideCommunityInt; | ||
38 | +import org.onosproject.flowapi.ExtDscpValue; | ||
39 | +import org.onosproject.flowapi.ExtFlowTypes; | ||
40 | +import org.onosproject.flowapi.ExtFragment; | ||
41 | +import org.onosproject.flowapi.ExtIcmpCode; | ||
42 | +import org.onosproject.flowapi.ExtIcmpType; | ||
43 | +import org.onosproject.flowapi.ExtIpProtocol; | ||
44 | +import org.onosproject.flowapi.ExtKeyName; | ||
45 | +import org.onosproject.flowapi.ExtPacketLength; | ||
46 | +import org.onosproject.flowapi.ExtPort; | ||
47 | +import org.onosproject.flowapi.ExtPrefix; | ||
48 | +import org.onosproject.flowapi.ExtTarget; | ||
49 | +import org.onosproject.flowapi.ExtTcpFlag; | ||
50 | +import org.onosproject.flowapi.ExtTrafficAction; | ||
51 | +import org.onosproject.flowapi.ExtTrafficMarking; | ||
52 | +import org.onosproject.flowapi.ExtTrafficRate; | ||
53 | +import org.onosproject.flowapi.ExtTrafficRedirect; | ||
54 | +import org.onosproject.flowapi.ExtWideCommunityInt; | ||
55 | + | ||
56 | +import java.util.HashMap; | ||
57 | +import java.util.Iterator; | ||
58 | +import java.util.Map; | ||
59 | + | ||
60 | +import static org.onlab.util.Tools.nullIsIllegal; | ||
61 | + | ||
62 | +/** | ||
63 | + * Decode the Ext extension codec. | ||
64 | + */ | ||
65 | +public final class DecodeBgpFlowExtnCodecHelper { | ||
66 | + | ||
67 | + private final ObjectNode json; | ||
68 | + | ||
69 | + protected static final String MISSING_MEMBER_MESSAGE = | ||
70 | + " member is required in ExtTypes"; | ||
71 | + | ||
72 | + protected static final String MALFORMED_MEMBER_MESSAGE = | ||
73 | + " member is malformed"; | ||
74 | + | ||
75 | + private interface ExtensionDecoder { | ||
76 | + ExtFlowTypes decodeExtension(ObjectNode json); | ||
77 | + } | ||
78 | + | ||
79 | + private final Map<String, ExtensionDecoder> decoderMap; | ||
80 | + | ||
81 | + BgpParseAttributes parse = new BgpParseAttributes(); | ||
82 | + | ||
83 | + /** | ||
84 | + * Creates a decode extension codec object. | ||
85 | + * Initializes the lookup map for Bgp extension types. | ||
86 | + * | ||
87 | + * @param json JSON object to decode | ||
88 | + */ | ||
89 | + public DecodeBgpFlowExtnCodecHelper(ObjectNode json) { | ||
90 | + this.json = json; | ||
91 | + decoderMap = new HashMap<>(); | ||
92 | + | ||
93 | + decoderMap.put(ExtFlowTypes.ExtType.IPV4_SRC_PFX.name(), new BgpSourcePrefixDecode()); | ||
94 | + decoderMap.put(ExtFlowTypes.ExtType.IPV4_DST_PFX.name(), new BgpDestinationPrefixDecode()); | ||
95 | + decoderMap.put(ExtFlowTypes.ExtType.EXT_FLOW_RULE_KEY.name(), new BgpFlowRuleKeyDecode()); | ||
96 | + decoderMap.put(ExtFlowTypes.ExtType.IP_PROTO_LIST.name(), new BgpIpProtocolDecode()); | ||
97 | + decoderMap.put(ExtFlowTypes.ExtType.IN_PORT_LIST.name(), new BgpInPortDecode()); | ||
98 | + decoderMap.put(ExtFlowTypes.ExtType.DST_PORT_LIST.name(), new BgpDestinationPortDecode()); | ||
99 | + decoderMap.put(ExtFlowTypes.ExtType.SRC_PORT_LIST.name(), new BgpSourcePortDecode()); | ||
100 | + decoderMap.put(ExtFlowTypes.ExtType.ICMP_TYPE_LIST.name(), new BgpIcmpTypeDecode()); | ||
101 | + decoderMap.put(ExtFlowTypes.ExtType.ICMP_CODE_LIST.name(), new BgpIcmpCodeDecode()); | ||
102 | + decoderMap.put(ExtFlowTypes.ExtType.TCP_FLAG_LIST.name(), new BgpTcpFlagDecode()); | ||
103 | + decoderMap.put(ExtFlowTypes.ExtType.PACKET_LENGTH_LIST.name(), new BgpPacketLengthDecode()); | ||
104 | + decoderMap.put(ExtFlowTypes.ExtType.DSCP_VALUE_LIST.name(), new BgpDscpValueDecode()); | ||
105 | + decoderMap.put(ExtFlowTypes.ExtType.FRAGMENT_LIST.name(), new BgpFragmentDecode()); | ||
106 | + | ||
107 | + decoderMap.put(ExtFlowTypes.ExtType.TRAFFIC_RATE.name(), new BgpTrafficRateDecode()); | ||
108 | + decoderMap.put(ExtFlowTypes.ExtType.TRAFFIC_ACTION.name(), new BgpTrafficActionDecode()); | ||
109 | + decoderMap.put(ExtFlowTypes.ExtType.TRAFFIC_REDIRECT.name(), new BgpTrafficRedirectDecode()); | ||
110 | + decoderMap.put(ExtFlowTypes.ExtType.TRAFFIC_MARKING.name(), new BgpTrafficMarkingDecode()); | ||
111 | + | ||
112 | + decoderMap.put(ExtFlowTypes.ExtType.WIDE_COMM_FLAGS.name(), new BgpWcommFlagsDecode()); | ||
113 | + decoderMap.put(ExtFlowTypes.ExtType.WIDE_COMM_HOP_COUNT.name(), new BgpWcommHopCountDecode()); | ||
114 | + decoderMap.put(ExtFlowTypes.ExtType.WIDE_COMM_COMMUNITY.name(), new BgpWcommCommunityDecode()); | ||
115 | + decoderMap.put(ExtFlowTypes.ExtType.WIDE_COMM_CONTEXT_AS.name(), new BgpWcommContextAsDecode()); | ||
116 | + decoderMap.put(ExtFlowTypes.ExtType.WIDE_COMM_LOCAL_AS.name(), new BgpWcommLocalAsDecode()); | ||
117 | + decoderMap.put(ExtFlowTypes.ExtType.WIDE_COMM_TARGET.name(), new BgpWcommTargetDecode()); | ||
118 | + decoderMap.put(ExtFlowTypes.ExtType.WIDE_COMM_EXT_TARGET.name(), new BgpWcommExtTargetDecode()); | ||
119 | + decoderMap.put(ExtFlowTypes.ExtType.WIDE_COMM_PARAMETER.name(), new BgpWcommParameterDecode()); | ||
120 | + } | ||
121 | + | ||
122 | + /** Source prefix decoder.*/ | ||
123 | + private class BgpSourcePrefixDecode implements ExtensionDecoder { | ||
124 | + @Override | ||
125 | + public ExtFlowTypes decodeExtension(ObjectNode json) { | ||
126 | + if (json == null || !json.isObject()) { | ||
127 | + return null; | ||
128 | + } | ||
129 | + | ||
130 | + ExtPrefix.Builder resultBuilder = new DefaultExtPrefix.Builder(); | ||
131 | + | ||
132 | + String ip = nullIsIllegal(json.get(BgpFlowExtensionCodec.PREFIX), | ||
133 | + BgpFlowExtensionCodec.PREFIX + MISSING_MEMBER_MESSAGE).asText(); | ||
134 | + resultBuilder.setPrefix(IpPrefix.valueOf(ip)); | ||
135 | + resultBuilder.setType(ExtFlowTypes.ExtType.IPV4_SRC_PFX); | ||
136 | + | ||
137 | + return resultBuilder.build(); | ||
138 | + } | ||
139 | + } | ||
140 | + | ||
141 | + /** Destination prefix decoder.*/ | ||
142 | + private class BgpDestinationPrefixDecode implements ExtensionDecoder { | ||
143 | + @Override | ||
144 | + public ExtFlowTypes decodeExtension(ObjectNode json) { | ||
145 | + if (json == null || !json.isObject()) { | ||
146 | + return null; | ||
147 | + } | ||
148 | + | ||
149 | + ExtPrefix.Builder resultBuilder = new DefaultExtPrefix.Builder(); | ||
150 | + | ||
151 | + String ip = nullIsIllegal(json.get(BgpFlowExtensionCodec.PREFIX), | ||
152 | + BgpFlowExtensionCodec.PREFIX + MISSING_MEMBER_MESSAGE).asText(); | ||
153 | + resultBuilder.setPrefix(IpPrefix.valueOf(ip)); | ||
154 | + resultBuilder.setType(ExtFlowTypes.ExtType.IPV4_DST_PFX); | ||
155 | + | ||
156 | + return resultBuilder.build(); | ||
157 | + } | ||
158 | + } | ||
159 | + | ||
160 | + /** Flow rule key decoder.*/ | ||
161 | + private class BgpFlowRuleKeyDecode implements ExtensionDecoder { | ||
162 | + @Override | ||
163 | + public ExtFlowTypes decodeExtension(ObjectNode json) { | ||
164 | + if (json == null || !json.isObject()) { | ||
165 | + return null; | ||
166 | + } | ||
167 | + | ||
168 | + ExtKeyName.Builder resultBuilder = new DefaultExtKeyName.Builder(); | ||
169 | + | ||
170 | + String name = nullIsIllegal(json.get(BgpFlowExtensionCodec.NAME), | ||
171 | + BgpFlowExtensionCodec.NAME + MISSING_MEMBER_MESSAGE).asText(); | ||
172 | + resultBuilder.setKeyName(name); | ||
173 | + resultBuilder.setType(ExtFlowTypes.ExtType.EXT_FLOW_RULE_KEY); | ||
174 | + | ||
175 | + return resultBuilder.build(); | ||
176 | + } | ||
177 | + } | ||
178 | + | ||
179 | + /** Ip protocol decoder.*/ | ||
180 | + private class BgpIpProtocolDecode implements ExtensionDecoder { | ||
181 | + @Override | ||
182 | + public ExtFlowTypes decodeExtension(ObjectNode json) { | ||
183 | + if (json == null || !json.isObject()) { | ||
184 | + return null; | ||
185 | + } | ||
186 | + | ||
187 | + ExtIpProtocol.Builder resultBuilder = new DefaultExtIpProtocol.Builder(); | ||
188 | + | ||
189 | + String protocols = nullIsIllegal(json.get(BgpFlowExtensionCodec.PROTOCOLS), | ||
190 | + BgpFlowExtensionCodec.PROTOCOLS + MISSING_MEMBER_MESSAGE).asText(); | ||
191 | + resultBuilder.setIpProtocol(parse.parseIpProtocol(protocols)); | ||
192 | + resultBuilder.setType(ExtFlowTypes.ExtType.IP_PROTO_LIST); | ||
193 | + | ||
194 | + return resultBuilder.build(); | ||
195 | + } | ||
196 | + } | ||
197 | + | ||
198 | + /** In port decoder.*/ | ||
199 | + private class BgpInPortDecode implements ExtensionDecoder { | ||
200 | + @Override | ||
201 | + public ExtFlowTypes decodeExtension(ObjectNode json) { | ||
202 | + if (json == null || !json.isObject()) { | ||
203 | + return null; | ||
204 | + } | ||
205 | + | ||
206 | + ExtPort.Builder resultBuilder = new DefaultExtPort.Builder(); | ||
207 | + | ||
208 | + String portList = nullIsIllegal(json.get(BgpFlowExtensionCodec.PORT), | ||
209 | + BgpFlowExtensionCodec.PORT + MISSING_MEMBER_MESSAGE).asText(); | ||
210 | + resultBuilder.setPort(parse.parsePort(portList)); | ||
211 | + resultBuilder.setType(ExtFlowTypes.ExtType.IN_PORT_LIST); | ||
212 | + | ||
213 | + return resultBuilder.build(); | ||
214 | + } | ||
215 | + } | ||
216 | + | ||
217 | + /** Destination decoder.*/ | ||
218 | + private class BgpDestinationPortDecode implements ExtensionDecoder { | ||
219 | + @Override | ||
220 | + public ExtFlowTypes decodeExtension(ObjectNode json) { | ||
221 | + if (json == null || !json.isObject()) { | ||
222 | + return null; | ||
223 | + } | ||
224 | + | ||
225 | + ExtPort.Builder resultBuilder = new DefaultExtPort.Builder(); | ||
226 | + | ||
227 | + String portList = nullIsIllegal(json.get(BgpFlowExtensionCodec.DST_PORT), | ||
228 | + BgpFlowExtensionCodec.DST_PORT + MISSING_MEMBER_MESSAGE).asText(); | ||
229 | + resultBuilder.setPort(parse.parsePort(portList)); | ||
230 | + resultBuilder.setType(ExtFlowTypes.ExtType.DST_PORT_LIST); | ||
231 | + | ||
232 | + return resultBuilder.build(); | ||
233 | + } | ||
234 | + } | ||
235 | + | ||
236 | + /** Source decoder.*/ | ||
237 | + private class BgpSourcePortDecode implements ExtensionDecoder { | ||
238 | + @Override | ||
239 | + public ExtFlowTypes decodeExtension(ObjectNode json) { | ||
240 | + if (json == null || !json.isObject()) { | ||
241 | + return null; | ||
242 | + } | ||
243 | + | ||
244 | + ExtPort.Builder resultBuilder = new DefaultExtPort.Builder(); | ||
245 | + | ||
246 | + String portList = nullIsIllegal(json.get(BgpFlowExtensionCodec.SRC_PORT), | ||
247 | + BgpFlowExtensionCodec.SRC_PORT + MISSING_MEMBER_MESSAGE).asText(); | ||
248 | + resultBuilder.setPort(parse.parsePort(portList)); | ||
249 | + resultBuilder.setType(ExtFlowTypes.ExtType.SRC_PORT_LIST); | ||
250 | + | ||
251 | + return resultBuilder.build(); | ||
252 | + } | ||
253 | + } | ||
254 | + | ||
255 | + /** Icmp type decoder.*/ | ||
256 | + private class BgpIcmpTypeDecode implements ExtensionDecoder { | ||
257 | + @Override | ||
258 | + public ExtFlowTypes decodeExtension(ObjectNode json) { | ||
259 | + if (json == null || !json.isObject()) { | ||
260 | + return null; | ||
261 | + } | ||
262 | + | ||
263 | + ExtIcmpType.Builder resultBuilder = new DefaultExtIcmpType.Builder(); | ||
264 | + | ||
265 | + String icmpType = nullIsIllegal(json.get(BgpFlowExtensionCodec.ICMP_TYPE), | ||
266 | + BgpFlowExtensionCodec.ICMP_TYPE + MISSING_MEMBER_MESSAGE).asText(); | ||
267 | + resultBuilder.setIcmpType(parse.parseIcmpType(icmpType)); | ||
268 | + resultBuilder.setType(ExtFlowTypes.ExtType.ICMP_TYPE_LIST); | ||
269 | + | ||
270 | + return resultBuilder.build(); | ||
271 | + } | ||
272 | + } | ||
273 | + | ||
274 | + /** Icmp code decoder.*/ | ||
275 | + private class BgpIcmpCodeDecode implements ExtensionDecoder { | ||
276 | + @Override | ||
277 | + public ExtFlowTypes decodeExtension(ObjectNode json) { | ||
278 | + if (json == null || !json.isObject()) { | ||
279 | + return null; | ||
280 | + } | ||
281 | + | ||
282 | + ExtIcmpCode.Builder resultBuilder = new DefaultExtIcmpCode.Builder(); | ||
283 | + | ||
284 | + String icmpCode = nullIsIllegal(json.get(BgpFlowExtensionCodec.ICMP_CODE), | ||
285 | + BgpFlowExtensionCodec.ICMP_CODE + MISSING_MEMBER_MESSAGE).asText(); | ||
286 | + resultBuilder.setIcmpCode(parse.parseIcmpCode(icmpCode)); | ||
287 | + resultBuilder.setType(ExtFlowTypes.ExtType.ICMP_CODE_LIST); | ||
288 | + | ||
289 | + return resultBuilder.build(); | ||
290 | + } | ||
291 | + } | ||
292 | + | ||
293 | + /** Tcp flag decoder.*/ | ||
294 | + private class BgpTcpFlagDecode implements ExtensionDecoder { | ||
295 | + @Override | ||
296 | + public ExtFlowTypes decodeExtension(ObjectNode json) { | ||
297 | + if (json == null || !json.isObject()) { | ||
298 | + return null; | ||
299 | + } | ||
300 | + | ||
301 | + ExtTcpFlag.Builder resultBuilder = new DefaultExtTcpFlag.Builder(); | ||
302 | + | ||
303 | + String tcpFlag = nullIsIllegal(json.get(BgpFlowExtensionCodec.TCP_FLAG), | ||
304 | + BgpFlowExtensionCodec.TCP_FLAG + MISSING_MEMBER_MESSAGE).asText(); | ||
305 | + resultBuilder.setTcpFlag(parse.parseTcpFlags(tcpFlag)); | ||
306 | + resultBuilder.setType(ExtFlowTypes.ExtType.TCP_FLAG_LIST); | ||
307 | + | ||
308 | + return resultBuilder.build(); | ||
309 | + } | ||
310 | + } | ||
311 | + | ||
312 | + /** Packet length decoder.*/ | ||
313 | + private class BgpPacketLengthDecode implements ExtensionDecoder { | ||
314 | + @Override | ||
315 | + public ExtFlowTypes decodeExtension(ObjectNode json) { | ||
316 | + if (json == null || !json.isObject()) { | ||
317 | + return null; | ||
318 | + } | ||
319 | + | ||
320 | + ExtPacketLength.Builder resultBuilder = new DefaultExtPacketLength.Builder(); | ||
321 | + | ||
322 | + String packetLength = nullIsIllegal(json.get(BgpFlowExtensionCodec.PACKET_LENGTH), | ||
323 | + BgpFlowExtensionCodec.PACKET_LENGTH + MISSING_MEMBER_MESSAGE).asText(); | ||
324 | + resultBuilder.setPacketLength(parse.parsePacketLength(packetLength)); | ||
325 | + resultBuilder.setType(ExtFlowTypes.ExtType.PACKET_LENGTH_LIST); | ||
326 | + | ||
327 | + return resultBuilder.build(); | ||
328 | + } | ||
329 | + } | ||
330 | + | ||
331 | + /** Dscp value decoder.*/ | ||
332 | + private class BgpDscpValueDecode implements ExtensionDecoder { | ||
333 | + @Override | ||
334 | + public ExtFlowTypes decodeExtension(ObjectNode json) { | ||
335 | + if (json == null || !json.isObject()) { | ||
336 | + return null; | ||
337 | + } | ||
338 | + | ||
339 | + ExtDscpValue.Builder resultBuilder = new DefaultExtDscpValue.Builder(); | ||
340 | + | ||
341 | + String dscpValue = nullIsIllegal(json.get(BgpFlowExtensionCodec.DSCP_VALUE), | ||
342 | + BgpFlowExtensionCodec.DSCP_VALUE + MISSING_MEMBER_MESSAGE).asText(); | ||
343 | + resultBuilder.setDscpValue(parse.parseDscp(dscpValue)); | ||
344 | + resultBuilder.setType(ExtFlowTypes.ExtType.DSCP_VALUE_LIST); | ||
345 | + | ||
346 | + return resultBuilder.build(); | ||
347 | + } | ||
348 | + } | ||
349 | + | ||
350 | + /** Fragment decoder.*/ | ||
351 | + private class BgpFragmentDecode implements ExtensionDecoder { | ||
352 | + @Override | ||
353 | + public ExtFlowTypes decodeExtension(ObjectNode json) { | ||
354 | + if (json == null || !json.isObject()) { | ||
355 | + return null; | ||
356 | + } | ||
357 | + | ||
358 | + ExtFragment.Builder resultBuilder = new DefaultExtFragment.Builder(); | ||
359 | + | ||
360 | + String fragment = nullIsIllegal(json.get(BgpFlowExtensionCodec.FRAGMENT), | ||
361 | + BgpFlowExtensionCodec.FRAGMENT + MISSING_MEMBER_MESSAGE).asText(); | ||
362 | + resultBuilder.setFragment(parse.parseFragment(fragment)); | ||
363 | + resultBuilder.setType(ExtFlowTypes.ExtType.FRAGMENT_LIST); | ||
364 | + | ||
365 | + return resultBuilder.build(); | ||
366 | + } | ||
367 | + } | ||
368 | + | ||
369 | + /** Traffic rate decoder.*/ | ||
370 | + private class BgpTrafficRateDecode implements ExtensionDecoder { | ||
371 | + @Override | ||
372 | + public ExtFlowTypes decodeExtension(ObjectNode json) { | ||
373 | + if (json == null || !json.isObject()) { | ||
374 | + return null; | ||
375 | + } | ||
376 | + | ||
377 | + ExtTrafficRate.Builder resultBuilder = new DefaultExtTrafficRate.Builder(); | ||
378 | + | ||
379 | + String rate = nullIsIllegal(json.get(BgpFlowExtensionCodec.TRAFFIC_RATE), | ||
380 | + BgpFlowExtensionCodec.TRAFFIC_RATE + MISSING_MEMBER_MESSAGE).asText(); | ||
381 | + | ||
382 | + String[] commaPart = rate.split(","); | ||
383 | + String[] valuePart = commaPart[0].split("="); | ||
384 | + | ||
385 | + if (valuePart[0].matches(BgpFlowExtensionCodec.TRAFFIC_RATE_ASN)) { | ||
386 | + short s = Short.decode(valuePart[1].trim()).shortValue(); | ||
387 | + resultBuilder.setAsn(s); | ||
388 | + } else { | ||
389 | + nullIsIllegal(valuePart[0], BgpFlowExtensionCodec.TRAFFIC_RATE + MALFORMED_MEMBER_MESSAGE); | ||
390 | + } | ||
391 | + | ||
392 | + valuePart = commaPart[1].split("="); | ||
393 | + if (valuePart[0].matches(BgpFlowExtensionCodec.TRAFFIC_RATE_RATE)) { | ||
394 | + float f = Float.parseFloat(valuePart[1].trim()); | ||
395 | + resultBuilder.setRate(f); | ||
396 | + } else { | ||
397 | + nullIsIllegal(valuePart[0], BgpFlowExtensionCodec.TRAFFIC_RATE + MALFORMED_MEMBER_MESSAGE); | ||
398 | + } | ||
399 | + | ||
400 | + resultBuilder.setType(ExtFlowTypes.ExtType.TRAFFIC_RATE); | ||
401 | + | ||
402 | + return resultBuilder.build(); | ||
403 | + } | ||
404 | + } | ||
405 | + | ||
406 | + /** Traffic action decoder.*/ | ||
407 | + private class BgpTrafficActionDecode implements ExtensionDecoder { | ||
408 | + @Override | ||
409 | + public ExtFlowTypes decodeExtension(ObjectNode json) { | ||
410 | + if (json == null || !json.isObject()) { | ||
411 | + return null; | ||
412 | + } | ||
413 | + | ||
414 | + ExtTrafficAction.Builder resultBuilder = new DefaultExtTrafficAction.Builder(); | ||
415 | + | ||
416 | + String rate = nullIsIllegal(json.get(BgpFlowExtensionCodec.TRAFFIC_ACTION), | ||
417 | + BgpFlowExtensionCodec.TRAFFIC_ACTION + MISSING_MEMBER_MESSAGE).asText(); | ||
418 | + | ||
419 | + String[] commaPart = rate.split(","); | ||
420 | + String[] valuePart = commaPart[0].split("="); | ||
421 | + | ||
422 | + if (valuePart[0].matches(BgpFlowExtensionCodec.TRAFFIC_ACTION_TERMINAL)) { | ||
423 | + boolean terminal = Boolean.parseBoolean(valuePart[1].trim()); | ||
424 | + resultBuilder.setTerminal(terminal); | ||
425 | + } else { | ||
426 | + nullIsIllegal(valuePart[0], BgpFlowExtensionCodec.TRAFFIC_ACTION_TERMINAL + MISSING_MEMBER_MESSAGE); | ||
427 | + } | ||
428 | + | ||
429 | + valuePart = commaPart[1].split("="); | ||
430 | + if (valuePart[0].matches(BgpFlowExtensionCodec.TRAFFIC_ACTION_SAMPLE)) { | ||
431 | + boolean sample = Boolean.parseBoolean(valuePart[1].trim()); | ||
432 | + resultBuilder.setSample(sample); | ||
433 | + } else { | ||
434 | + nullIsIllegal(valuePart[0], BgpFlowExtensionCodec.TRAFFIC_ACTION_SAMPLE + MISSING_MEMBER_MESSAGE); | ||
435 | + } | ||
436 | + | ||
437 | + valuePart = commaPart[2].split("="); | ||
438 | + if (valuePart[0].matches(BgpFlowExtensionCodec.TRAFFIC_ACTION_RPD)) { | ||
439 | + boolean rpd = Boolean.parseBoolean(valuePart[1].trim()); | ||
440 | + resultBuilder.setRpd(rpd); | ||
441 | + } else { | ||
442 | + nullIsIllegal(valuePart[0], BgpFlowExtensionCodec.TRAFFIC_ACTION_RPD + MISSING_MEMBER_MESSAGE); | ||
443 | + } | ||
444 | + | ||
445 | + resultBuilder.setType(ExtFlowTypes.ExtType.TRAFFIC_ACTION); | ||
446 | + | ||
447 | + return resultBuilder.build(); | ||
448 | + } | ||
449 | + } | ||
450 | + | ||
451 | + /** Traffic redirect decoder.*/ | ||
452 | + private class BgpTrafficRedirectDecode implements ExtensionDecoder { | ||
453 | + @Override | ||
454 | + public ExtFlowTypes decodeExtension(ObjectNode json) { | ||
455 | + if (json == null || !json.isObject()) { | ||
456 | + return null; | ||
457 | + } | ||
458 | + | ||
459 | + ExtTrafficRedirect.Builder resultBuilder = new DefaultExtTrafficRedirect.Builder(); | ||
460 | + | ||
461 | + String action = nullIsIllegal(json.get(BgpFlowExtensionCodec.TRAFFIC_REDIRECTION), | ||
462 | + BgpFlowExtensionCodec.TRAFFIC_REDIRECTION + MISSING_MEMBER_MESSAGE).asText(); | ||
463 | + resultBuilder.setRedirect(action); | ||
464 | + resultBuilder.setType(ExtFlowTypes.ExtType.TRAFFIC_REDIRECT); | ||
465 | + | ||
466 | + return resultBuilder.build(); | ||
467 | + } | ||
468 | + } | ||
469 | + | ||
470 | + /** Traffic marking decoder.*/ | ||
471 | + private class BgpTrafficMarkingDecode implements ExtensionDecoder { | ||
472 | + @Override | ||
473 | + public ExtFlowTypes decodeExtension(ObjectNode json) { | ||
474 | + if (json == null || !json.isObject()) { | ||
475 | + return null; | ||
476 | + } | ||
477 | + | ||
478 | + ExtTrafficMarking.Builder resultBuilder = new DefaultExtTrafficMarking.Builder(); | ||
479 | + | ||
480 | + String action = nullIsIllegal(json.get(BgpFlowExtensionCodec.TRAFFIC_MARKING), | ||
481 | + BgpFlowExtensionCodec.TRAFFIC_MARKING + MISSING_MEMBER_MESSAGE).asText(); | ||
482 | + | ||
483 | + if ((action.length() != 1) || action.isEmpty()) { | ||
484 | + nullIsIllegal(action, BgpFlowExtensionCodec.TRAFFIC_MARKING + MALFORMED_MEMBER_MESSAGE); | ||
485 | + } | ||
486 | + | ||
487 | + resultBuilder.setMarking((byte) action.charAt(0)); | ||
488 | + resultBuilder.setType(ExtFlowTypes.ExtType.TRAFFIC_MARKING); | ||
489 | + | ||
490 | + return resultBuilder.build(); | ||
491 | + } | ||
492 | + } | ||
493 | + | ||
494 | + /** Wide community flag decoder.*/ | ||
495 | + private class BgpWcommFlagsDecode implements ExtensionDecoder { | ||
496 | + @Override | ||
497 | + public ExtFlowTypes decodeExtension(ObjectNode json) { | ||
498 | + if (json == null || !json.isObject()) { | ||
499 | + return null; | ||
500 | + } | ||
501 | + | ||
502 | + ExtWideCommunityInt.Builder resultBuilder = new DefaultExtWideCommunityInt.Builder(); | ||
503 | + | ||
504 | + String wideComm = nullIsIllegal(json.get(BgpFlowExtensionCodec.WIDE_COMM_FLAGS), | ||
505 | + BgpFlowExtensionCodec.WIDE_COMM_FLAGS + MISSING_MEMBER_MESSAGE).asText(); | ||
506 | + resultBuilder.setwCommInt(Integer.valueOf(wideComm)); | ||
507 | + resultBuilder.setType(ExtFlowTypes.ExtType.WIDE_COMM_FLAGS); | ||
508 | + | ||
509 | + return resultBuilder.build(); | ||
510 | + } | ||
511 | + } | ||
512 | + | ||
513 | + /** Wide community hop count decoder.*/ | ||
514 | + private class BgpWcommHopCountDecode implements ExtensionDecoder { | ||
515 | + @Override | ||
516 | + public ExtFlowTypes decodeExtension(ObjectNode json) { | ||
517 | + if (json == null || !json.isObject()) { | ||
518 | + return null; | ||
519 | + } | ||
520 | + | ||
521 | + ExtWideCommunityInt.Builder resultBuilder = new DefaultExtWideCommunityInt.Builder(); | ||
522 | + | ||
523 | + String wideComm = nullIsIllegal(json.get(BgpFlowExtensionCodec.WIDE_COMM_HOP_COUNT), | ||
524 | + BgpFlowExtensionCodec.WIDE_COMM_HOP_COUNT + MISSING_MEMBER_MESSAGE).asText(); | ||
525 | + resultBuilder.setwCommInt(Integer.valueOf(wideComm)); | ||
526 | + resultBuilder.setType(ExtFlowTypes.ExtType.WIDE_COMM_HOP_COUNT); | ||
527 | + | ||
528 | + return resultBuilder.build(); | ||
529 | + } | ||
530 | + } | ||
531 | + | ||
532 | + /** Wide community decoder.*/ | ||
533 | + private class BgpWcommCommunityDecode implements ExtensionDecoder { | ||
534 | + @Override | ||
535 | + public ExtFlowTypes decodeExtension(ObjectNode json) { | ||
536 | + if (json == null || !json.isObject()) { | ||
537 | + return null; | ||
538 | + } | ||
539 | + | ||
540 | + ExtWideCommunityInt.Builder resultBuilder = new DefaultExtWideCommunityInt.Builder(); | ||
541 | + | ||
542 | + String wideComm = nullIsIllegal(json.get(BgpFlowExtensionCodec.WIDE_COMM_COMMUNITY), | ||
543 | + BgpFlowExtensionCodec.WIDE_COMM_COMMUNITY + MISSING_MEMBER_MESSAGE).asText(); | ||
544 | + resultBuilder.setwCommInt(Integer.valueOf(wideComm)); | ||
545 | + resultBuilder.setType(ExtFlowTypes.ExtType.WIDE_COMM_COMMUNITY); | ||
546 | + | ||
547 | + return resultBuilder.build(); | ||
548 | + } | ||
549 | + } | ||
550 | + | ||
551 | + /** Wide community context AS decoder.*/ | ||
552 | + private class BgpWcommContextAsDecode implements ExtensionDecoder { | ||
553 | + @Override | ||
554 | + public ExtFlowTypes decodeExtension(ObjectNode json) { | ||
555 | + if (json == null || !json.isObject()) { | ||
556 | + return null; | ||
557 | + } | ||
558 | + | ||
559 | + ExtWideCommunityInt.Builder resultBuilder = new DefaultExtWideCommunityInt.Builder(); | ||
560 | + | ||
561 | + String wideComm = nullIsIllegal(json.get(BgpFlowExtensionCodec.WIDE_COMM_CONTEXT_AS), | ||
562 | + BgpFlowExtensionCodec.WIDE_COMM_CONTEXT_AS + MISSING_MEMBER_MESSAGE).asText(); | ||
563 | + resultBuilder.setwCommInt(Integer.valueOf(wideComm)); | ||
564 | + resultBuilder.setType(ExtFlowTypes.ExtType.WIDE_COMM_CONTEXT_AS); | ||
565 | + | ||
566 | + return resultBuilder.build(); | ||
567 | + } | ||
568 | + } | ||
569 | + | ||
570 | + /** Wide community local AS decoder.*/ | ||
571 | + private class BgpWcommLocalAsDecode implements ExtensionDecoder { | ||
572 | + @Override | ||
573 | + public ExtFlowTypes decodeExtension(ObjectNode json) { | ||
574 | + if (json == null || !json.isObject()) { | ||
575 | + return null; | ||
576 | + } | ||
577 | + | ||
578 | + ExtWideCommunityInt.Builder resultBuilder = new DefaultExtWideCommunityInt.Builder(); | ||
579 | + | ||
580 | + String wideComm = nullIsIllegal(json.get(BgpFlowExtensionCodec.WIDE_COMM_LOCAL_AS), | ||
581 | + BgpFlowExtensionCodec.WIDE_COMM_LOCAL_AS + MISSING_MEMBER_MESSAGE).asText(); | ||
582 | + resultBuilder.setwCommInt(Integer.valueOf(wideComm)); | ||
583 | + resultBuilder.setType(ExtFlowTypes.ExtType.WIDE_COMM_LOCAL_AS); | ||
584 | + | ||
585 | + return resultBuilder.build(); | ||
586 | + } | ||
587 | + } | ||
588 | + | ||
589 | + /** Wide community parameter decoder.*/ | ||
590 | + private class BgpWcommParameterDecode implements ExtensionDecoder { | ||
591 | + @Override | ||
592 | + public ExtFlowTypes decodeExtension(ObjectNode json) { | ||
593 | + if (json == null || !json.isObject()) { | ||
594 | + return null; | ||
595 | + } | ||
596 | + | ||
597 | + ExtWideCommunityInt.Builder resultBuilder = new DefaultExtWideCommunityInt.Builder(); | ||
598 | + | ||
599 | + String wideComm = nullIsIllegal(json.get(BgpFlowExtensionCodec.WIDE_COMM_PARAMETER), | ||
600 | + BgpFlowExtensionCodec.WIDE_COMM_PARAMETER + MISSING_MEMBER_MESSAGE).asText(); | ||
601 | + resultBuilder.setwCommInt(Integer.valueOf(wideComm)); | ||
602 | + resultBuilder.setType(ExtFlowTypes.ExtType.WIDE_COMM_PARAMETER); | ||
603 | + | ||
604 | + return resultBuilder.build(); | ||
605 | + } | ||
606 | + } | ||
607 | + | ||
608 | + /** Wide community target decoder.*/ | ||
609 | + private class BgpWcommTargetDecode implements ExtensionDecoder { | ||
610 | + @Override | ||
611 | + public ExtFlowTypes decodeExtension(ObjectNode json) { | ||
612 | + if (json == null || !json.isObject()) { | ||
613 | + return null; | ||
614 | + } | ||
615 | + | ||
616 | + ExtTarget.Builder resultBuilder = new DefaultExtTarget.Builder(); | ||
617 | + | ||
618 | + JsonNode jsonNodes = json.get(BgpFlowExtensionCodec.WIDE_COMM_TARGET); | ||
619 | + if (jsonNodes == null) { | ||
620 | + nullIsIllegal(json.get(BgpFlowExtensionCodec.WIDE_COMM_TARGET), | ||
621 | + BgpFlowExtensionCodec.WIDE_COMM_TARGET + MISSING_MEMBER_MESSAGE).asText(); | ||
622 | + } | ||
623 | + | ||
624 | + JsonNode array = jsonNodes.path(BgpFlowExtensionCodec.WIDE_COMM_TGT_LOCAL_SP); | ||
625 | + if (array == null) { | ||
626 | + nullIsIllegal(array, BgpFlowExtensionCodec.WIDE_COMM_TGT_LOCAL_SP + MISSING_MEMBER_MESSAGE).asText(); | ||
627 | + } | ||
628 | + | ||
629 | + ExtPrefix.Builder resultBuilderPfx = parseIpArrayToPrefix(array); | ||
630 | + resultBuilderPfx.setType(ExtFlowTypes.ExtType.IPV4_SRC_PFX); | ||
631 | + resultBuilder.setLocalSpeaker(resultBuilderPfx.build()); | ||
632 | + | ||
633 | + array = jsonNodes.path(BgpFlowExtensionCodec.WIDE_COMM_TGT_REMOTE_SP); | ||
634 | + if (array == null) { | ||
635 | + nullIsIllegal(array, BgpFlowExtensionCodec.WIDE_COMM_TGT_REMOTE_SP + MISSING_MEMBER_MESSAGE).asText(); | ||
636 | + } | ||
637 | + | ||
638 | + resultBuilderPfx = parseIpArrayToPrefix(array); | ||
639 | + resultBuilderPfx.setType(ExtFlowTypes.ExtType.IPV4_DST_PFX); | ||
640 | + resultBuilder.setRemoteSpeaker(resultBuilderPfx.build()); | ||
641 | + resultBuilder.setType(ExtFlowTypes.ExtType.WIDE_COMM_TARGET); | ||
642 | + | ||
643 | + return resultBuilder.build(); | ||
644 | + } | ||
645 | + } | ||
646 | + | ||
647 | + /** Wide community extended target decoder.*/ | ||
648 | + private class BgpWcommExtTargetDecode implements ExtensionDecoder { | ||
649 | + @Override | ||
650 | + public ExtFlowTypes decodeExtension(ObjectNode json) { | ||
651 | + if (json == null || !json.isObject()) { | ||
652 | + return null; | ||
653 | + } | ||
654 | + | ||
655 | + ExtTarget.Builder resultBuilder = new DefaultExtTarget.Builder(); | ||
656 | + | ||
657 | + JsonNode jsonNodes = json.get(BgpFlowExtensionCodec.WIDE_COMM_EXT_TARGET); | ||
658 | + if (jsonNodes == null) { | ||
659 | + nullIsIllegal(json.get(BgpFlowExtensionCodec.WIDE_COMM_EXT_TARGET), | ||
660 | + BgpFlowExtensionCodec.WIDE_COMM_EXT_TARGET + MISSING_MEMBER_MESSAGE).asText(); | ||
661 | + } | ||
662 | + | ||
663 | + JsonNode array = jsonNodes.path(BgpFlowExtensionCodec.WIDE_COMM_TGT_LOCAL_SP); | ||
664 | + if (array == null) { | ||
665 | + nullIsIllegal(array, BgpFlowExtensionCodec.WIDE_COMM_TGT_LOCAL_SP + MISSING_MEMBER_MESSAGE).asText(); | ||
666 | + } | ||
667 | + | ||
668 | + ExtPrefix.Builder resultBuilderPfx = parseIpArrayToPrefix(array); | ||
669 | + resultBuilderPfx.setType(ExtFlowTypes.ExtType.IPV4_SRC_PFX); | ||
670 | + resultBuilder.setLocalSpeaker(resultBuilderPfx.build()); | ||
671 | + | ||
672 | + array = jsonNodes.path(BgpFlowExtensionCodec.WIDE_COMM_TGT_REMOTE_SP); | ||
673 | + if (array == null) { | ||
674 | + nullIsIllegal(array, BgpFlowExtensionCodec.WIDE_COMM_TGT_REMOTE_SP + MISSING_MEMBER_MESSAGE).asText(); | ||
675 | + } | ||
676 | + | ||
677 | + resultBuilderPfx = parseIpArrayToPrefix(array); | ||
678 | + resultBuilderPfx.setType(ExtFlowTypes.ExtType.IPV4_DST_PFX); | ||
679 | + resultBuilder.setRemoteSpeaker(resultBuilderPfx.build()); | ||
680 | + resultBuilder.setType(ExtFlowTypes.ExtType.WIDE_COMM_EXT_TARGET); | ||
681 | + | ||
682 | + return resultBuilder.build(); | ||
683 | + } | ||
684 | + } | ||
685 | + | ||
686 | + /** Ip address parser decoder.*/ | ||
687 | + public ExtPrefix.Builder parseIpArrayToPrefix(JsonNode array) { | ||
688 | + | ||
689 | + ExtPrefix.Builder resultBuilder = new DefaultExtPrefix.Builder(); | ||
690 | + String ip; | ||
691 | + IpPrefix prefix; | ||
692 | + IpAddress ipAddr; | ||
693 | + | ||
694 | + Iterator<JsonNode> itr = array.iterator(); | ||
695 | + while (itr.hasNext()) { | ||
696 | + ip = itr.next().asText(); | ||
697 | + ipAddr = IpAddress.valueOf(ip); | ||
698 | + prefix = IpPrefix.valueOf(ipAddr, 32); | ||
699 | + resultBuilder.setPrefix(prefix); | ||
700 | + } | ||
701 | + | ||
702 | + return resultBuilder; | ||
703 | + } | ||
704 | + | ||
705 | + /** | ||
706 | + * Decodes the JSON into a BgpFlowType extension object. | ||
707 | + * | ||
708 | + * @return ExtFlowTypes object | ||
709 | + * @throws IllegalArgumentException if the JSON is invalid | ||
710 | + */ | ||
711 | + public ExtFlowTypes decode() { | ||
712 | + String type = json.get(BgpFlowExtensionCodec.TYPE).asText(); | ||
713 | + | ||
714 | + ExtensionDecoder decoder = decoderMap.get(type); | ||
715 | + if (decoder != null) { | ||
716 | + return decoder.decodeExtension(json); | ||
717 | + } | ||
718 | + | ||
719 | + throw new IllegalArgumentException("Type " + type + " is unknown"); | ||
720 | + } | ||
721 | +} |
1 | +/* | ||
2 | + * Copyright 2016-prensent Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +/** | ||
18 | + * Codec for bgp flow. | ||
19 | + */ | ||
20 | +package org.onosproject.bgpweb.web; |
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<!-- | ||
3 | + ~ Copyright 2016-present Open Networking Laboratory | ||
4 | + ~ | ||
5 | + ~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
6 | + ~ you may not use this file except in compliance with the License. | ||
7 | + ~ You may obtain a copy of the License at | ||
8 | + ~ | ||
9 | + ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
10 | + ~ | ||
11 | + ~ Unless required by applicable law or agreed to in writing, software | ||
12 | + ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
13 | + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
14 | + ~ See the License for the specific language governing permissions and | ||
15 | + ~ limitations under the License. | ||
16 | + --> | ||
17 | +<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" | ||
18 | + xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" | ||
19 | + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" | ||
20 | + id="ONOS" version="2.5"> | ||
21 | + <display-name>BGP REST API v1.0</display-name> | ||
22 | + | ||
23 | + | ||
24 | + <servlet> | ||
25 | + <servlet-name>JAX-RS Service</servlet-name> | ||
26 | + <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class> | ||
27 | + <init-param> | ||
28 | + <param-name>javax.ws.rs.Application</param-name> | ||
29 | + <param-value>org.onosproject.bgpweb.resources.BgpWebApplication</param-value> | ||
30 | + </init-param> | ||
31 | + <load-on-startup>1</load-on-startup> | ||
32 | + </servlet> | ||
33 | + | ||
34 | + <servlet-mapping> | ||
35 | + <servlet-name>JAX-RS Service</servlet-name> | ||
36 | + <url-pattern>/*</url-pattern> | ||
37 | + </servlet-mapping> | ||
38 | +</web-app> |
apps/bgpflowspec/flowapi/BUCK
0 → 100755
1 | +COMPILE_DEPS = [ | ||
2 | + '//utils/osgi:onlab-osgi', | ||
3 | + '//utils/misc:onlab-misc', | ||
4 | + '//lib:commons-io', | ||
5 | + '//lib:guava', | ||
6 | + '//lib:kryo', | ||
7 | + '//lib:slf4j-api', | ||
8 | +] | ||
9 | + | ||
10 | +TEST_DEPS = [ | ||
11 | + '//lib:TEST_ADAPTERS', | ||
12 | +] | ||
13 | + | ||
14 | +osgi_jar_with_tests ( | ||
15 | + name = 'onos-apps-bgpflowspec-flowapi', | ||
16 | + deps = COMPILE_DEPS, | ||
17 | + test_deps = TEST_DEPS, | ||
18 | + visibility = ['PUBLIC'], | ||
19 | +) |
apps/bgpflowspec/flowapi/pom.xml
0 → 100755
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<!-- | ||
3 | + ~ Copyright 2016-present Open Networking Laboratory | ||
4 | + ~ | ||
5 | + ~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
6 | + ~ you may not use this file except in compliance with the License. | ||
7 | + ~ You may obtain a copy of the License at | ||
8 | + ~ | ||
9 | + ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
10 | + ~ | ||
11 | + ~ Unless required by applicable law or agreed to in writing, software | ||
12 | + ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
13 | + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
14 | + ~ See the License for the specific language governing permissions and | ||
15 | + ~ limitations under the License. | ||
16 | + --> | ||
17 | +<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
18 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
19 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
20 | + <modelVersion>4.0.0</modelVersion> | ||
21 | + | ||
22 | + <parent> | ||
23 | + <groupId>org.onosproject</groupId> | ||
24 | + <artifactId>onos-app-bgpflow</artifactId> | ||
25 | + <version>1.6.0-SNAPSHOT</version> | ||
26 | + <relativePath>../pom.xml</relativePath> | ||
27 | + </parent> | ||
28 | + | ||
29 | + <artifactId>onos-app-bgp-flowapi</artifactId> | ||
30 | + <packaging>bundle</packaging> | ||
31 | + | ||
32 | + <description>api bundle to be accessible across the layers</description> | ||
33 | + | ||
34 | + <dependencies> | ||
35 | + <dependency> | ||
36 | + <groupId>org.onosproject</groupId> | ||
37 | + <artifactId>onlab-misc</artifactId> | ||
38 | + <version>1.6.0-SNAPSHOT</version> | ||
39 | + </dependency> | ||
40 | + <dependency> | ||
41 | + <groupId>com.google.guava</groupId> | ||
42 | + <artifactId>guava-testlib</artifactId> | ||
43 | + <scope>test</scope> | ||
44 | + </dependency> | ||
45 | + </dependencies> | ||
46 | + | ||
47 | +</project> |
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.flowapi; | ||
17 | + | ||
18 | +import java.util.List; | ||
19 | +import java.util.Objects; | ||
20 | + | ||
21 | +import static com.google.common.base.MoreObjects.toStringHelper; | ||
22 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
23 | + | ||
24 | +/** | ||
25 | + * DSCP value extension implementation. | ||
26 | + */ | ||
27 | +public class DefaultExtDscpValue implements ExtDscpValue { | ||
28 | + | ||
29 | + private List<ExtOperatorValue> dscpValue; | ||
30 | + private ExtType type; | ||
31 | + | ||
32 | + /** | ||
33 | + * Creates an object of type DefaultExtDscpValue which contains dscp operator value list. | ||
34 | + * | ||
35 | + * @param dscpValue is a dscp value rule list | ||
36 | + * @param type ExtType type | ||
37 | + */ | ||
38 | + DefaultExtDscpValue(List<ExtOperatorValue> dscpValue, ExtType type) { | ||
39 | + this.dscpValue = dscpValue; | ||
40 | + this.type = type; | ||
41 | + } | ||
42 | + | ||
43 | + @Override | ||
44 | + public ExtType type() { | ||
45 | + return type; | ||
46 | + } | ||
47 | + | ||
48 | + @Override | ||
49 | + public List<ExtOperatorValue> dscpValue() { | ||
50 | + return dscpValue; | ||
51 | + } | ||
52 | + | ||
53 | + @Override | ||
54 | + public boolean exactMatch(ExtDscpValue value) { | ||
55 | + return this.equals(value) && | ||
56 | + Objects.equals(this.dscpValue, value.dscpValue()) | ||
57 | + && Objects.equals(this.type, value.type()); | ||
58 | + } | ||
59 | + | ||
60 | + @Override | ||
61 | + public int hashCode() { | ||
62 | + return Objects.hash(dscpValue, type); | ||
63 | + } | ||
64 | + | ||
65 | + @Override | ||
66 | + public boolean equals(Object obj) { | ||
67 | + if (this == obj) { | ||
68 | + return true; | ||
69 | + } | ||
70 | + if (obj instanceof DefaultExtDscpValue) { | ||
71 | + DefaultExtDscpValue that = (DefaultExtDscpValue) obj; | ||
72 | + return Objects.equals(dscpValue, that.dscpValue()) | ||
73 | + && Objects.equals(this.type, that.type()); | ||
74 | + } | ||
75 | + return false; | ||
76 | + } | ||
77 | + | ||
78 | + @Override | ||
79 | + public String toString() { | ||
80 | + return toStringHelper(this) | ||
81 | + .add("dscpValue", dscpValue.toString()) | ||
82 | + .add("type", type.toString()) | ||
83 | + .toString(); | ||
84 | + } | ||
85 | + | ||
86 | + /** | ||
87 | + * Builder class for extension dscp value. | ||
88 | + */ | ||
89 | + public static class Builder implements ExtDscpValue.Builder { | ||
90 | + private List<ExtOperatorValue> dscpValue; | ||
91 | + private ExtType type; | ||
92 | + | ||
93 | + @Override | ||
94 | + public Builder setDscpValue(List<ExtOperatorValue> dscpValue) { | ||
95 | + this.dscpValue = dscpValue; | ||
96 | + return this; | ||
97 | + } | ||
98 | + | ||
99 | + @Override | ||
100 | + public Builder setType(ExtType type) { | ||
101 | + this.type = type; | ||
102 | + return this; | ||
103 | + } | ||
104 | + | ||
105 | + @Override | ||
106 | + public ExtDscpValue build() { | ||
107 | + checkNotNull(dscpValue, "dscpValue cannot be null"); | ||
108 | + return new DefaultExtDscpValue(dscpValue, type); | ||
109 | + } | ||
110 | + } | ||
111 | +} |
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.flowapi; | ||
17 | + | ||
18 | +import java.util.List; | ||
19 | +import java.util.Objects; | ||
20 | + | ||
21 | +import static com.google.common.base.MoreObjects.toStringHelper; | ||
22 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
23 | + | ||
24 | +/** | ||
25 | + * Fragment extension implementation. | ||
26 | + */ | ||
27 | +public class DefaultExtFragment implements ExtFragment { | ||
28 | + | ||
29 | + private List<ExtOperatorValue> fragment; | ||
30 | + private ExtType type; | ||
31 | + | ||
32 | + /** | ||
33 | + * Creates an object of type DefaultExtFragment which contains fragment operator value list. | ||
34 | + * | ||
35 | + * @param fragment is a fragment value rule list | ||
36 | + * @param type ExtType type | ||
37 | + */ | ||
38 | + DefaultExtFragment(List<ExtOperatorValue> fragment, ExtType type) { | ||
39 | + this.fragment = fragment; | ||
40 | + this.type = type; | ||
41 | + } | ||
42 | + | ||
43 | + @Override | ||
44 | + public ExtType type() { | ||
45 | + return type; | ||
46 | + } | ||
47 | + | ||
48 | + @Override | ||
49 | + public List<ExtOperatorValue> fragment() { | ||
50 | + return fragment; | ||
51 | + } | ||
52 | + | ||
53 | + @Override | ||
54 | + public boolean exactMatch(ExtFragment value) { | ||
55 | + return this.equals(value) && | ||
56 | + Objects.equals(this.fragment, value.fragment()) | ||
57 | + && Objects.equals(this.type, value.type()); | ||
58 | + } | ||
59 | + | ||
60 | + @Override | ||
61 | + public int hashCode() { | ||
62 | + return Objects.hash(fragment, type); | ||
63 | + } | ||
64 | + | ||
65 | + @Override | ||
66 | + public boolean equals(Object obj) { | ||
67 | + if (this == obj) { | ||
68 | + return true; | ||
69 | + } | ||
70 | + if (obj instanceof DefaultExtFragment) { | ||
71 | + DefaultExtFragment that = (DefaultExtFragment) obj; | ||
72 | + return Objects.equals(fragment, that.fragment()) | ||
73 | + && Objects.equals(this.type, that.type()); | ||
74 | + } | ||
75 | + return false; | ||
76 | + } | ||
77 | + | ||
78 | + @Override | ||
79 | + public String toString() { | ||
80 | + return toStringHelper(this) | ||
81 | + .add("fragment", fragment.toString()) | ||
82 | + .add("type", type.toString()) | ||
83 | + .toString(); | ||
84 | + } | ||
85 | + | ||
86 | + /** | ||
87 | + * Builder class for extension fragment value. | ||
88 | + */ | ||
89 | + public static class Builder implements ExtFragment.Builder { | ||
90 | + private List<ExtOperatorValue> fragment; | ||
91 | + private ExtType type; | ||
92 | + | ||
93 | + @Override | ||
94 | + public Builder setFragment(List<ExtOperatorValue> fragment) { | ||
95 | + this.fragment = fragment; | ||
96 | + return this; | ||
97 | + } | ||
98 | + | ||
99 | + @Override | ||
100 | + public Builder setType(ExtType type) { | ||
101 | + this.type = type; | ||
102 | + return this; | ||
103 | + } | ||
104 | + | ||
105 | + @Override | ||
106 | + public ExtFragment build() { | ||
107 | + checkNotNull(fragment, "fragment cannot be null"); | ||
108 | + return new DefaultExtFragment(fragment, type); | ||
109 | + } | ||
110 | + } | ||
111 | +} |
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.flowapi; | ||
17 | + | ||
18 | +import java.util.List; | ||
19 | +import java.util.Objects; | ||
20 | + | ||
21 | +import static com.google.common.base.MoreObjects.toStringHelper; | ||
22 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
23 | + | ||
24 | +/** | ||
25 | + * Icmp code extension implementation. | ||
26 | + */ | ||
27 | +public class DefaultExtIcmpCode implements ExtIcmpCode { | ||
28 | + | ||
29 | + private List<ExtOperatorValue> icmpCode; | ||
30 | + private ExtType type; | ||
31 | + | ||
32 | + /** | ||
33 | + * Creates an object of type DefaultExtIcmpCode which contains ICMP code operator value list. | ||
34 | + * | ||
35 | + * @param icmpCode is a icmp code rule list | ||
36 | + * @param type ExtType type | ||
37 | + */ | ||
38 | + DefaultExtIcmpCode(List<ExtOperatorValue> icmpCode, ExtType type) { | ||
39 | + this.icmpCode = icmpCode; | ||
40 | + this.type = type; | ||
41 | + } | ||
42 | + | ||
43 | + @Override | ||
44 | + public ExtType type() { | ||
45 | + return type; | ||
46 | + } | ||
47 | + | ||
48 | + @Override | ||
49 | + public List<ExtOperatorValue> icmpCode() { | ||
50 | + return icmpCode; | ||
51 | + } | ||
52 | + | ||
53 | + @Override | ||
54 | + public boolean exactMatch(ExtIcmpCode icmpCode) { | ||
55 | + return this.equals(icmpCode) && | ||
56 | + Objects.equals(this.icmpCode, icmpCode.icmpCode()) | ||
57 | + && Objects.equals(this.type, icmpCode.type()); | ||
58 | + } | ||
59 | + | ||
60 | + @Override | ||
61 | + public int hashCode() { | ||
62 | + return Objects.hash(icmpCode, type); | ||
63 | + } | ||
64 | + | ||
65 | + @Override | ||
66 | + public boolean equals(Object obj) { | ||
67 | + if (this == obj) { | ||
68 | + return true; | ||
69 | + } | ||
70 | + if (obj instanceof DefaultExtIcmpCode) { | ||
71 | + DefaultExtIcmpCode that = (DefaultExtIcmpCode) obj; | ||
72 | + return Objects.equals(icmpCode, that.icmpCode()) | ||
73 | + && Objects.equals(this.type, that.type()); | ||
74 | + } | ||
75 | + return false; | ||
76 | + } | ||
77 | + | ||
78 | + @Override | ||
79 | + public String toString() { | ||
80 | + return toStringHelper(this) | ||
81 | + .add("icmpCode", icmpCode.toString()) | ||
82 | + .add("type", type.toString()) | ||
83 | + .toString(); | ||
84 | + } | ||
85 | + | ||
86 | + /** | ||
87 | + * Builder class for extension icmp type. | ||
88 | + */ | ||
89 | + public static class Builder implements ExtIcmpCode.Builder { | ||
90 | + private List<ExtOperatorValue> icmpCode; | ||
91 | + private ExtType type; | ||
92 | + | ||
93 | + @Override | ||
94 | + public Builder setIcmpCode(List<ExtOperatorValue> icmpCode) { | ||
95 | + this.icmpCode = icmpCode; | ||
96 | + return this; | ||
97 | + } | ||
98 | + | ||
99 | + @Override | ||
100 | + public Builder setType(ExtType type) { | ||
101 | + this.type = type; | ||
102 | + return this; | ||
103 | + } | ||
104 | + | ||
105 | + @Override | ||
106 | + public ExtIcmpCode build() { | ||
107 | + checkNotNull(icmpCode, "icmpCode cannot be null"); | ||
108 | + return new DefaultExtIcmpCode(icmpCode, type); | ||
109 | + } | ||
110 | + } | ||
111 | +} |
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.flowapi; | ||
17 | + | ||
18 | +import java.util.List; | ||
19 | +import java.util.Objects; | ||
20 | + | ||
21 | +import static com.google.common.base.MoreObjects.toStringHelper; | ||
22 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
23 | + | ||
24 | +/** | ||
25 | + * Icmp type extension implementation. | ||
26 | + */ | ||
27 | +public class DefaultExtIcmpType implements ExtIcmpType { | ||
28 | + | ||
29 | + private List<ExtOperatorValue> icmpType; | ||
30 | + private ExtType type; | ||
31 | + | ||
32 | + /** | ||
33 | + * Creates an object of type DefaultExtIcmpType which contains ICMP type operator value list. | ||
34 | + * | ||
35 | + * @param icmpType is a icmp type rule list | ||
36 | + * @param type ExtType type | ||
37 | + */ | ||
38 | + DefaultExtIcmpType(List<ExtOperatorValue> icmpType, ExtType type) { | ||
39 | + this.icmpType = icmpType; | ||
40 | + this.type = type; | ||
41 | + } | ||
42 | + | ||
43 | + @Override | ||
44 | + public ExtType type() { | ||
45 | + return type; | ||
46 | + } | ||
47 | + | ||
48 | + @Override | ||
49 | + public List<ExtOperatorValue> icmpType() { | ||
50 | + return icmpType; | ||
51 | + } | ||
52 | + | ||
53 | + @Override | ||
54 | + public boolean exactMatch(ExtIcmpType icmpType) { | ||
55 | + return this.equals(icmpType) && | ||
56 | + Objects.equals(this.icmpType, icmpType.icmpType()) | ||
57 | + && Objects.equals(this.type, icmpType.type()); | ||
58 | + } | ||
59 | + | ||
60 | + @Override | ||
61 | + public int hashCode() { | ||
62 | + return Objects.hash(icmpType, type); | ||
63 | + } | ||
64 | + | ||
65 | + @Override | ||
66 | + public boolean equals(Object obj) { | ||
67 | + if (this == obj) { | ||
68 | + return true; | ||
69 | + } | ||
70 | + if (obj instanceof DefaultExtIcmpType) { | ||
71 | + DefaultExtIcmpType that = (DefaultExtIcmpType) obj; | ||
72 | + return Objects.equals(icmpType, that.icmpType()) | ||
73 | + && Objects.equals(this.type, that.type()); | ||
74 | + } | ||
75 | + return false; | ||
76 | + } | ||
77 | + | ||
78 | + @Override | ||
79 | + public String toString() { | ||
80 | + return toStringHelper(this) | ||
81 | + .add("icmpType", icmpType.toString()) | ||
82 | + .add("type", type.toString()) | ||
83 | + .toString(); | ||
84 | + } | ||
85 | + | ||
86 | + /** | ||
87 | + * Builder class for extension icmp type. | ||
88 | + */ | ||
89 | + public static class Builder implements ExtIcmpType.Builder { | ||
90 | + private List<ExtOperatorValue> icmpType; | ||
91 | + private ExtType type; | ||
92 | + | ||
93 | + @Override | ||
94 | + public Builder setIcmpType(List<ExtOperatorValue> icmpType) { | ||
95 | + this.icmpType = icmpType; | ||
96 | + return this; | ||
97 | + } | ||
98 | + | ||
99 | + @Override | ||
100 | + public Builder setType(ExtType type) { | ||
101 | + this.type = type; | ||
102 | + return this; | ||
103 | + } | ||
104 | + | ||
105 | + @Override | ||
106 | + public ExtIcmpType build() { | ||
107 | + checkNotNull(icmpType, "icmpType cannot be null"); | ||
108 | + return new DefaultExtIcmpType(icmpType, type); | ||
109 | + } | ||
110 | + } | ||
111 | +} |
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.flowapi; | ||
17 | + | ||
18 | +import java.util.List; | ||
19 | +import java.util.Objects; | ||
20 | + | ||
21 | +import static com.google.common.base.MoreObjects.toStringHelper; | ||
22 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
23 | + | ||
24 | +/** | ||
25 | + * Ip protocol extension implementation. | ||
26 | + */ | ||
27 | +public final class DefaultExtIpProtocol implements ExtIpProtocol { | ||
28 | + | ||
29 | + private List<ExtOperatorValue> ipProtocol; | ||
30 | + private ExtType type; | ||
31 | + | ||
32 | + /** | ||
33 | + * Creates an object of type DefaultExtIpProtocol which contains Ip protocol list. | ||
34 | + * | ||
35 | + * @param ipProtocol Ip protocol operator value list | ||
36 | + * @param type BgpType type | ||
37 | + */ | ||
38 | + DefaultExtIpProtocol(List<ExtOperatorValue> ipProtocol, ExtType type) { | ||
39 | + this.ipProtocol = ipProtocol; | ||
40 | + this.type = type; | ||
41 | + } | ||
42 | + | ||
43 | + @Override | ||
44 | + public ExtType type() { | ||
45 | + return type; | ||
46 | + } | ||
47 | + | ||
48 | + @Override | ||
49 | + public List<ExtOperatorValue> ipProtocol() { | ||
50 | + return ipProtocol; | ||
51 | + } | ||
52 | + | ||
53 | + @Override | ||
54 | + public boolean exactMatch(ExtIpProtocol ipProto) { | ||
55 | + return this.equals(ipProto) && | ||
56 | + Objects.equals(this.ipProtocol, ipProto.ipProtocol()) | ||
57 | + && Objects.equals(this.type, ipProto.type()); | ||
58 | + } | ||
59 | + | ||
60 | + @Override | ||
61 | + public int hashCode() { | ||
62 | + return Objects.hash(ipProtocol, type); | ||
63 | + } | ||
64 | + | ||
65 | + @Override | ||
66 | + public boolean equals(Object obj) { | ||
67 | + if (this == obj) { | ||
68 | + return true; | ||
69 | + } | ||
70 | + if (obj instanceof DefaultExtIpProtocol) { | ||
71 | + DefaultExtIpProtocol that = (DefaultExtIpProtocol) obj; | ||
72 | + return Objects.equals(ipProtocol, that.ipProtocol()) | ||
73 | + && Objects.equals(this.type, that.type); | ||
74 | + } | ||
75 | + return false; | ||
76 | + } | ||
77 | + | ||
78 | + @Override | ||
79 | + public String toString() { | ||
80 | + return toStringHelper(this) | ||
81 | + .add("ipProtocol", ipProtocol.toString()) | ||
82 | + .add("type", type.toString()) | ||
83 | + .toString(); | ||
84 | + } | ||
85 | + | ||
86 | + /** | ||
87 | + * Builder class for extension Ip protocol. | ||
88 | + */ | ||
89 | + public static class Builder implements ExtIpProtocol.Builder { | ||
90 | + private List<ExtOperatorValue> ipProtocol; | ||
91 | + private ExtType type; | ||
92 | + | ||
93 | + @Override | ||
94 | + public Builder setIpProtocol(List<ExtOperatorValue> ipProtocol) { | ||
95 | + this.ipProtocol = ipProtocol; | ||
96 | + return this; | ||
97 | + } | ||
98 | + | ||
99 | + @Override | ||
100 | + public Builder setType(ExtType type) { | ||
101 | + this.type = type; | ||
102 | + return this; | ||
103 | + } | ||
104 | + | ||
105 | + @Override | ||
106 | + public ExtIpProtocol build() { | ||
107 | + checkNotNull(ipProtocol, "Ip protocol cannot be null"); | ||
108 | + return new DefaultExtIpProtocol(ipProtocol, type); | ||
109 | + } | ||
110 | + } | ||
111 | +} | ||
112 | + |
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.flowapi; | ||
17 | + | ||
18 | +import java.util.Objects; | ||
19 | +import static com.google.common.base.MoreObjects.toStringHelper; | ||
20 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
21 | + | ||
22 | +/** | ||
23 | + * Key Name for the extension implementation. | ||
24 | + */ | ||
25 | +public class DefaultExtKeyName implements ExtKeyName { | ||
26 | + | ||
27 | + private String keyName; | ||
28 | + private ExtType type; | ||
29 | + | ||
30 | + /** | ||
31 | + * Creates an object of type DefaultExtKeyName which name for the flow rule. | ||
32 | + * | ||
33 | + * @param keyName is a key for the extended rule | ||
34 | + * @param type ExtType type | ||
35 | + */ | ||
36 | + DefaultExtKeyName(String keyName, ExtType type) { | ||
37 | + this.keyName = keyName; | ||
38 | + this.type = type; | ||
39 | + } | ||
40 | + | ||
41 | + @Override | ||
42 | + public ExtType type() { | ||
43 | + return type; | ||
44 | + } | ||
45 | + | ||
46 | + @Override | ||
47 | + public String keyName() { | ||
48 | + return keyName; | ||
49 | + } | ||
50 | + | ||
51 | + @Override | ||
52 | + public boolean exactMatch(ExtKeyName value) { | ||
53 | + return this.equals(value) && | ||
54 | + Objects.equals(this.keyName, value.keyName()) | ||
55 | + && Objects.equals(this.type, value.type()); | ||
56 | + } | ||
57 | + | ||
58 | + @Override | ||
59 | + public int hashCode() { | ||
60 | + return Objects.hash(keyName, type); | ||
61 | + } | ||
62 | + | ||
63 | + @Override | ||
64 | + public boolean equals(Object obj) { | ||
65 | + if (this == obj) { | ||
66 | + return true; | ||
67 | + } | ||
68 | + if (obj instanceof DefaultExtKeyName) { | ||
69 | + DefaultExtKeyName that = (DefaultExtKeyName) obj; | ||
70 | + return Objects.equals(keyName, that.keyName()) | ||
71 | + && Objects.equals(this.type, that.type()); | ||
72 | + } | ||
73 | + return false; | ||
74 | + } | ||
75 | + | ||
76 | + @Override | ||
77 | + public String toString() { | ||
78 | + return toStringHelper(this) | ||
79 | + .add("keyName", keyName.toString()) | ||
80 | + .add("type", type.toString()) | ||
81 | + .toString(); | ||
82 | + } | ||
83 | + | ||
84 | + /** | ||
85 | + * Builder class for Extended key name for the rule. | ||
86 | + */ | ||
87 | + public static class Builder implements ExtKeyName.Builder { | ||
88 | + private String keyName; | ||
89 | + private ExtType type; | ||
90 | + | ||
91 | + @Override | ||
92 | + public Builder setKeyName(String keyName) { | ||
93 | + this.keyName = keyName; | ||
94 | + return this; | ||
95 | + } | ||
96 | + | ||
97 | + @Override | ||
98 | + public Builder setType(ExtType type) { | ||
99 | + this.type = type; | ||
100 | + return this; | ||
101 | + } | ||
102 | + | ||
103 | + @Override | ||
104 | + public ExtKeyName build() { | ||
105 | + checkNotNull(keyName, "keyName cannot be null"); | ||
106 | + return new DefaultExtKeyName(keyName, type); | ||
107 | + } | ||
108 | + } | ||
109 | +} |
apps/bgpflowspec/flowapi/src/main/java/org/onosproject/flowapi/DefaultExtPacketLength.java
0 → 100755
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.flowapi; | ||
17 | + | ||
18 | +import java.util.List; | ||
19 | +import java.util.Objects; | ||
20 | + | ||
21 | +import static com.google.common.base.MoreObjects.toStringHelper; | ||
22 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
23 | + | ||
24 | +/** | ||
25 | + * Packet length extension implementation. | ||
26 | + */ | ||
27 | +public class DefaultExtPacketLength implements ExtPacketLength { | ||
28 | + | ||
29 | + private List<ExtOperatorValue> packetLength; | ||
30 | + private ExtType type; | ||
31 | + | ||
32 | + /** | ||
33 | + * Creates an object of type DefaultExtPacketLength which contains packet length list.. | ||
34 | + * | ||
35 | + * @param packetLength is a packet length rule | ||
36 | + * @param type ExtType type | ||
37 | + */ | ||
38 | + DefaultExtPacketLength(List<ExtOperatorValue> packetLength, ExtType type) { | ||
39 | + this.packetLength = packetLength; | ||
40 | + this.type = type; | ||
41 | + } | ||
42 | + | ||
43 | + @Override | ||
44 | + public ExtType type() { | ||
45 | + return type; | ||
46 | + } | ||
47 | + | ||
48 | + @Override | ||
49 | + public List<ExtOperatorValue> packetLength() { | ||
50 | + return packetLength; | ||
51 | + } | ||
52 | + | ||
53 | + @Override | ||
54 | + public boolean exactMatch(ExtPacketLength length) { | ||
55 | + return this.equals(packetLength) && | ||
56 | + Objects.equals(this.packetLength, length.packetLength()) | ||
57 | + && Objects.equals(this.type, length.type()); | ||
58 | + } | ||
59 | + | ||
60 | + @Override | ||
61 | + public int hashCode() { | ||
62 | + return Objects.hash(packetLength, type); | ||
63 | + } | ||
64 | + | ||
65 | + @Override | ||
66 | + public boolean equals(Object obj) { | ||
67 | + if (this == obj) { | ||
68 | + return true; | ||
69 | + } | ||
70 | + if (obj instanceof DefaultExtPacketLength) { | ||
71 | + DefaultExtPacketLength that = (DefaultExtPacketLength) obj; | ||
72 | + return Objects.equals(packetLength, that.packetLength()) | ||
73 | + && Objects.equals(this.type, that.type()); | ||
74 | + } | ||
75 | + return false; | ||
76 | + } | ||
77 | + | ||
78 | + @Override | ||
79 | + public String toString() { | ||
80 | + return toStringHelper(this) | ||
81 | + .add("packetLength", packetLength.toString()) | ||
82 | + .add("type", type.toString()) | ||
83 | + .toString(); | ||
84 | + } | ||
85 | + | ||
86 | + /** | ||
87 | + * Builder class for extension packet length. | ||
88 | + */ | ||
89 | + public static class Builder implements ExtPacketLength.Builder { | ||
90 | + private List<ExtOperatorValue> packetLength; | ||
91 | + private ExtType type; | ||
92 | + | ||
93 | + @Override | ||
94 | + public Builder setPacketLength(List<ExtOperatorValue> packetLength) { | ||
95 | + this.packetLength = packetLength; | ||
96 | + return this; | ||
97 | + } | ||
98 | + | ||
99 | + @Override | ||
100 | + public Builder setType(ExtType type) { | ||
101 | + this.type = type; | ||
102 | + return this; | ||
103 | + } | ||
104 | + | ||
105 | + @Override | ||
106 | + public ExtPacketLength build() { | ||
107 | + checkNotNull(packetLength, "packetLength cannot be null"); | ||
108 | + return new DefaultExtPacketLength(packetLength, type); | ||
109 | + } | ||
110 | + } | ||
111 | +} |
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.flowapi; | ||
17 | + | ||
18 | +import java.util.List; | ||
19 | +import java.util.Objects; | ||
20 | + | ||
21 | +import static com.google.common.base.MoreObjects.toStringHelper; | ||
22 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
23 | + | ||
24 | +/** | ||
25 | + * Port extension implementation. | ||
26 | + */ | ||
27 | +public class DefaultExtPort implements ExtPort { | ||
28 | + | ||
29 | + private List<ExtOperatorValue> port; | ||
30 | + private ExtType type; | ||
31 | + | ||
32 | + /** | ||
33 | + * Creates an object of type DefaultExtPort which contains port list. | ||
34 | + * | ||
35 | + * @param port is a port rule list | ||
36 | + * @param type ExtType type | ||
37 | + */ | ||
38 | + DefaultExtPort(List<ExtOperatorValue> port, ExtType type) { | ||
39 | + this.port = port; | ||
40 | + this.type = type; | ||
41 | + } | ||
42 | + | ||
43 | + @Override | ||
44 | + public ExtType type() { | ||
45 | + return type; | ||
46 | + } | ||
47 | + | ||
48 | + @Override | ||
49 | + public List<ExtOperatorValue> port() { | ||
50 | + return port; | ||
51 | + } | ||
52 | + | ||
53 | + @Override | ||
54 | + public boolean exactMatch(ExtPort port) { | ||
55 | + return this.equals(port) && | ||
56 | + Objects.equals(this.port, port.port()) | ||
57 | + && Objects.equals(this.type, port.type()); | ||
58 | + } | ||
59 | + | ||
60 | + @Override | ||
61 | + public int hashCode() { | ||
62 | + return Objects.hash(port, type); | ||
63 | + } | ||
64 | + | ||
65 | + @Override | ||
66 | + public boolean equals(Object obj) { | ||
67 | + if (this == obj) { | ||
68 | + return true; | ||
69 | + } | ||
70 | + if (obj instanceof DefaultExtPort) { | ||
71 | + DefaultExtPort that = (DefaultExtPort) obj; | ||
72 | + return Objects.equals(port, that.port()) | ||
73 | + && Objects.equals(this.type, that.type()); | ||
74 | + } | ||
75 | + return false; | ||
76 | + } | ||
77 | + | ||
78 | + @Override | ||
79 | + public String toString() { | ||
80 | + return toStringHelper(this) | ||
81 | + .add("port", port.toString()) | ||
82 | + .add("type", type.toString()) | ||
83 | + .toString(); | ||
84 | + } | ||
85 | + | ||
86 | + /** | ||
87 | + * Builder class for extension port. | ||
88 | + */ | ||
89 | + public static class Builder implements ExtPort.Builder { | ||
90 | + private List<ExtOperatorValue> port; | ||
91 | + private ExtType type; | ||
92 | + | ||
93 | + @Override | ||
94 | + public Builder setPort(List<ExtOperatorValue> port) { | ||
95 | + this.port = port; | ||
96 | + return this; | ||
97 | + } | ||
98 | + | ||
99 | + @Override | ||
100 | + public Builder setType(ExtType type) { | ||
101 | + this.type = type; | ||
102 | + return this; | ||
103 | + } | ||
104 | + | ||
105 | + @Override | ||
106 | + public ExtPort build() { | ||
107 | + checkNotNull(port, "port cannot be null"); | ||
108 | + return new DefaultExtPort(port, type); | ||
109 | + } | ||
110 | + } | ||
111 | +} |
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.flowapi; | ||
17 | + | ||
18 | +import org.onlab.packet.IpPrefix; | ||
19 | + | ||
20 | +import java.util.ArrayList; | ||
21 | +import java.util.List; | ||
22 | +import java.util.Objects; | ||
23 | + | ||
24 | +import static com.google.common.base.MoreObjects.toStringHelper; | ||
25 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
26 | + | ||
27 | +/** | ||
28 | + * Ip prefix extension implementation. | ||
29 | + */ | ||
30 | +public final class DefaultExtPrefix implements ExtPrefix { | ||
31 | + | ||
32 | + private List<IpPrefix> prefix; | ||
33 | + private ExtType type; | ||
34 | + | ||
35 | + /** | ||
36 | + * Creates an object of type DefaultExtPrefix which contains Ip prefix list. | ||
37 | + * | ||
38 | + * @param prefix Ip prefix list | ||
39 | + * @param type ExtType type | ||
40 | + */ | ||
41 | + DefaultExtPrefix(List<IpPrefix> prefix, ExtType type) { | ||
42 | + this.prefix = prefix; | ||
43 | + this.type = type; | ||
44 | + } | ||
45 | + | ||
46 | + @Override | ||
47 | + public ExtType type() { | ||
48 | + return type; | ||
49 | + } | ||
50 | + | ||
51 | + @Override | ||
52 | + public List<IpPrefix> prefix() { | ||
53 | + return prefix; | ||
54 | + } | ||
55 | + | ||
56 | + @Override | ||
57 | + public boolean exactMatch(ExtPrefix prefix) { | ||
58 | + return this.equals(prefix) && | ||
59 | + Objects.equals(this.prefix, prefix.prefix()) | ||
60 | + && Objects.equals(this.type, prefix.type()); | ||
61 | + } | ||
62 | + | ||
63 | + @Override | ||
64 | + public int hashCode() { | ||
65 | + return Objects.hash(prefix, type); | ||
66 | + } | ||
67 | + | ||
68 | + @Override | ||
69 | + public boolean equals(Object obj) { | ||
70 | + if (this == obj) { | ||
71 | + return true; | ||
72 | + } | ||
73 | + if (obj instanceof DefaultExtPrefix) { | ||
74 | + DefaultExtPrefix that = (DefaultExtPrefix) obj; | ||
75 | + return Objects.equals(prefix, that.prefix()) | ||
76 | + && Objects.equals(this.type, that.type); | ||
77 | + } | ||
78 | + return false; | ||
79 | + } | ||
80 | + | ||
81 | + @Override | ||
82 | + public String toString() { | ||
83 | + return toStringHelper(this) | ||
84 | + .add("prefix", prefix.toString()) | ||
85 | + .add("type", type.toString()) | ||
86 | + .toString(); | ||
87 | + } | ||
88 | + | ||
89 | + /** | ||
90 | + * Builder class for extension Ip prefix. | ||
91 | + */ | ||
92 | + public static class Builder implements ExtPrefix.Builder { | ||
93 | + private List<IpPrefix> prefix = new ArrayList<>(); | ||
94 | + private ExtType type; | ||
95 | + | ||
96 | + @Override | ||
97 | + public Builder setPrefix(IpPrefix ip) { | ||
98 | + this.prefix.add(ip); | ||
99 | + return this; | ||
100 | + } | ||
101 | + | ||
102 | + @Override | ||
103 | + public Builder setType(ExtType type) { | ||
104 | + this.type = type; | ||
105 | + return this; | ||
106 | + } | ||
107 | + | ||
108 | + @Override | ||
109 | + public ExtPrefix build() { | ||
110 | + checkNotNull(prefix, "Ip prefix cannot be null"); | ||
111 | + return new DefaultExtPrefix(prefix, type); | ||
112 | + } | ||
113 | + } | ||
114 | +} | ||
115 | + |
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.flowapi; | ||
17 | + | ||
18 | +import java.util.Objects; | ||
19 | + | ||
20 | +import static com.google.common.base.MoreObjects.toStringHelper; | ||
21 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
22 | + | ||
23 | +/** | ||
24 | + * Target local and remote speaker implementation for wide community. | ||
25 | + */ | ||
26 | +public final class DefaultExtTarget implements ExtTarget { | ||
27 | + | ||
28 | + private ExtPrefix localSpeaker; | ||
29 | + private ExtPrefix remoteSpeaker; | ||
30 | + private ExtType type; | ||
31 | + | ||
32 | + /** | ||
33 | + * Creates an object of type DefaultExtTarget which contains local and remote speakers. | ||
34 | + * | ||
35 | + * @param localSpeaker local speaker prefix list | ||
36 | + * @param remoteSpeaker remoteSpeaker speaker prefix list | ||
37 | + * @param type ExtType type | ||
38 | + */ | ||
39 | + DefaultExtTarget(ExtPrefix localSpeaker, ExtPrefix remoteSpeaker, ExtType type) { | ||
40 | + this.localSpeaker = localSpeaker; | ||
41 | + this.remoteSpeaker = remoteSpeaker; | ||
42 | + this.type = type; | ||
43 | + } | ||
44 | + | ||
45 | + @Override | ||
46 | + public ExtType type() { | ||
47 | + return type; | ||
48 | + } | ||
49 | + | ||
50 | + /** | ||
51 | + * Returns the local speaker prefix list. | ||
52 | + * | ||
53 | + * @return the ExtPrefix | ||
54 | + */ | ||
55 | + @Override | ||
56 | + public ExtPrefix localSpeaker() { | ||
57 | + return localSpeaker; | ||
58 | + } | ||
59 | + | ||
60 | + /** | ||
61 | + * Returns the remote speaker prefix list. | ||
62 | + * | ||
63 | + * @return the ExtPrefix | ||
64 | + */ | ||
65 | + @Override | ||
66 | + public ExtPrefix remoteSpeaker() { | ||
67 | + return remoteSpeaker; | ||
68 | + } | ||
69 | + | ||
70 | + /** | ||
71 | + * Returns whether this target is an exact match to the target given | ||
72 | + * in the argument. | ||
73 | + * | ||
74 | + * @param target other target to match | ||
75 | + * @return true if the target are an exact match, otherwise false | ||
76 | + */ | ||
77 | + @Override | ||
78 | + public boolean exactMatch(ExtTarget target) { | ||
79 | + return this.equals(target) && | ||
80 | + Objects.equals(this.localSpeaker, target.localSpeaker()) | ||
81 | + && Objects.equals(this.remoteSpeaker, target.remoteSpeaker()) | ||
82 | + && Objects.equals(this.type, target.type()); | ||
83 | + } | ||
84 | + | ||
85 | + @Override | ||
86 | + public int hashCode() { | ||
87 | + return Objects.hash(localSpeaker, remoteSpeaker, type); | ||
88 | + } | ||
89 | + | ||
90 | + @Override | ||
91 | + public boolean equals(Object obj) { | ||
92 | + if (this == obj) { | ||
93 | + return true; | ||
94 | + } | ||
95 | + if (obj instanceof DefaultExtTarget) { | ||
96 | + DefaultExtTarget that = (DefaultExtTarget) obj; | ||
97 | + return Objects.equals(localSpeaker, that.localSpeaker()) | ||
98 | + && Objects.equals(remoteSpeaker, that.remoteSpeaker()) | ||
99 | + && Objects.equals(this.type, that.type); | ||
100 | + } | ||
101 | + return false; | ||
102 | + } | ||
103 | + | ||
104 | + @Override | ||
105 | + public String toString() { | ||
106 | + return toStringHelper(this) | ||
107 | + .add("localSpeaker", localSpeaker) | ||
108 | + .add("remoteSpeaker", remoteSpeaker) | ||
109 | + .add("type", type) | ||
110 | + .toString(); | ||
111 | + } | ||
112 | + | ||
113 | + /** | ||
114 | + * Builder class for wide community target. | ||
115 | + */ | ||
116 | + public static class Builder implements ExtTarget.Builder { | ||
117 | + private ExtPrefix localSpeaker; | ||
118 | + private ExtPrefix remoteSpeaker; | ||
119 | + private ExtType type; | ||
120 | + | ||
121 | + @Override | ||
122 | + public Builder setLocalSpeaker(ExtPrefix localSpeaker) { | ||
123 | + this.localSpeaker = localSpeaker; | ||
124 | + return this; | ||
125 | + } | ||
126 | + | ||
127 | + @Override | ||
128 | + public Builder setRemoteSpeaker(ExtPrefix remoteSpeaker) { | ||
129 | + this.remoteSpeaker = remoteSpeaker; | ||
130 | + return this; | ||
131 | + } | ||
132 | + | ||
133 | + @Override | ||
134 | + public Builder setType(ExtType type) { | ||
135 | + this.type = type; | ||
136 | + return this; | ||
137 | + } | ||
138 | + | ||
139 | + @Override | ||
140 | + public ExtTarget build() { | ||
141 | + checkNotNull(localSpeaker, "localSpeaker cannot be null"); | ||
142 | + checkNotNull(remoteSpeaker, "remoteSpeaker cannot be null"); | ||
143 | + return new DefaultExtTarget(localSpeaker, remoteSpeaker, type); | ||
144 | + } | ||
145 | + } | ||
146 | +} | ||
... | \ 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.flowapi; | ||
17 | + | ||
18 | +import java.util.List; | ||
19 | +import java.util.Objects; | ||
20 | + | ||
21 | +import static com.google.common.base.MoreObjects.toStringHelper; | ||
22 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
23 | + | ||
24 | +/** | ||
25 | + * Tcp flag extension implementation. | ||
26 | + */ | ||
27 | +public class DefaultExtTcpFlag implements ExtTcpFlag { | ||
28 | + | ||
29 | + private List<ExtOperatorValue> tcpFlag; | ||
30 | + private ExtType type; | ||
31 | + | ||
32 | + /** | ||
33 | + * Creates an object of type DefaultExtTcpFlag which contains tcp flag. | ||
34 | + * | ||
35 | + * @param tcpFlag is a Tcp Flag rule list | ||
36 | + * @param type ExtType type | ||
37 | + */ | ||
38 | + DefaultExtTcpFlag(List<ExtOperatorValue> tcpFlag, ExtType type) { | ||
39 | + this.tcpFlag = tcpFlag; | ||
40 | + this.type = type; | ||
41 | + } | ||
42 | + | ||
43 | + @Override | ||
44 | + public ExtType type() { | ||
45 | + return type; | ||
46 | + } | ||
47 | + | ||
48 | + @Override | ||
49 | + public List<ExtOperatorValue> tcpFlag() { | ||
50 | + return tcpFlag; | ||
51 | + } | ||
52 | + | ||
53 | + @Override | ||
54 | + public boolean exactMatch(ExtTcpFlag flag) { | ||
55 | + return this.equals(tcpFlag) && | ||
56 | + Objects.equals(this.tcpFlag, flag.tcpFlag()) | ||
57 | + && Objects.equals(this.type, flag.type()); | ||
58 | + } | ||
59 | + | ||
60 | + @Override | ||
61 | + public int hashCode() { | ||
62 | + return Objects.hash(tcpFlag, type); | ||
63 | + } | ||
64 | + | ||
65 | + @Override | ||
66 | + public boolean equals(Object obj) { | ||
67 | + if (this == obj) { | ||
68 | + return true; | ||
69 | + } | ||
70 | + if (obj instanceof DefaultExtTcpFlag) { | ||
71 | + DefaultExtTcpFlag that = (DefaultExtTcpFlag) obj; | ||
72 | + return Objects.equals(tcpFlag, that.tcpFlag()) | ||
73 | + && Objects.equals(this.type, that.type()); | ||
74 | + } | ||
75 | + return false; | ||
76 | + } | ||
77 | + | ||
78 | + @Override | ||
79 | + public String toString() { | ||
80 | + return toStringHelper(this) | ||
81 | + .add("tcpFlag", tcpFlag.toString()) | ||
82 | + .add("type", type.toString()) | ||
83 | + .toString(); | ||
84 | + } | ||
85 | + | ||
86 | + /** | ||
87 | + * Builder class for extension tcp flag. | ||
88 | + */ | ||
89 | + public static class Builder implements ExtTcpFlag.Builder { | ||
90 | + private List<ExtOperatorValue> tcpFlag; | ||
91 | + private ExtType type; | ||
92 | + | ||
93 | + @Override | ||
94 | + public Builder setTcpFlag(List<ExtOperatorValue> tcpFlag) { | ||
95 | + this.tcpFlag = tcpFlag; | ||
96 | + return this; | ||
97 | + } | ||
98 | + | ||
99 | + @Override | ||
100 | + public Builder setType(ExtType type) { | ||
101 | + this.type = type; | ||
102 | + return this; | ||
103 | + } | ||
104 | + | ||
105 | + @Override | ||
106 | + public ExtTcpFlag build() { | ||
107 | + checkNotNull(tcpFlag, "tcpFlag cannot be null"); | ||
108 | + return new DefaultExtTcpFlag(tcpFlag, type); | ||
109 | + } | ||
110 | + } | ||
111 | +} |
apps/bgpflowspec/flowapi/src/main/java/org/onosproject/flowapi/DefaultExtTrafficAction.java
0 → 100755
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.flowapi; | ||
17 | + | ||
18 | +import java.util.Objects; | ||
19 | + | ||
20 | +import static com.google.common.base.MoreObjects.toStringHelper; | ||
21 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
22 | + | ||
23 | +/** | ||
24 | + * Extended traffic action implementation. | ||
25 | + */ | ||
26 | +public class DefaultExtTrafficAction implements ExtTrafficAction { | ||
27 | + | ||
28 | + private boolean terminal; | ||
29 | + private boolean sample; | ||
30 | + private boolean rpd; | ||
31 | + private ExtType type; | ||
32 | + | ||
33 | + /** | ||
34 | + * Creates an object of type DefaultExtTrafficAction which contains traffic action flag. | ||
35 | + * | ||
36 | + * @param terminal traffic action terminal bit | ||
37 | + * @param sample is a traffic action sampling | ||
38 | + * @param rpd traffic action rpd bit | ||
39 | + * @param type ExtType type | ||
40 | + */ | ||
41 | + DefaultExtTrafficAction(boolean terminal, boolean sample, boolean rpd, ExtType type) { | ||
42 | + this.terminal = terminal; | ||
43 | + this.sample = sample; | ||
44 | + this.rpd = rpd; | ||
45 | + this.type = type; | ||
46 | + } | ||
47 | + | ||
48 | + @Override | ||
49 | + public ExtType type() { | ||
50 | + return type; | ||
51 | + } | ||
52 | + | ||
53 | + @Override | ||
54 | + public boolean terminal() { | ||
55 | + return terminal; | ||
56 | + } | ||
57 | + | ||
58 | + @Override | ||
59 | + public boolean sample() { | ||
60 | + return sample; | ||
61 | + } | ||
62 | + | ||
63 | + @Override | ||
64 | + public boolean rpd() { | ||
65 | + return rpd; | ||
66 | + } | ||
67 | + | ||
68 | + @Override | ||
69 | + public boolean exactMatch(ExtTrafficAction value) { | ||
70 | + return this.equals(value) && | ||
71 | + Objects.equals(this.terminal, value.terminal()) | ||
72 | + && Objects.equals(this.sample, value.sample()) | ||
73 | + && Objects.equals(this.rpd, value.rpd()) | ||
74 | + && Objects.equals(this.type, value.type()); | ||
75 | + } | ||
76 | + | ||
77 | + @Override | ||
78 | + public int hashCode() { | ||
79 | + return Objects.hash(terminal, sample, rpd, type); | ||
80 | + } | ||
81 | + | ||
82 | + @Override | ||
83 | + public boolean equals(Object obj) { | ||
84 | + if (this == obj) { | ||
85 | + return true; | ||
86 | + } | ||
87 | + if (obj instanceof DefaultExtTrafficAction) { | ||
88 | + DefaultExtTrafficAction that = (DefaultExtTrafficAction) obj; | ||
89 | + return Objects.equals(terminal, that.terminal()) | ||
90 | + && Objects.equals(this.sample, that.sample()) | ||
91 | + && Objects.equals(this.rpd, that.rpd()) | ||
92 | + && Objects.equals(this.type, that.type()); | ||
93 | + } | ||
94 | + return false; | ||
95 | + } | ||
96 | + | ||
97 | + @Override | ||
98 | + public String toString() { | ||
99 | + return toStringHelper(this) | ||
100 | + .add("terminal", Boolean.valueOf(terminal).toString()) | ||
101 | + .add("sample", Boolean.valueOf(sample).toString()) | ||
102 | + .add("rpd", Boolean.valueOf(rpd).toString()) | ||
103 | + .add("type", type.toString()) | ||
104 | + .toString(); | ||
105 | + } | ||
106 | + | ||
107 | + /** | ||
108 | + * Builder class for extended traffic rate rule. | ||
109 | + */ | ||
110 | + public static class Builder implements ExtTrafficAction.Builder { | ||
111 | + private boolean terminal; | ||
112 | + private boolean sample; | ||
113 | + private boolean rpd; | ||
114 | + private ExtType type; | ||
115 | + | ||
116 | + @Override | ||
117 | + public Builder setTerminal(boolean terminal) { | ||
118 | + this.terminal = terminal; | ||
119 | + return this; | ||
120 | + } | ||
121 | + | ||
122 | + @Override | ||
123 | + public Builder setSample(boolean sample) { | ||
124 | + this.sample = sample; | ||
125 | + return this; | ||
126 | + } | ||
127 | + | ||
128 | + @Override | ||
129 | + public Builder setRpd(boolean rpd) { | ||
130 | + this.rpd = rpd; | ||
131 | + return this; | ||
132 | + } | ||
133 | + | ||
134 | + @Override | ||
135 | + public Builder setType(ExtType type) { | ||
136 | + this.type = type; | ||
137 | + return this; | ||
138 | + } | ||
139 | + | ||
140 | + @Override | ||
141 | + public ExtTrafficAction build() { | ||
142 | + checkNotNull(terminal, "terminal cannot be null"); | ||
143 | + checkNotNull(sample, "sample cannot be null"); | ||
144 | + checkNotNull(rpd, "rpd cannot be null"); | ||
145 | + return new DefaultExtTrafficAction(terminal, sample, rpd, type); | ||
146 | + } | ||
147 | + } | ||
148 | +} |
apps/bgpflowspec/flowapi/src/main/java/org/onosproject/flowapi/DefaultExtTrafficMarking.java
0 → 100755
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.flowapi; | ||
17 | + | ||
18 | +import java.util.Objects; | ||
19 | + | ||
20 | +import static com.google.common.base.MoreObjects.toStringHelper; | ||
21 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
22 | + | ||
23 | +/** | ||
24 | + * Extended traffic marking implementation. | ||
25 | + */ | ||
26 | +public class DefaultExtTrafficMarking implements ExtTrafficMarking { | ||
27 | + | ||
28 | + private byte marking; | ||
29 | + private ExtType type; | ||
30 | + | ||
31 | + /** | ||
32 | + * Creates an object of type DefaultExtTrafficMarking which contains traffic marking byte. | ||
33 | + * | ||
34 | + * @param marking is a marking rule | ||
35 | + * @param type ExtType type | ||
36 | + */ | ||
37 | + DefaultExtTrafficMarking(byte marking, ExtType type) { | ||
38 | + this.marking = marking; | ||
39 | + this.type = type; | ||
40 | + } | ||
41 | + | ||
42 | + @Override | ||
43 | + public ExtType type() { | ||
44 | + return type; | ||
45 | + } | ||
46 | + | ||
47 | + @Override | ||
48 | + public byte marking() { | ||
49 | + return marking; | ||
50 | + } | ||
51 | + | ||
52 | + @Override | ||
53 | + public boolean exactMatch(ExtTrafficMarking value) { | ||
54 | + return this.equals(value) && | ||
55 | + Objects.equals(this.marking, value.marking()) | ||
56 | + && Objects.equals(this.type, value.type()); | ||
57 | + } | ||
58 | + | ||
59 | + @Override | ||
60 | + public int hashCode() { | ||
61 | + return Objects.hash(marking, type); | ||
62 | + } | ||
63 | + | ||
64 | + @Override | ||
65 | + public boolean equals(Object obj) { | ||
66 | + if (this == obj) { | ||
67 | + return true; | ||
68 | + } | ||
69 | + if (obj instanceof DefaultExtTrafficMarking) { | ||
70 | + DefaultExtTrafficMarking that = (DefaultExtTrafficMarking) obj; | ||
71 | + return Objects.equals(marking, that.marking()) | ||
72 | + && Objects.equals(this.type, that.type()); | ||
73 | + } | ||
74 | + return false; | ||
75 | + } | ||
76 | + | ||
77 | + @Override | ||
78 | + public String toString() { | ||
79 | + return toStringHelper(this) | ||
80 | + .add("marking", marking) | ||
81 | + .add("type", type.toString()) | ||
82 | + .toString(); | ||
83 | + } | ||
84 | + | ||
85 | + /** | ||
86 | + * Builder class for extended traffic marking value rule. | ||
87 | + */ | ||
88 | + public static class Builder implements ExtTrafficMarking.Builder { | ||
89 | + private byte marking; | ||
90 | + private ExtType type; | ||
91 | + | ||
92 | + @Override | ||
93 | + public Builder setMarking(byte marking) { | ||
94 | + this.marking = marking; | ||
95 | + return this; | ||
96 | + } | ||
97 | + | ||
98 | + @Override | ||
99 | + public Builder setType(ExtType type) { | ||
100 | + this.type = type; | ||
101 | + return this; | ||
102 | + } | ||
103 | + | ||
104 | + @Override | ||
105 | + public ExtTrafficMarking build() { | ||
106 | + checkNotNull(marking, "marking cannot be null"); | ||
107 | + return new DefaultExtTrafficMarking(marking, type); | ||
108 | + } | ||
109 | + } | ||
110 | +} |
apps/bgpflowspec/flowapi/src/main/java/org/onosproject/flowapi/DefaultExtTrafficRate.java
0 → 100755
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.flowapi; | ||
17 | + | ||
18 | +import java.util.Objects; | ||
19 | + | ||
20 | +import static com.google.common.base.MoreObjects.toStringHelper; | ||
21 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
22 | + | ||
23 | +/** | ||
24 | + * Extended traffic rate implementation. | ||
25 | + */ | ||
26 | +public class DefaultExtTrafficRate implements ExtTrafficRate { | ||
27 | + | ||
28 | + private Short asn; | ||
29 | + private Float rate; | ||
30 | + private ExtType type; | ||
31 | + | ||
32 | + /** | ||
33 | + * Creates an object of type DefaultExtTrafficRate which contains traffic rate action. | ||
34 | + * | ||
35 | + * @param asn is a AS number | ||
36 | + * @param rate is a traffic rate in bytes per second | ||
37 | + * @param type ExtType type | ||
38 | + */ | ||
39 | + DefaultExtTrafficRate(short asn, float rate, ExtType type) { | ||
40 | + this.asn = Short.valueOf(asn); | ||
41 | + this.rate = Float.valueOf(rate); | ||
42 | + this.type = type; | ||
43 | + } | ||
44 | + | ||
45 | + @Override | ||
46 | + public ExtType type() { | ||
47 | + return type; | ||
48 | + } | ||
49 | + | ||
50 | + @Override | ||
51 | + public Short asn() { | ||
52 | + return asn; | ||
53 | + } | ||
54 | + | ||
55 | + @Override | ||
56 | + public Float rate() { | ||
57 | + return rate; | ||
58 | + } | ||
59 | + | ||
60 | + @Override | ||
61 | + public boolean exactMatch(ExtTrafficRate value) { | ||
62 | + return this.equals(value) && | ||
63 | + Objects.equals(this.asn, value.asn()) | ||
64 | + && Objects.equals(this.rate, value.rate()) | ||
65 | + && Objects.equals(this.type, value.type()); | ||
66 | + } | ||
67 | + | ||
68 | + @Override | ||
69 | + public int hashCode() { | ||
70 | + return Objects.hash(asn, rate, type); | ||
71 | + } | ||
72 | + | ||
73 | + @Override | ||
74 | + public boolean equals(Object obj) { | ||
75 | + if (this == obj) { | ||
76 | + return true; | ||
77 | + } | ||
78 | + if (obj instanceof DefaultExtTrafficRate) { | ||
79 | + DefaultExtTrafficRate that = (DefaultExtTrafficRate) obj; | ||
80 | + return Objects.equals(asn, that.asn()) | ||
81 | + && Objects.equals(this.rate, that.rate()) | ||
82 | + && Objects.equals(this.type, that.type()); | ||
83 | + } | ||
84 | + return false; | ||
85 | + } | ||
86 | + | ||
87 | + @Override | ||
88 | + public String toString() { | ||
89 | + return toStringHelper(this) | ||
90 | + .add("asn", asn.toString()) | ||
91 | + .add("rate", rate.toString()) | ||
92 | + .add("type", type.toString()) | ||
93 | + .toString(); | ||
94 | + } | ||
95 | + | ||
96 | + /** | ||
97 | + * Builder class for extended traffic rate rule. | ||
98 | + */ | ||
99 | + public static class Builder implements ExtTrafficRate.Builder { | ||
100 | + private Short asn; | ||
101 | + private Float rate; | ||
102 | + private ExtType type; | ||
103 | + | ||
104 | + @Override | ||
105 | + public Builder setAsn(short asn) { | ||
106 | + this.asn = Short.valueOf(asn); | ||
107 | + return this; | ||
108 | + } | ||
109 | + | ||
110 | + @Override | ||
111 | + public Builder setRate(float rate) { | ||
112 | + this.rate = Float.valueOf(rate); | ||
113 | + return this; | ||
114 | + } | ||
115 | + | ||
116 | + @Override | ||
117 | + public Builder setType(ExtType type) { | ||
118 | + this.type = type; | ||
119 | + return this; | ||
120 | + } | ||
121 | + | ||
122 | + @Override | ||
123 | + public ExtTrafficRate build() { | ||
124 | + checkNotNull(asn, "asn cannot be null"); | ||
125 | + checkNotNull(rate, "rate cannot be null"); | ||
126 | + return new DefaultExtTrafficRate(asn, rate, type); | ||
127 | + } | ||
128 | + } | ||
129 | +} |
apps/bgpflowspec/flowapi/src/main/java/org/onosproject/flowapi/DefaultExtTrafficRedirect.java
0 → 100755
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.flowapi; | ||
17 | + | ||
18 | +import java.util.Objects; | ||
19 | + | ||
20 | +import static com.google.common.base.MoreObjects.toStringHelper; | ||
21 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
22 | + | ||
23 | +/** | ||
24 | + * Extended traffic redirect implementation. | ||
25 | + */ | ||
26 | +public class DefaultExtTrafficRedirect implements ExtTrafficRedirect { | ||
27 | + | ||
28 | + private String redirect; | ||
29 | + private ExtType type; | ||
30 | + | ||
31 | + /** | ||
32 | + * Creates an object of type DefaultExtTrafficRedirect which contains traffic redirect action. | ||
33 | + * | ||
34 | + * @param redirect is a redirect rule | ||
35 | + * @param type ExtType type | ||
36 | + */ | ||
37 | + DefaultExtTrafficRedirect(String redirect, ExtType type) { | ||
38 | + this.redirect = redirect; | ||
39 | + this.type = type; | ||
40 | + } | ||
41 | + | ||
42 | + @Override | ||
43 | + public ExtType type() { | ||
44 | + return type; | ||
45 | + } | ||
46 | + | ||
47 | + @Override | ||
48 | + public String redirect() { | ||
49 | + return redirect; | ||
50 | + } | ||
51 | + | ||
52 | + @Override | ||
53 | + public boolean exactMatch(ExtTrafficRedirect value) { | ||
54 | + return this.equals(value) && | ||
55 | + Objects.equals(this.redirect, value.redirect()) | ||
56 | + && Objects.equals(this.type, value.type()); | ||
57 | + } | ||
58 | + | ||
59 | + @Override | ||
60 | + public int hashCode() { | ||
61 | + return Objects.hash(redirect, type); | ||
62 | + } | ||
63 | + | ||
64 | + @Override | ||
65 | + public boolean equals(Object obj) { | ||
66 | + if (this == obj) { | ||
67 | + return true; | ||
68 | + } | ||
69 | + if (obj instanceof DefaultExtTrafficRedirect) { | ||
70 | + DefaultExtTrafficRedirect that = (DefaultExtTrafficRedirect) obj; | ||
71 | + return Objects.equals(redirect, that.redirect()) | ||
72 | + && Objects.equals(this.type, that.type()); | ||
73 | + } | ||
74 | + return false; | ||
75 | + } | ||
76 | + | ||
77 | + @Override | ||
78 | + public String toString() { | ||
79 | + return toStringHelper(this) | ||
80 | + .add("redirect", redirect.toString()) | ||
81 | + .add("type", type.toString()) | ||
82 | + .toString(); | ||
83 | + } | ||
84 | + | ||
85 | + /** | ||
86 | + * Builder class for extended redirect value rule. | ||
87 | + */ | ||
88 | + public static class Builder implements ExtTrafficRedirect.Builder { | ||
89 | + private String redirect; | ||
90 | + private ExtType type; | ||
91 | + | ||
92 | + @Override | ||
93 | + public Builder setRedirect(String redirect) { | ||
94 | + this.redirect = redirect; | ||
95 | + return this; | ||
96 | + } | ||
97 | + | ||
98 | + @Override | ||
99 | + public Builder setType(ExtType type) { | ||
100 | + this.type = type; | ||
101 | + return this; | ||
102 | + } | ||
103 | + | ||
104 | + @Override | ||
105 | + public ExtTrafficRedirect build() { | ||
106 | + checkNotNull(redirect, "redirect cannot be null"); | ||
107 | + return new DefaultExtTrafficRedirect(redirect, type); | ||
108 | + } | ||
109 | + } | ||
110 | +} |
apps/bgpflowspec/flowapi/src/main/java/org/onosproject/flowapi/DefaultExtWideCommunityInt.java
0 → 100755
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.flowapi; | ||
17 | + | ||
18 | +import java.util.ArrayList; | ||
19 | +import java.util.List; | ||
20 | +import java.util.Objects; | ||
21 | + | ||
22 | +import static com.google.common.base.MoreObjects.toStringHelper; | ||
23 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
24 | + | ||
25 | +/** | ||
26 | + * Wide community attributes for RPD implementation. | ||
27 | + */ | ||
28 | +public class DefaultExtWideCommunityInt implements ExtWideCommunityInt { | ||
29 | + | ||
30 | + private List<Integer> wCommInt; | ||
31 | + private ExtType type; | ||
32 | + | ||
33 | + /** | ||
34 | + * Creates an object of type DefaultExtWideCommunityInt which contains wide community attributes. | ||
35 | + * | ||
36 | + * @param wCommInt is a wide community value | ||
37 | + * @param type ExtType type | ||
38 | + */ | ||
39 | + DefaultExtWideCommunityInt(List<Integer> wCommInt, ExtType type) { | ||
40 | + this.wCommInt = wCommInt; | ||
41 | + this.type = type; | ||
42 | + } | ||
43 | + | ||
44 | + @Override | ||
45 | + public ExtType type() { | ||
46 | + return type; | ||
47 | + } | ||
48 | + | ||
49 | + @Override | ||
50 | + public List<Integer> communityInt() { | ||
51 | + return wCommInt; | ||
52 | + } | ||
53 | + | ||
54 | + @Override | ||
55 | + public boolean exactMatch(ExtWideCommunityInt value) { | ||
56 | + return this.equals(value) && | ||
57 | + Objects.equals(this.wCommInt, value.communityInt()) | ||
58 | + && Objects.equals(this.type, value.type()); | ||
59 | + } | ||
60 | + | ||
61 | + @Override | ||
62 | + public int hashCode() { | ||
63 | + return Objects.hash(wCommInt, type); | ||
64 | + } | ||
65 | + | ||
66 | + @Override | ||
67 | + public boolean equals(Object obj) { | ||
68 | + if (this == obj) { | ||
69 | + return true; | ||
70 | + } | ||
71 | + if (obj instanceof DefaultExtWideCommunityInt) { | ||
72 | + DefaultExtWideCommunityInt that = (DefaultExtWideCommunityInt) obj; | ||
73 | + return Objects.equals(wCommInt, that.communityInt()) | ||
74 | + && Objects.equals(this.type, that.type()); | ||
75 | + } | ||
76 | + return false; | ||
77 | + } | ||
78 | + | ||
79 | + @Override | ||
80 | + public String toString() { | ||
81 | + return toStringHelper(this) | ||
82 | + .add("value", wCommInt.toString()) | ||
83 | + .add("type", type.toString()) | ||
84 | + .toString(); | ||
85 | + } | ||
86 | + | ||
87 | + /** | ||
88 | + * Builder class for wide community value rule. | ||
89 | + */ | ||
90 | + public static class Builder implements ExtWideCommunityInt.Builder { | ||
91 | + private List<Integer> wCommInt = new ArrayList<>(); | ||
92 | + private ExtType type; | ||
93 | + | ||
94 | + @Override | ||
95 | + public Builder setwCommInt(Integer wCommInt) { | ||
96 | + this.wCommInt.add(wCommInt); | ||
97 | + return this; | ||
98 | + } | ||
99 | + | ||
100 | + @Override | ||
101 | + public Builder setType(ExtType type) { | ||
102 | + this.type = type; | ||
103 | + return this; | ||
104 | + } | ||
105 | + | ||
106 | + @Override | ||
107 | + public ExtWideCommunityInt build() { | ||
108 | + checkNotNull(wCommInt, "value cannot be null"); | ||
109 | + return new DefaultExtWideCommunityInt(wCommInt, type); | ||
110 | + } | ||
111 | + } | ||
112 | +} |
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.flowapi; | ||
17 | + | ||
18 | +import java.util.List; | ||
19 | + | ||
20 | +/** | ||
21 | + * Extended multivalue Dscp value class. | ||
22 | + */ | ||
23 | +public interface ExtDscpValue extends ExtFlowTypes { | ||
24 | + | ||
25 | + /** | ||
26 | + * Returns the ExtType. | ||
27 | + * | ||
28 | + * @return the ExtType | ||
29 | + */ | ||
30 | + ExtType type(); | ||
31 | + | ||
32 | + /** | ||
33 | + * Returns the dscp value operator value list. | ||
34 | + * | ||
35 | + * @return the dscp value operator value list | ||
36 | + */ | ||
37 | + List<ExtOperatorValue> dscpValue(); | ||
38 | + | ||
39 | + /** | ||
40 | + * Returns whether this dscp value list is an exact match to the dscp value list given | ||
41 | + * in the argument. | ||
42 | + * | ||
43 | + * @param dscpValue other dscp value to match against | ||
44 | + * @return true if the dscp value list are an exact match, otherwise false | ||
45 | + */ | ||
46 | + boolean exactMatch(ExtDscpValue dscpValue); | ||
47 | + | ||
48 | + /** | ||
49 | + * A dscp value extended builder.. | ||
50 | + */ | ||
51 | + interface Builder { | ||
52 | + | ||
53 | + /** | ||
54 | + * Assigns the ExtType to this object. | ||
55 | + * | ||
56 | + * @param type extended type | ||
57 | + * @return this the builder object | ||
58 | + */ | ||
59 | + Builder setType(ExtType type); | ||
60 | + | ||
61 | + /** | ||
62 | + * Assigns the dscp operator value to this object. | ||
63 | + * | ||
64 | + * @param dscpValue the dscp value | ||
65 | + * @return this the builder object | ||
66 | + */ | ||
67 | + Builder setDscpValue(List<ExtOperatorValue> dscpValue); | ||
68 | + | ||
69 | + /** | ||
70 | + * Builds a dscp value object. | ||
71 | + * | ||
72 | + * @return a dscp value object. | ||
73 | + */ | ||
74 | + ExtDscpValue build(); | ||
75 | + } | ||
76 | +} |
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.flowapi; | ||
17 | + | ||
18 | +import com.google.common.base.MoreObjects; | ||
19 | + | ||
20 | +import java.util.ArrayList; | ||
21 | +import java.util.List; | ||
22 | +import java.util.Objects; | ||
23 | + | ||
24 | +/** | ||
25 | + * Representation of Multi value flow container having custom rules. | ||
26 | + */ | ||
27 | +public final class ExtFlowContainer { | ||
28 | + | ||
29 | + private List<ExtFlowTypes> container = new ArrayList<>(); | ||
30 | + private String deviceId; | ||
31 | + | ||
32 | + /** | ||
33 | + * Creates an object of type ExtFlowContainer. | ||
34 | + */ | ||
35 | + public ExtFlowContainer(List<ExtFlowTypes> container) { | ||
36 | + this.container = container; | ||
37 | + } | ||
38 | + | ||
39 | + /** | ||
40 | + * Returns the ExtFlowContainer by setting its value. | ||
41 | + * | ||
42 | + * @return ExtFlowContainer | ||
43 | + */ | ||
44 | + public static ExtFlowContainer of(List<ExtFlowTypes> container) { | ||
45 | + return new ExtFlowContainer(container); | ||
46 | + } | ||
47 | + | ||
48 | + /** | ||
49 | + * Returns the list of ExtFlowTypes value. | ||
50 | + * | ||
51 | + * @return list of ExtFlowTypes | ||
52 | + */ | ||
53 | + public List<ExtFlowTypes> container() { | ||
54 | + return container; | ||
55 | + } | ||
56 | + | ||
57 | + /** | ||
58 | + * Returns the device Id. | ||
59 | + * | ||
60 | + * @return deviceId | ||
61 | + */ | ||
62 | + public String deviceId() { | ||
63 | + return deviceId; | ||
64 | + } | ||
65 | + | ||
66 | + /** | ||
67 | + * Adds the flow type to the container list. | ||
68 | + * | ||
69 | + * @param obj of ExtFlowTypes type | ||
70 | + */ | ||
71 | + public void add(ExtFlowTypes obj) { | ||
72 | + container.add(obj); | ||
73 | + } | ||
74 | + | ||
75 | + /** | ||
76 | + * Removes the flow type from the container list. | ||
77 | + * | ||
78 | + * @param obj of ExtFlowTypes type | ||
79 | + */ | ||
80 | + public void remove(ExtFlowTypes obj) { | ||
81 | + container.remove(obj); | ||
82 | + } | ||
83 | + | ||
84 | + /** | ||
85 | + * Sets the device Id to this container. | ||
86 | + * | ||
87 | + * @param deviceId to be set to this container | ||
88 | + */ | ||
89 | + public void setDeviceId(String deviceId) { | ||
90 | + this.deviceId = deviceId; | ||
91 | + } | ||
92 | + | ||
93 | + @Override | ||
94 | + public int hashCode() { | ||
95 | + return Objects.hash(container); | ||
96 | + } | ||
97 | + | ||
98 | + @Override | ||
99 | + public boolean equals(Object obj) { | ||
100 | + if (this == obj) { | ||
101 | + return true; | ||
102 | + } | ||
103 | + if (!(obj instanceof ExtFlowContainer)) { | ||
104 | + return false; | ||
105 | + } | ||
106 | + final ExtFlowContainer other = (ExtFlowContainer) obj; | ||
107 | + return Objects.equals(this.container, other.container) | ||
108 | + && Objects.equals(this.deviceId, other.deviceId); | ||
109 | + } | ||
110 | + | ||
111 | + @Override | ||
112 | + public String toString() { | ||
113 | + return MoreObjects.toStringHelper(this) | ||
114 | + .add("container", container) | ||
115 | + .add("deviceId", deviceId) | ||
116 | + .toString(); | ||
117 | + } | ||
118 | +} |
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.flowapi; | ||
17 | + | ||
18 | +/** | ||
19 | + * Representation of BgpFlow container having custom rules. | ||
20 | + */ | ||
21 | +public interface ExtFlowTypes { | ||
22 | + | ||
23 | + /** | ||
24 | + * Bgp types. | ||
25 | + */ | ||
26 | + public enum ExtType { | ||
27 | + | ||
28 | + /** Extended flow rule key. */ | ||
29 | + EXT_FLOW_RULE_KEY(0), | ||
30 | + | ||
31 | + /** IPv4 destination address. */ | ||
32 | + IPV4_DST_PFX(1), | ||
33 | + | ||
34 | + /** IPv4 source address. */ | ||
35 | + IPV4_SRC_PFX(2), | ||
36 | + | ||
37 | + /** IP protocol list. */ | ||
38 | + IP_PROTO_LIST(3), | ||
39 | + | ||
40 | + /** Input port list. */ | ||
41 | + IN_PORT_LIST(4), | ||
42 | + | ||
43 | + /** Destination port list. */ | ||
44 | + DST_PORT_LIST(5), | ||
45 | + | ||
46 | + /** Source port list. */ | ||
47 | + SRC_PORT_LIST(6), | ||
48 | + | ||
49 | + /** ICMP type list. */ | ||
50 | + ICMP_TYPE_LIST(7), | ||
51 | + | ||
52 | + /** ICMP code list. */ | ||
53 | + ICMP_CODE_LIST(8), | ||
54 | + | ||
55 | + /** TCP flag list. */ | ||
56 | + TCP_FLAG_LIST(9), | ||
57 | + | ||
58 | + /** Packet length list. */ | ||
59 | + PACKET_LENGTH_LIST(10), | ||
60 | + | ||
61 | + /** DSCP Value component. */ | ||
62 | + DSCP_VALUE_LIST(11), | ||
63 | + | ||
64 | + /** Fragment list. */ | ||
65 | + FRAGMENT_LIST(12), | ||
66 | + | ||
67 | + /** Wide community flags. */ | ||
68 | + WIDE_COMM_FLAGS(13), | ||
69 | + | ||
70 | + /** Wide community hop count. */ | ||
71 | + WIDE_COMM_HOP_COUNT(14), | ||
72 | + | ||
73 | + /** Wide community community attribute. */ | ||
74 | + WIDE_COMM_COMMUNITY(15), | ||
75 | + | ||
76 | + /** Wide community context AS. */ | ||
77 | + WIDE_COMM_CONTEXT_AS(16), | ||
78 | + | ||
79 | + /** Wide community local AS. */ | ||
80 | + WIDE_COMM_LOCAL_AS(17), | ||
81 | + | ||
82 | + /** Wide community target prefixes. */ | ||
83 | + WIDE_COMM_TARGET(18), | ||
84 | + | ||
85 | + /** Wide community extended target prefixes. */ | ||
86 | + WIDE_COMM_EXT_TARGET(19), | ||
87 | + | ||
88 | + /** Wide community parameter. */ | ||
89 | + WIDE_COMM_PARAMETER(20), | ||
90 | + | ||
91 | + /** Traffic filtering actions. */ | ||
92 | + | ||
93 | + TRAFFIC_RATE(0x8006), | ||
94 | + TRAFFIC_ACTION(0x8007), | ||
95 | + TRAFFIC_REDIRECT(0x8008), | ||
96 | + TRAFFIC_MARKING(0x8009); | ||
97 | + | ||
98 | + private int type; | ||
99 | + | ||
100 | + /** | ||
101 | + * Creates a new type. | ||
102 | + * | ||
103 | + * @param type type code | ||
104 | + */ | ||
105 | + ExtType(int type) { | ||
106 | + this.type = type; | ||
107 | + } | ||
108 | + | ||
109 | + /** | ||
110 | + * Returns the type object for this type code. | ||
111 | + * | ||
112 | + * @return ExtType object | ||
113 | + */ | ||
114 | + public int type() { | ||
115 | + return (type); | ||
116 | + } | ||
117 | + } | ||
118 | + | ||
119 | + ExtType type(); | ||
120 | +} |
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.flowapi; | ||
17 | + | ||
18 | +import java.util.List; | ||
19 | + | ||
20 | +/** | ||
21 | + * Extended multivalue Fragment value list class. | ||
22 | + */ | ||
23 | +public interface ExtFragment extends ExtFlowTypes { | ||
24 | + | ||
25 | + /** | ||
26 | + * Returns the ExtType. | ||
27 | + * | ||
28 | + * @return the ExtType | ||
29 | + */ | ||
30 | + ExtType type(); | ||
31 | + | ||
32 | + /** | ||
33 | + * Returns the fragment operator value list. | ||
34 | + * | ||
35 | + * @return the fragment operator value list | ||
36 | + */ | ||
37 | + List<ExtOperatorValue> fragment(); | ||
38 | + | ||
39 | + /** | ||
40 | + * Returns whether this fragment value list is an exact match to the fragment value list given | ||
41 | + * in the argument. | ||
42 | + * | ||
43 | + * @param fragment other fragment value to match against | ||
44 | + * @return true if the fragment value list are an exact match, otherwise false | ||
45 | + */ | ||
46 | + boolean exactMatch(ExtFragment fragment); | ||
47 | + | ||
48 | + /** | ||
49 | + * Extended fragment value builder.. | ||
50 | + */ | ||
51 | + interface Builder { | ||
52 | + | ||
53 | + /** | ||
54 | + * Assigns the ExtType to this object. | ||
55 | + * | ||
56 | + * @param type extended type | ||
57 | + * @return this the builder object | ||
58 | + */ | ||
59 | + Builder setType(ExtType type); | ||
60 | + | ||
61 | + /** | ||
62 | + * Assigns the fragment operator value to this object. | ||
63 | + * | ||
64 | + * @param fragment the fragment value | ||
65 | + * @return this the builder object | ||
66 | + */ | ||
67 | + Builder setFragment(List<ExtOperatorValue> fragment); | ||
68 | + | ||
69 | + /** | ||
70 | + * Builds a fragment value object. | ||
71 | + * | ||
72 | + * @return a fragment value object. | ||
73 | + */ | ||
74 | + ExtFragment build(); | ||
75 | + } | ||
76 | +} | ||
77 | + |
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.flowapi; | ||
17 | + | ||
18 | +import java.util.List; | ||
19 | + | ||
20 | +/** | ||
21 | + * Extended multivalue ICMP code class. | ||
22 | + */ | ||
23 | +public interface ExtIcmpCode extends ExtFlowTypes { | ||
24 | + | ||
25 | + /** | ||
26 | + * Returns the ExtType. | ||
27 | + * | ||
28 | + * @return the ExtType | ||
29 | + */ | ||
30 | + ExtType type(); | ||
31 | + | ||
32 | + /** | ||
33 | + * Returns the Icmp code operator value list. | ||
34 | + * | ||
35 | + * @return the Icmp code operator value list | ||
36 | + */ | ||
37 | + List<ExtOperatorValue> icmpCode(); | ||
38 | + | ||
39 | + /** | ||
40 | + * Returns whether this Icmp code list is an exact match to the Icmp code list given | ||
41 | + * in the argument. | ||
42 | + * | ||
43 | + * @param icmpCode other Icmp code to match against | ||
44 | + * @return true if the Icmp code list are an exact match, otherwise false | ||
45 | + */ | ||
46 | + boolean exactMatch(ExtIcmpCode icmpCode); | ||
47 | + | ||
48 | + /** | ||
49 | + * An Icmp code extension builder.. | ||
50 | + */ | ||
51 | + interface Builder { | ||
52 | + | ||
53 | + /** | ||
54 | + * Assigns the ExtType to this object. | ||
55 | + * | ||
56 | + * @param type extended type | ||
57 | + * @return this the builder object | ||
58 | + */ | ||
59 | + Builder setType(ExtType type); | ||
60 | + | ||
61 | + /** | ||
62 | + * Assigns the Icmp code operator value to this object. | ||
63 | + * | ||
64 | + * @param icmpCode the Icmp code operator value combination | ||
65 | + * @return this the builder object | ||
66 | + */ | ||
67 | + Builder setIcmpCode(List<ExtOperatorValue> icmpCode); | ||
68 | + | ||
69 | + /** | ||
70 | + * Builds a Icmp code object. | ||
71 | + * | ||
72 | + * @return a Tcmp code object. | ||
73 | + */ | ||
74 | + ExtIcmpCode build(); | ||
75 | + } | ||
76 | +} |
1 | +/* | ||
2 | + * Copyright 2016 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.flowapi; | ||
17 | + | ||
18 | +import java.util.List; | ||
19 | + | ||
20 | +/** | ||
21 | + * Extended multivalue ICMP type class. | ||
22 | + */ | ||
23 | +public interface ExtIcmpType extends ExtFlowTypes { | ||
24 | + | ||
25 | + /** | ||
26 | + * Returns the ExtType. | ||
27 | + * | ||
28 | + * @return the ExtType | ||
29 | + */ | ||
30 | + ExtType type(); | ||
31 | + | ||
32 | + /** | ||
33 | + * Returns the Icmp type operator value list. | ||
34 | + * | ||
35 | + * @return the Icmp type operator value list | ||
36 | + */ | ||
37 | + List<ExtOperatorValue> icmpType(); | ||
38 | + | ||
39 | + /** | ||
40 | + * Returns whether this Icmp type list is an exact match to the Icmp type list given | ||
41 | + * in the argument. | ||
42 | + * | ||
43 | + * @param icmpType other Icmp type to match against | ||
44 | + * @return true if the Icmp type list are an exact match, otherwise false | ||
45 | + */ | ||
46 | + boolean exactMatch(ExtIcmpType icmpType); | ||
47 | + | ||
48 | + /** | ||
49 | + * An Icmp type extension builder.. | ||
50 | + */ | ||
51 | + interface Builder { | ||
52 | + | ||
53 | + /** | ||
54 | + * Assigns the ExtType to this object. | ||
55 | + * | ||
56 | + * @param type extended type | ||
57 | + * @return this the builder object | ||
58 | + */ | ||
59 | + Builder setType(ExtType type); | ||
60 | + | ||
61 | + /** | ||
62 | + * Assigns the Icmp type operator value to this object. | ||
63 | + * | ||
64 | + * @param icmpType the Icmp type operator value combination | ||
65 | + * @return this the builder object | ||
66 | + */ | ||
67 | + Builder setIcmpType(List<ExtOperatorValue> icmpType); | ||
68 | + | ||
69 | + /** | ||
70 | + * Builds a Icmp type object. | ||
71 | + * | ||
72 | + * @return a Tcmp type object. | ||
73 | + */ | ||
74 | + ExtIcmpType build(); | ||
75 | + } | ||
76 | +} |
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.flowapi; | ||
17 | + | ||
18 | +import java.util.List; | ||
19 | + | ||
20 | +/** | ||
21 | + * Extended multivalue Ip protocol class. | ||
22 | + */ | ||
23 | +public interface ExtIpProtocol extends ExtFlowTypes { | ||
24 | + | ||
25 | + /** | ||
26 | + * Returns the ExtType. | ||
27 | + * | ||
28 | + * @return the ExtType | ||
29 | + */ | ||
30 | + ExtType type(); | ||
31 | + | ||
32 | + /** | ||
33 | + * Returns the Ip protocol operator value list. | ||
34 | + * | ||
35 | + * @return the Ip protocol operator value list | ||
36 | + */ | ||
37 | + List<ExtOperatorValue> ipProtocol(); | ||
38 | + | ||
39 | + /** | ||
40 | + * Returns whether this Ip protocol list is an exact match to the Ip protocol list given | ||
41 | + * in the argument. | ||
42 | + * | ||
43 | + * @param ipProto other Ip protocols list to match against | ||
44 | + * @return true if the Ip protocols list are an exact match, otherwise false | ||
45 | + */ | ||
46 | + boolean exactMatch(ExtIpProtocol ipProto); | ||
47 | + | ||
48 | + /** | ||
49 | + * Ip protocol extension builder. | ||
50 | + */ | ||
51 | + interface Builder { | ||
52 | + | ||
53 | + /** | ||
54 | + * Assigns the ExtType to this object. | ||
55 | + * | ||
56 | + * @param type extended type | ||
57 | + * @return this the builder object | ||
58 | + */ | ||
59 | + Builder setType(ExtType type); | ||
60 | + | ||
61 | + /** | ||
62 | + * Adds the Ip protocol operator value to this object. | ||
63 | + * | ||
64 | + * @param ipProto is the operator-value combination | ||
65 | + * @return this the builder object | ||
66 | + */ | ||
67 | + Builder setIpProtocol(List<ExtOperatorValue> ipProto); | ||
68 | + | ||
69 | + /** | ||
70 | + * Builds a Ip protocol object. | ||
71 | + * | ||
72 | + * @return a Ip protocol object. | ||
73 | + */ | ||
74 | + ExtIpProtocol build(); | ||
75 | + } | ||
76 | +} |
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.flowapi; | ||
17 | + | ||
18 | +/** | ||
19 | + * Ext flwo key name class. | ||
20 | + */ | ||
21 | +public interface ExtKeyName extends ExtFlowTypes { | ||
22 | + | ||
23 | + /** | ||
24 | + * Returns the ExtType. | ||
25 | + * | ||
26 | + * @return the ExtType | ||
27 | + */ | ||
28 | + ExtType type(); | ||
29 | + | ||
30 | + /** | ||
31 | + * Returns the key name identifier for the flow. | ||
32 | + * | ||
33 | + * @return the key name | ||
34 | + */ | ||
35 | + String keyName(); | ||
36 | + | ||
37 | + /** | ||
38 | + * Returns whether this key name is an exact match to the key name given | ||
39 | + * in the argument. | ||
40 | + * | ||
41 | + * @param key other key name to match against | ||
42 | + * @return true if the key name are an exact match, otherwise false | ||
43 | + */ | ||
44 | + boolean exactMatch(ExtKeyName key); | ||
45 | + | ||
46 | + /** | ||
47 | + * A key name value list builder.. | ||
48 | + */ | ||
49 | + interface Builder { | ||
50 | + | ||
51 | + /** | ||
52 | + * Assigns the ExtType to this object. | ||
53 | + * | ||
54 | + * @param type extended type | ||
55 | + * @return this the builder object | ||
56 | + */ | ||
57 | + Builder setType(ExtType type); | ||
58 | + | ||
59 | + /** | ||
60 | + * Assigns the key name to this object. | ||
61 | + * | ||
62 | + * @param key the key name | ||
63 | + * @return this the builder object | ||
64 | + */ | ||
65 | + Builder setKeyName(String key); | ||
66 | + | ||
67 | + /** | ||
68 | + * Builds a key name object. | ||
69 | + * | ||
70 | + * @return a key name object. | ||
71 | + */ | ||
72 | + ExtKeyName build(); | ||
73 | + } | ||
74 | +} |
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.flowapi; | ||
17 | + | ||
18 | +import com.google.common.base.MoreObjects; | ||
19 | +import org.slf4j.Logger; | ||
20 | +import org.slf4j.LoggerFactory; | ||
21 | + | ||
22 | +import java.util.Arrays; | ||
23 | +import java.util.Objects; | ||
24 | + | ||
25 | +/** | ||
26 | + * Flow specification type operator and value implementation. | ||
27 | + */ | ||
28 | +public class ExtOperatorValue { | ||
29 | + | ||
30 | + protected static final Logger log = LoggerFactory.getLogger(ExtOperatorValue.class); | ||
31 | + | ||
32 | + private final byte option; | ||
33 | + private final byte[] value; | ||
34 | + | ||
35 | + /** | ||
36 | + * Creates an object of type ExtOperatorValue. | ||
37 | + * | ||
38 | + * @param option for a specific flow type | ||
39 | + * @param value for a specific flow type | ||
40 | + */ | ||
41 | + public ExtOperatorValue(byte option, byte[] value) { | ||
42 | + this.option = option; | ||
43 | + this.value = Arrays.copyOf(value, value.length); | ||
44 | + } | ||
45 | + | ||
46 | + /** | ||
47 | + * Returns option of the flow type. | ||
48 | + * | ||
49 | + * @return option of the flow type | ||
50 | + */ | ||
51 | + public byte option() { | ||
52 | + return option; | ||
53 | + } | ||
54 | + | ||
55 | + /** | ||
56 | + * Returns value of the flow type. | ||
57 | + * | ||
58 | + * @return value of the flow type | ||
59 | + */ | ||
60 | + public byte[] value() { | ||
61 | + return value; | ||
62 | + } | ||
63 | + | ||
64 | + @Override | ||
65 | + public int hashCode() { | ||
66 | + return Objects.hash(option, Arrays.hashCode(value)); | ||
67 | + } | ||
68 | + | ||
69 | + @Override | ||
70 | + public boolean equals(Object obj) { | ||
71 | + if (this == obj) { | ||
72 | + return true; | ||
73 | + } | ||
74 | + if (obj instanceof ExtOperatorValue) { | ||
75 | + ExtOperatorValue other = (ExtOperatorValue) obj; | ||
76 | + return Objects.equals(this.option, other.option) && Arrays.equals(this.value, other.value); | ||
77 | + } | ||
78 | + return false; | ||
79 | + } | ||
80 | + | ||
81 | + @Override | ||
82 | + public String toString() { | ||
83 | + return MoreObjects.toStringHelper(getClass()).add("option", option).add("value", value).toString(); | ||
84 | + } | ||
85 | +} |
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.flowapi; | ||
17 | + | ||
18 | +import java.util.List; | ||
19 | + | ||
20 | +/** | ||
21 | + * Extended multivalue packet length list class. | ||
22 | + */ | ||
23 | +public interface ExtPacketLength extends ExtFlowTypes { | ||
24 | + | ||
25 | + /** | ||
26 | + * Returns the ExtType. | ||
27 | + * | ||
28 | + * @return the ExtType | ||
29 | + */ | ||
30 | + ExtType type(); | ||
31 | + | ||
32 | + /** | ||
33 | + * Returns the packet length operator value list. | ||
34 | + * | ||
35 | + * @return the packet length operator value list | ||
36 | + */ | ||
37 | + List<ExtOperatorValue> packetLength(); | ||
38 | + | ||
39 | + /** | ||
40 | + * Returns whether this packet length list is an exact match to the packet length list given | ||
41 | + * in the argument. | ||
42 | + * | ||
43 | + * @param packetLength other packet length to match against | ||
44 | + * @return true if the packet length list are an exact match, otherwise false | ||
45 | + */ | ||
46 | + boolean exactMatch(ExtPacketLength packetLength); | ||
47 | + | ||
48 | + /** | ||
49 | + * A packet length extended builder.. | ||
50 | + */ | ||
51 | + interface Builder { | ||
52 | + | ||
53 | + /** | ||
54 | + * Assigns the ExtType to this object. | ||
55 | + * | ||
56 | + * @param type extended type | ||
57 | + * @return this the builder object | ||
58 | + */ | ||
59 | + Builder setType(ExtType type); | ||
60 | + | ||
61 | + /** | ||
62 | + * Assigns the packet length list to this object. | ||
63 | + * | ||
64 | + * @param packetLength the packet length | ||
65 | + * @return this the builder object | ||
66 | + */ | ||
67 | + Builder setPacketLength(List<ExtOperatorValue> packetLength); | ||
68 | + | ||
69 | + /** | ||
70 | + * Builds a packet length object. | ||
71 | + * | ||
72 | + * @return a packet length object. | ||
73 | + */ | ||
74 | + ExtPacketLength build(); | ||
75 | + } | ||
76 | +} |
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.flowapi; | ||
17 | + | ||
18 | +import java.util.List; | ||
19 | + | ||
20 | +/** | ||
21 | + * Extended multivalue port class. | ||
22 | + */ | ||
23 | +public interface ExtPort extends ExtFlowTypes { | ||
24 | + | ||
25 | + /** | ||
26 | + * Returns the ExtType. | ||
27 | + * | ||
28 | + * @return the ExtType | ||
29 | + */ | ||
30 | + ExtType type(); | ||
31 | + | ||
32 | + /** | ||
33 | + * Returns the port operator value list. | ||
34 | + * | ||
35 | + * @return the port operator value list | ||
36 | + */ | ||
37 | + List<ExtOperatorValue> port(); | ||
38 | + | ||
39 | + /** | ||
40 | + * Returns whether this port list is an exact match to the port list given | ||
41 | + * in the argument. | ||
42 | + * | ||
43 | + * @param port other port to match against | ||
44 | + * @return true if the port list are an exact match, otherwise false | ||
45 | + */ | ||
46 | + boolean exactMatch(ExtPort port); | ||
47 | + | ||
48 | + /** | ||
49 | + * An extended port extension builder.. | ||
50 | + */ | ||
51 | + interface Builder { | ||
52 | + | ||
53 | + /** | ||
54 | + * Assigns the ExtType to this object. | ||
55 | + * | ||
56 | + * @param type extended type | ||
57 | + * @return this the builder object | ||
58 | + */ | ||
59 | + Builder setType(ExtType type); | ||
60 | + | ||
61 | + /** | ||
62 | + * Assigns the port list operator value to this object. | ||
63 | + * | ||
64 | + * @param port is the operator-value combination | ||
65 | + * @return this the builder object | ||
66 | + */ | ||
67 | + Builder setPort(List<ExtOperatorValue> port); | ||
68 | + | ||
69 | + /** | ||
70 | + * Builds a port object. | ||
71 | + * | ||
72 | + * @return a port object. | ||
73 | + */ | ||
74 | + ExtPort build(); | ||
75 | + } | ||
76 | +} |
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.flowapi; | ||
17 | + | ||
18 | +import org.onlab.packet.IpPrefix; | ||
19 | + | ||
20 | +import java.util.List; | ||
21 | + | ||
22 | +/** | ||
23 | + * Ext Prefix class. | ||
24 | + */ | ||
25 | +public interface ExtPrefix extends ExtFlowTypes { | ||
26 | + | ||
27 | + /** | ||
28 | + * Returns the ExtType. | ||
29 | + * | ||
30 | + * @return the ExtType | ||
31 | + */ | ||
32 | + ExtType type(); | ||
33 | + | ||
34 | + /** | ||
35 | + * Returns the prefix list. | ||
36 | + * | ||
37 | + * @return the IpPrefix list | ||
38 | + */ | ||
39 | + List<IpPrefix> prefix(); | ||
40 | + | ||
41 | + /** | ||
42 | + * Returns whether this prefix list is an exact match to the prefix list given | ||
43 | + * in the argument. | ||
44 | + * | ||
45 | + * @param prefix other prefix to match against | ||
46 | + * @return true if the prefix are an exact match, otherwise false | ||
47 | + */ | ||
48 | + boolean exactMatch(ExtPrefix prefix); | ||
49 | + | ||
50 | + /** | ||
51 | + * A prefix builder.. | ||
52 | + */ | ||
53 | + interface Builder { | ||
54 | + | ||
55 | + /** | ||
56 | + * Assigns the ExtType to this object. | ||
57 | + * | ||
58 | + * @param type the prefix | ||
59 | + * @return this the builder object | ||
60 | + */ | ||
61 | + Builder setType(ExtType type); | ||
62 | + | ||
63 | + /** | ||
64 | + * Add the prefix to this object. | ||
65 | + * | ||
66 | + * @param prefix the prefix | ||
67 | + * @return this the builder object | ||
68 | + */ | ||
69 | + Builder setPrefix(IpPrefix prefix); | ||
70 | + | ||
71 | + /** | ||
72 | + * Builds a prefix object. | ||
73 | + * | ||
74 | + * @return a port chain. | ||
75 | + */ | ||
76 | + ExtPrefix build(); | ||
77 | + } | ||
78 | +} |
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.flowapi; | ||
17 | + | ||
18 | +/** | ||
19 | + * Ext target prefix class class. | ||
20 | + */ | ||
21 | +public interface ExtTarget extends ExtFlowTypes { | ||
22 | + | ||
23 | + /** | ||
24 | + * Returns the ExtType. | ||
25 | + * | ||
26 | + * @return the ExtType | ||
27 | + */ | ||
28 | + ExtType type(); | ||
29 | + | ||
30 | + /** | ||
31 | + * Returns the local speaker prefix list. | ||
32 | + * | ||
33 | + * @return the prefix list | ||
34 | + */ | ||
35 | + ExtPrefix localSpeaker(); | ||
36 | + | ||
37 | + /** | ||
38 | + * Returns the remote speaker prefix list. | ||
39 | + * | ||
40 | + * @return the prefix list | ||
41 | + */ | ||
42 | + ExtPrefix remoteSpeaker(); | ||
43 | + | ||
44 | + /** | ||
45 | + * Returns whether this prefix list is an exact match to the prefix list given | ||
46 | + * in the argument. | ||
47 | + * | ||
48 | + * @param prefix other prefix to match against | ||
49 | + * @return true if the prefix are an exact match, otherwise false | ||
50 | + */ | ||
51 | + boolean exactMatch(ExtTarget prefix); | ||
52 | + | ||
53 | + /** | ||
54 | + * A prefix builder.. | ||
55 | + */ | ||
56 | + interface Builder { | ||
57 | + | ||
58 | + /** | ||
59 | + * Assigns the ExtType to this object. | ||
60 | + * | ||
61 | + * @param type the prefix | ||
62 | + * @return this the builder object | ||
63 | + */ | ||
64 | + Builder setType(ExtType type); | ||
65 | + | ||
66 | + /** | ||
67 | + * Add the local speaker prefix to this object. | ||
68 | + * | ||
69 | + * @param localSpeaker list of local speakers | ||
70 | + * @return this the builder object | ||
71 | + */ | ||
72 | + Builder setLocalSpeaker(ExtPrefix localSpeaker); | ||
73 | + | ||
74 | + /** | ||
75 | + * Add the remote speaker prefix to this object. | ||
76 | + * | ||
77 | + * @param remoteSpeaker list of remote speakers | ||
78 | + * @return this the builder object | ||
79 | + */ | ||
80 | + Builder setRemoteSpeaker(ExtPrefix remoteSpeaker); | ||
81 | + | ||
82 | + /** | ||
83 | + * Builds a prefix object. | ||
84 | + * | ||
85 | + * @return a port chain. | ||
86 | + */ | ||
87 | + ExtTarget build(); | ||
88 | + } | ||
89 | +} |
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.flowapi; | ||
17 | + | ||
18 | +import java.util.List; | ||
19 | + | ||
20 | +/** | ||
21 | + * Extended multivalue Tcp Flags list class. | ||
22 | + */ | ||
23 | +public interface ExtTcpFlag extends ExtFlowTypes { | ||
24 | + | ||
25 | + /** | ||
26 | + * Returns the ExtType. | ||
27 | + * | ||
28 | + * @return the ExtType | ||
29 | + */ | ||
30 | + ExtType type(); | ||
31 | + | ||
32 | + /** | ||
33 | + * Returns the Tcp flag Extended multivalue. | ||
34 | + * | ||
35 | + * @return the Tcp flag Extended multivalue | ||
36 | + */ | ||
37 | + List<ExtOperatorValue> tcpFlag(); | ||
38 | + | ||
39 | + /** | ||
40 | + * Returns whether this Tcp flag list is an exact match to the Tcp flag list given | ||
41 | + * in the argument. | ||
42 | + * | ||
43 | + * @param tcpFlag other Tcp flag to match against | ||
44 | + * @return true if the Tcp flag list are an exact match, otherwise false | ||
45 | + */ | ||
46 | + boolean exactMatch(ExtTcpFlag tcpFlag); | ||
47 | + | ||
48 | + /** | ||
49 | + * A Tcp flag extended builder.. | ||
50 | + */ | ||
51 | + interface Builder { | ||
52 | + | ||
53 | + /** | ||
54 | + * Assigns the ExtType to this object. | ||
55 | + * | ||
56 | + * @param type extended type | ||
57 | + * @return this the builder object | ||
58 | + */ | ||
59 | + Builder setType(ExtType type); | ||
60 | + | ||
61 | + /** | ||
62 | + * Assigns the Tcp flag operator value to this object. | ||
63 | + * | ||
64 | + * @param tcpFlag the Tcp flag | ||
65 | + * @return this the builder object | ||
66 | + */ | ||
67 | + Builder setTcpFlag(List<ExtOperatorValue> tcpFlag); | ||
68 | + | ||
69 | + /** | ||
70 | + * Builds a Tcp flag object. | ||
71 | + * | ||
72 | + * @return a Tcp flag object. | ||
73 | + */ | ||
74 | + ExtTcpFlag build(); | ||
75 | + } | ||
76 | +} |
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.flowapi; | ||
17 | + | ||
18 | +/** | ||
19 | + * Extended flow traffic action class. | ||
20 | + */ | ||
21 | +public interface ExtTrafficAction extends ExtFlowTypes { | ||
22 | + | ||
23 | + /** | ||
24 | + * Returns the ExtType. | ||
25 | + * | ||
26 | + * @return the ExtType | ||
27 | + */ | ||
28 | + ExtType type(); | ||
29 | + | ||
30 | + /** | ||
31 | + * Returns the terminal action. | ||
32 | + * | ||
33 | + * @return the terminal action is set or not | ||
34 | + */ | ||
35 | + boolean terminal(); | ||
36 | + | ||
37 | + /** | ||
38 | + * Returns the traffic sampling. | ||
39 | + * | ||
40 | + * @return the traffic sampling set or not | ||
41 | + */ | ||
42 | + boolean sample(); | ||
43 | + | ||
44 | + /** | ||
45 | + * Returns the traffic action to be taken is rpd. | ||
46 | + * | ||
47 | + * @return the traffic action rpd is set or not | ||
48 | + */ | ||
49 | + boolean rpd(); | ||
50 | + | ||
51 | + /** | ||
52 | + * Returns whether this traffic action is an exact match to the traffic action given | ||
53 | + * in the argument. | ||
54 | + * | ||
55 | + * @param trafficAction other traffic action to match against | ||
56 | + * @return true if the traffic action are an exact match, otherwise false | ||
57 | + */ | ||
58 | + boolean exactMatch(ExtTrafficAction trafficAction); | ||
59 | + | ||
60 | + /** | ||
61 | + * A traffic action builder.. | ||
62 | + */ | ||
63 | + interface Builder { | ||
64 | + | ||
65 | + /** | ||
66 | + * Assigns the ExtType to this object. | ||
67 | + * | ||
68 | + * @param type extended type | ||
69 | + * @return this the builder object | ||
70 | + */ | ||
71 | + Builder setType(ExtType type); | ||
72 | + | ||
73 | + /** | ||
74 | + * Assigns the terminal action to this object. | ||
75 | + * | ||
76 | + * @param terminal action | ||
77 | + * @return this the builder object | ||
78 | + */ | ||
79 | + Builder setTerminal(boolean terminal); | ||
80 | + | ||
81 | + /** | ||
82 | + * Assigns the traffic sampling to this object. | ||
83 | + * | ||
84 | + * @param sample to be done or not | ||
85 | + * @return this the builder object | ||
86 | + */ | ||
87 | + Builder setSample(boolean sample); | ||
88 | + | ||
89 | + /** | ||
90 | + * Assigns the traffic action rpd to this object. | ||
91 | + * | ||
92 | + * @param rpd rpd or not | ||
93 | + * @return this the builder object | ||
94 | + */ | ||
95 | + Builder setRpd(boolean rpd); | ||
96 | + | ||
97 | + /** | ||
98 | + * Builds a traffic action object. | ||
99 | + * | ||
100 | + * @return a traffic action object. | ||
101 | + */ | ||
102 | + ExtTrafficAction build(); | ||
103 | + } | ||
104 | +} |
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.flowapi; | ||
17 | + | ||
18 | +/** | ||
19 | + * Extended traffic marking class. | ||
20 | + */ | ||
21 | +public interface ExtTrafficMarking extends ExtFlowTypes { | ||
22 | + | ||
23 | + /** | ||
24 | + * Returns the ExtType. | ||
25 | + * | ||
26 | + * @return the ExtType | ||
27 | + */ | ||
28 | + ExtType type(); | ||
29 | + | ||
30 | + /** | ||
31 | + * Returns the traffic marking DSCP value. | ||
32 | + * | ||
33 | + * @return the marking rule | ||
34 | + */ | ||
35 | + byte marking(); | ||
36 | + | ||
37 | + /** | ||
38 | + * Returns whether this traffic marking is an exact match to the traffic marking given | ||
39 | + * in the argument. | ||
40 | + * | ||
41 | + * @param marking other traffic marking to match against | ||
42 | + * @return true if the traffic marking are an exact match, otherwise false | ||
43 | + */ | ||
44 | + boolean exactMatch(ExtTrafficMarking marking); | ||
45 | + | ||
46 | + /** | ||
47 | + * A traffic marking builder.. | ||
48 | + */ | ||
49 | + interface Builder { | ||
50 | + | ||
51 | + /** | ||
52 | + * Assigns the ExtType to this object. | ||
53 | + * | ||
54 | + * @param type extended type | ||
55 | + * @return this the builder object | ||
56 | + */ | ||
57 | + Builder setType(ExtType type); | ||
58 | + | ||
59 | + /** | ||
60 | + * Assigns the traffic marking to this object. | ||
61 | + * | ||
62 | + * @param marking the marking value | ||
63 | + * @return this the builder object | ||
64 | + */ | ||
65 | + Builder setMarking(byte marking); | ||
66 | + | ||
67 | + /** | ||
68 | + * Builds a traffic marking object. | ||
69 | + * | ||
70 | + * @return a marking value object. | ||
71 | + */ | ||
72 | + ExtTrafficMarking build(); | ||
73 | + } | ||
74 | +} |
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.flowapi; | ||
17 | + | ||
18 | +/** | ||
19 | + * Extended flow traffic rate class. | ||
20 | + */ | ||
21 | +public interface ExtTrafficRate extends ExtFlowTypes { | ||
22 | + | ||
23 | + /** | ||
24 | + * Returns the ExtType. | ||
25 | + * | ||
26 | + * @return the ExtType | ||
27 | + */ | ||
28 | + ExtType type(); | ||
29 | + | ||
30 | + /** | ||
31 | + * Returns the AS number. | ||
32 | + * | ||
33 | + * @return the 2 byte ASN | ||
34 | + */ | ||
35 | + Short asn(); | ||
36 | + | ||
37 | + /** | ||
38 | + * Returns the traffic rate. | ||
39 | + * | ||
40 | + * @return the floating point traffic rate | ||
41 | + */ | ||
42 | + Float rate(); | ||
43 | + | ||
44 | + /** | ||
45 | + * Returns whether this traffic rate is an exact match to the traffic rate given | ||
46 | + * in the argument. | ||
47 | + * | ||
48 | + * @param trafficRate other traffic rate to match against | ||
49 | + * @return true if the traffic rate list are an exact match, otherwise false | ||
50 | + */ | ||
51 | + boolean exactMatch(ExtTrafficRate trafficRate); | ||
52 | + | ||
53 | + /** | ||
54 | + * A traffic rate builder.. | ||
55 | + */ | ||
56 | + interface Builder { | ||
57 | + | ||
58 | + /** | ||
59 | + * Assigns the ExtType to this object. | ||
60 | + * | ||
61 | + * @param type extended type | ||
62 | + * @return this the builder object | ||
63 | + */ | ||
64 | + Builder setType(ExtType type); | ||
65 | + | ||
66 | + /** | ||
67 | + * Assigns the AS number to this object. | ||
68 | + * | ||
69 | + * @param asn the ASN | ||
70 | + * @return this the builder object | ||
71 | + */ | ||
72 | + Builder setAsn(short asn); | ||
73 | + | ||
74 | + /** | ||
75 | + * Assigns the traffic rate to this object. | ||
76 | + * | ||
77 | + * @param rate in floating point number bytes per second | ||
78 | + * @return this the builder object | ||
79 | + */ | ||
80 | + Builder setRate(float rate); | ||
81 | + | ||
82 | + /** | ||
83 | + * Builds a traffic rate object. | ||
84 | + * | ||
85 | + * @return a traffic rate object. | ||
86 | + */ | ||
87 | + ExtTrafficRate build(); | ||
88 | + } | ||
89 | +} |
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.flowapi; | ||
17 | + | ||
18 | +/** | ||
19 | + * Extended flow traffic redirect class. | ||
20 | + */ | ||
21 | +public interface ExtTrafficRedirect extends ExtFlowTypes { | ||
22 | + | ||
23 | + /** | ||
24 | + * Returns the ExtType. | ||
25 | + * | ||
26 | + * @return the ExtType | ||
27 | + */ | ||
28 | + ExtType type(); | ||
29 | + | ||
30 | + /** | ||
31 | + * Returns the traffic redirect in human readable format. | ||
32 | + * | ||
33 | + * @return the redirect rule | ||
34 | + */ | ||
35 | + String redirect(); | ||
36 | + | ||
37 | + /** | ||
38 | + * Returns whether this traffic redirect is an exact match to the traffic redirect given | ||
39 | + * in the argument. | ||
40 | + * | ||
41 | + * @param redirect other traffic redirect to match against | ||
42 | + * @return true if the traffic redirect are an exact match, otherwise false | ||
43 | + */ | ||
44 | + boolean exactMatch(ExtTrafficRedirect redirect); | ||
45 | + | ||
46 | + /** | ||
47 | + * A dscp value list builder.. | ||
48 | + */ | ||
49 | + interface Builder { | ||
50 | + | ||
51 | + /** | ||
52 | + * Assigns the ExtType to this object. | ||
53 | + * | ||
54 | + * @param type extended type | ||
55 | + * @return this the builder object | ||
56 | + */ | ||
57 | + Builder setType(ExtType type); | ||
58 | + | ||
59 | + /** | ||
60 | + * Assigns the traffic redirect to this object. | ||
61 | + * | ||
62 | + * @param redirect the redirect value | ||
63 | + * @return this the builder object | ||
64 | + */ | ||
65 | + Builder setRedirect(String redirect); | ||
66 | + | ||
67 | + /** | ||
68 | + * Builds a traffic redirect object. | ||
69 | + * | ||
70 | + * @return a redirect value object. | ||
71 | + */ | ||
72 | + ExtTrafficRedirect build(); | ||
73 | + } | ||
74 | +} |
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.flowapi; | ||
17 | + | ||
18 | +import java.util.List; | ||
19 | + | ||
20 | +/** | ||
21 | + * Extended wide community integer class. | ||
22 | + */ | ||
23 | +public interface ExtWideCommunityInt extends ExtFlowTypes { | ||
24 | + | ||
25 | + /** | ||
26 | + * Returns the ExtType. | ||
27 | + * | ||
28 | + * @return the ExtType | ||
29 | + */ | ||
30 | + ExtType type(); | ||
31 | + | ||
32 | + /** | ||
33 | + * Returns the wide community integer list. | ||
34 | + * | ||
35 | + * @return the wide community integer list | ||
36 | + */ | ||
37 | + List<Integer> communityInt(); | ||
38 | + | ||
39 | + /** | ||
40 | + * Returns whether this wide community integer is an exact match to the wide community int given | ||
41 | + * in the argument. | ||
42 | + * | ||
43 | + * @param wCommInt other wide community integer to match against | ||
44 | + * @return true if the wide community integer are an exact match, otherwise false | ||
45 | + */ | ||
46 | + boolean exactMatch(ExtWideCommunityInt wCommInt); | ||
47 | + | ||
48 | + /** | ||
49 | + * A wide community integer list builder.. | ||
50 | + */ | ||
51 | + interface Builder { | ||
52 | + | ||
53 | + /** | ||
54 | + * Assigns the ExtType to this object. | ||
55 | + * | ||
56 | + * @param type extended type | ||
57 | + * @return this the builder object | ||
58 | + */ | ||
59 | + Builder setType(ExtType type); | ||
60 | + | ||
61 | + /** | ||
62 | + * Assigns the wide community integer to this object. | ||
63 | + * | ||
64 | + * @param wCommInt the wide community integer | ||
65 | + * @return this the builder object | ||
66 | + */ | ||
67 | + Builder setwCommInt(Integer wCommInt); | ||
68 | + | ||
69 | + /** | ||
70 | + * Builds a wide community integer object. | ||
71 | + * | ||
72 | + * @return a wide community integer value object. | ||
73 | + */ | ||
74 | + ExtWideCommunityInt build(); | ||
75 | + } | ||
76 | +} |
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 | + | ||
17 | +/** | ||
18 | + * API bundle. | ||
19 | + */ | ||
20 | +package org.onosproject.flowapi; |
apps/bgpflowspec/flowapi/src/test/java/org/onosproject/flowapi/DefaultExtDscpValueTest.java
0 → 100644
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.flowapi; | ||
17 | + | ||
18 | +import com.google.common.testing.EqualsTester; | ||
19 | +import org.junit.Test; | ||
20 | + | ||
21 | +import java.util.ArrayList; | ||
22 | +import java.util.List; | ||
23 | + | ||
24 | +/** | ||
25 | + * Test for extended dscp value attribute. | ||
26 | + */ | ||
27 | +public class DefaultExtDscpValueTest { | ||
28 | + | ||
29 | + private List<ExtOperatorValue> dscpValue = new ArrayList<>(); | ||
30 | + private List<ExtOperatorValue> dscpValue1 = new ArrayList<>(); | ||
31 | + private ExtOperatorValue opVal = new ExtOperatorValue((byte) 1, new byte[100]); | ||
32 | + private ExtOperatorValue opVal1 = new ExtOperatorValue((byte) 1, new byte[200]); | ||
33 | + private ExtFlowTypes.ExtType type = ExtFlowTypes.ExtType.DSCP_VALUE_LIST; | ||
34 | + | ||
35 | + @Test | ||
36 | + public void basics() { | ||
37 | + dscpValue.add(opVal); | ||
38 | + dscpValue1.add(opVal1); | ||
39 | + DefaultExtDscpValue data = new DefaultExtDscpValue(dscpValue, type); | ||
40 | + DefaultExtDscpValue sameAsData = new DefaultExtDscpValue(dscpValue, type); | ||
41 | + DefaultExtDscpValue diffData = new DefaultExtDscpValue(dscpValue1, type); | ||
42 | + new EqualsTester().addEqualityGroup(data, sameAsData) | ||
43 | + .addEqualityGroup(diffData).testEquals(); | ||
44 | + } | ||
45 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
apps/bgpflowspec/flowapi/src/test/java/org/onosproject/flowapi/DefaultExtFragmentTest.java
0 → 100644
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.flowapi; | ||
17 | + | ||
18 | +import com.google.common.testing.EqualsTester; | ||
19 | +import org.junit.Test; | ||
20 | + | ||
21 | +import java.util.ArrayList; | ||
22 | +import java.util.List; | ||
23 | + | ||
24 | +/** | ||
25 | + * Test for extended fragment value attribute. | ||
26 | + */ | ||
27 | +public class DefaultExtFragmentTest { | ||
28 | + | ||
29 | + private List<ExtOperatorValue> fragment = new ArrayList<>(); | ||
30 | + private List<ExtOperatorValue> fragment1 = new ArrayList<>(); | ||
31 | + private ExtOperatorValue opVal = new ExtOperatorValue((byte) 1, new byte[100]); | ||
32 | + private ExtOperatorValue opVal1 = new ExtOperatorValue((byte) 1, new byte[200]); | ||
33 | + private ExtFlowTypes.ExtType type = ExtFlowTypes.ExtType.FRAGMENT_LIST; | ||
34 | + | ||
35 | + @Test | ||
36 | + public void basics() { | ||
37 | + fragment.add(opVal); | ||
38 | + fragment1.add(opVal1); | ||
39 | + DefaultExtFragment data = new DefaultExtFragment(fragment, type); | ||
40 | + DefaultExtFragment sameAsData = new DefaultExtFragment(fragment, type); | ||
41 | + DefaultExtFragment diffData = new DefaultExtFragment(fragment1, type); | ||
42 | + new EqualsTester().addEqualityGroup(data, sameAsData) | ||
43 | + .addEqualityGroup(diffData).testEquals(); | ||
44 | + } | ||
45 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
apps/bgpflowspec/flowapi/src/test/java/org/onosproject/flowapi/DefaultExtIcmpCodeTest.java
0 → 100644
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.flowapi; | ||
17 | + | ||
18 | +import com.google.common.testing.EqualsTester; | ||
19 | +import org.junit.Test; | ||
20 | + | ||
21 | +import java.util.ArrayList; | ||
22 | +import java.util.List; | ||
23 | + | ||
24 | +/** | ||
25 | + * Test for extended icmp code value attribute. | ||
26 | + */ | ||
27 | +public class DefaultExtIcmpCodeTest { | ||
28 | + | ||
29 | + private List<ExtOperatorValue> icmpCode = new ArrayList<>(); | ||
30 | + private List<ExtOperatorValue> icmpCode1 = new ArrayList<>(); | ||
31 | + private ExtOperatorValue opVal = new ExtOperatorValue((byte) 1, new byte[100]); | ||
32 | + private ExtOperatorValue opVal1 = new ExtOperatorValue((byte) 1, new byte[200]); | ||
33 | + private ExtFlowTypes.ExtType type = ExtFlowTypes.ExtType.ICMP_CODE_LIST; | ||
34 | + | ||
35 | + @Test | ||
36 | + public void basics() { | ||
37 | + icmpCode.add(opVal); | ||
38 | + icmpCode1.add(opVal1); | ||
39 | + DefaultExtIcmpCode data = new DefaultExtIcmpCode(icmpCode, type); | ||
40 | + DefaultExtIcmpCode sameAsData = new DefaultExtIcmpCode(icmpCode, type); | ||
41 | + DefaultExtIcmpCode diffData = new DefaultExtIcmpCode(icmpCode1, type); | ||
42 | + new EqualsTester().addEqualityGroup(data, sameAsData) | ||
43 | + .addEqualityGroup(diffData).testEquals(); | ||
44 | + } | ||
45 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
apps/bgpflowspec/flowapi/src/test/java/org/onosproject/flowapi/DefaultExtIcmpTypeTest.java
0 → 100644
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.flowapi; | ||
17 | + | ||
18 | + import com.google.common.testing.EqualsTester; | ||
19 | + import org.junit.Test; | ||
20 | + | ||
21 | + import java.util.ArrayList; | ||
22 | + import java.util.List; | ||
23 | + | ||
24 | +/** | ||
25 | + * Test for extended icmp type value attribute. | ||
26 | + */ | ||
27 | +public class DefaultExtIcmpTypeTest { | ||
28 | + | ||
29 | + private List<ExtOperatorValue> icmpType = new ArrayList<>(); | ||
30 | + private List<ExtOperatorValue> icmpType1 = new ArrayList<>(); | ||
31 | + private ExtOperatorValue opVal = new ExtOperatorValue((byte) 1, new byte[100]); | ||
32 | + private ExtOperatorValue opVal1 = new ExtOperatorValue((byte) 1, new byte[200]); | ||
33 | + private ExtFlowTypes.ExtType type = ExtFlowTypes.ExtType.ICMP_TYPE_LIST; | ||
34 | + | ||
35 | + @Test | ||
36 | + public void basics() { | ||
37 | + icmpType.add(opVal); | ||
38 | + icmpType1.add(opVal1); | ||
39 | + DefaultExtIcmpType data = new DefaultExtIcmpType(icmpType, type); | ||
40 | + DefaultExtIcmpType sameAsData = new DefaultExtIcmpType(icmpType, type); | ||
41 | + DefaultExtIcmpType diffData = new DefaultExtIcmpType(icmpType1, type); | ||
42 | + new EqualsTester().addEqualityGroup(data, sameAsData) | ||
43 | + .addEqualityGroup(diffData).testEquals(); | ||
44 | + } | ||
45 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
apps/bgpflowspec/flowapi/src/test/java/org/onosproject/flowapi/DefaultExtIpProtocolTest.java
0 → 100644
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.flowapi; | ||
17 | + | ||
18 | +import com.google.common.testing.EqualsTester; | ||
19 | +import org.junit.Test; | ||
20 | + | ||
21 | +import java.util.ArrayList; | ||
22 | +import java.util.List; | ||
23 | + | ||
24 | +/** | ||
25 | + * Test for extended icmp type value attribute. | ||
26 | + */ | ||
27 | +public class DefaultExtIpProtocolTest { | ||
28 | + | ||
29 | + private List<ExtOperatorValue> ipProtocol = new ArrayList<>(); | ||
30 | + private List<ExtOperatorValue> ipProtocol1 = new ArrayList<>(); | ||
31 | + private ExtOperatorValue opVal = new ExtOperatorValue((byte) 1, new byte[100]); | ||
32 | + private ExtOperatorValue opVal1 = new ExtOperatorValue((byte) 1, new byte[200]); | ||
33 | + private ExtFlowTypes.ExtType type = ExtFlowTypes.ExtType.IP_PROTO_LIST; | ||
34 | + | ||
35 | + @Test | ||
36 | + public void basics() { | ||
37 | + ipProtocol.add(opVal); | ||
38 | + ipProtocol1.add(opVal1); | ||
39 | + DefaultExtIpProtocol data = new DefaultExtIpProtocol(ipProtocol, type); | ||
40 | + DefaultExtIpProtocol sameAsData = new DefaultExtIpProtocol(ipProtocol, type); | ||
41 | + DefaultExtIpProtocol diffData = new DefaultExtIpProtocol(ipProtocol1, type); | ||
42 | + new EqualsTester().addEqualityGroup(data, sameAsData) | ||
43 | + .addEqualityGroup(diffData).testEquals(); | ||
44 | + } | ||
45 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
apps/bgpflowspec/flowapi/src/test/java/org/onosproject/flowapi/DefaultExtKeyNameTest.java
0 → 100644
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.flowapi; | ||
17 | + | ||
18 | +import com.google.common.testing.EqualsTester; | ||
19 | +import org.junit.Test; | ||
20 | + | ||
21 | +/** | ||
22 | + * Test for extended key name value attribute. | ||
23 | + */ | ||
24 | +public class DefaultExtKeyNameTest { | ||
25 | + | ||
26 | + private String keyName = new String("hello"); | ||
27 | + private String keyName1 = new String("Hi"); | ||
28 | + | ||
29 | + private ExtFlowTypes.ExtType type = ExtFlowTypes.ExtType.EXT_FLOW_RULE_KEY; | ||
30 | + | ||
31 | + @Test | ||
32 | + public void basics() { | ||
33 | + | ||
34 | + DefaultExtKeyName data = new DefaultExtKeyName(keyName, type); | ||
35 | + DefaultExtKeyName sameAsData = new DefaultExtKeyName(keyName, type); | ||
36 | + DefaultExtKeyName diffData = new DefaultExtKeyName(keyName1, type); | ||
37 | + new EqualsTester().addEqualityGroup(data, sameAsData) | ||
38 | + .addEqualityGroup(diffData).testEquals(); | ||
39 | + } | ||
40 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
apps/bgpflowspec/flowapi/src/test/java/org/onosproject/flowapi/DefaultExtPacketLengthTest.java
0 → 100644
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.flowapi; | ||
17 | + | ||
18 | +import com.google.common.testing.EqualsTester; | ||
19 | +import org.junit.Test; | ||
20 | + | ||
21 | +import java.util.ArrayList; | ||
22 | +import java.util.List; | ||
23 | + | ||
24 | +/** | ||
25 | + * Test for extended packet length value attribute. | ||
26 | + */ | ||
27 | +public class DefaultExtPacketLengthTest { | ||
28 | + | ||
29 | + private List<ExtOperatorValue> packetLength = new ArrayList<>(); | ||
30 | + private List<ExtOperatorValue> packetLength1 = new ArrayList<>(); | ||
31 | + private ExtOperatorValue opVal = new ExtOperatorValue((byte) 1, new byte[100]); | ||
32 | + private ExtOperatorValue opVal1 = new ExtOperatorValue((byte) 1, new byte[200]); | ||
33 | + private ExtFlowTypes.ExtType type = ExtFlowTypes.ExtType.PACKET_LENGTH_LIST; | ||
34 | + | ||
35 | + @Test | ||
36 | + public void basics() { | ||
37 | + packetLength.add(opVal); | ||
38 | + packetLength1.add(opVal1); | ||
39 | + DefaultExtPacketLength data = new DefaultExtPacketLength(packetLength, type); | ||
40 | + DefaultExtPacketLength sameAsData = new DefaultExtPacketLength(packetLength, type); | ||
41 | + DefaultExtPacketLength diffData = new DefaultExtPacketLength(packetLength1, type); | ||
42 | + new EqualsTester().addEqualityGroup(data, sameAsData) | ||
43 | + .addEqualityGroup(diffData).testEquals(); | ||
44 | + } | ||
45 | +} | ||
... | \ 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.flowapi; | ||
17 | + | ||
18 | + import com.google.common.testing.EqualsTester; | ||
19 | + import org.junit.Test; | ||
20 | + | ||
21 | + import java.util.ArrayList; | ||
22 | + import java.util.List; | ||
23 | + | ||
24 | +/** | ||
25 | + * Test for extended icmp type value attribute. | ||
26 | + */ | ||
27 | +public class DefaultExtPortTest { | ||
28 | + | ||
29 | + private List<ExtOperatorValue> port = new ArrayList<>(); | ||
30 | + private List<ExtOperatorValue> port1 = new ArrayList<>(); | ||
31 | + private ExtOperatorValue opVal = new ExtOperatorValue((byte) 1, new byte[100]); | ||
32 | + private ExtOperatorValue opVal1 = new ExtOperatorValue((byte) 1, new byte[200]); | ||
33 | + private ExtFlowTypes.ExtType type = ExtFlowTypes.ExtType.IN_PORT_LIST; | ||
34 | + | ||
35 | + @Test | ||
36 | + public void basics() { | ||
37 | + port.add(opVal); | ||
38 | + port1.add(opVal1); | ||
39 | + DefaultExtPort data = new DefaultExtPort(port, type); | ||
40 | + DefaultExtPort sameAsData = new DefaultExtPort(port, type); | ||
41 | + DefaultExtPort diffData = new DefaultExtPort(port1, type); | ||
42 | + new EqualsTester().addEqualityGroup(data, sameAsData) | ||
43 | + .addEqualityGroup(diffData).testEquals(); | ||
44 | + } | ||
45 | +} | ||
... | \ 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.flowapi; | ||
17 | + | ||
18 | + import com.google.common.testing.EqualsTester; | ||
19 | + import org.junit.Test; | ||
20 | + import org.onlab.packet.IpAddress; | ||
21 | + import org.onlab.packet.IpPrefix; | ||
22 | + | ||
23 | + import java.util.ArrayList; | ||
24 | + import java.util.List; | ||
25 | + | ||
26 | +/** | ||
27 | + * Test for extended prefix value attribute. | ||
28 | + */ | ||
29 | +public class DefaultExtPrefixTest { | ||
30 | + | ||
31 | + private List<IpPrefix> prefix = new ArrayList<>(); | ||
32 | + private List<IpPrefix> prefix1 = new ArrayList<>(); | ||
33 | + private IpAddress address = IpAddress.valueOf("192.168.1.1"); | ||
34 | + private IpPrefix opVal = IpPrefix.valueOf(address, 16); | ||
35 | + private IpPrefix opVal1 = IpPrefix.valueOf(address, 20); | ||
36 | + private ExtFlowTypes.ExtType type = ExtFlowTypes.ExtType.IPV4_DST_PFX; | ||
37 | + | ||
38 | + @Test | ||
39 | + public void basics() { | ||
40 | + prefix.add(opVal); | ||
41 | + prefix1.add(opVal1); | ||
42 | + DefaultExtPrefix data = new DefaultExtPrefix(prefix, type); | ||
43 | + DefaultExtPrefix sameAsData = new DefaultExtPrefix(prefix, type); | ||
44 | + DefaultExtPrefix diffData = new DefaultExtPrefix(prefix1, type); | ||
45 | + new EqualsTester().addEqualityGroup(data, sameAsData) | ||
46 | + .addEqualityGroup(diffData).testEquals(); | ||
47 | + } | ||
48 | +} | ||
... | \ 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.flowapi; | ||
17 | + | ||
18 | +import com.google.common.testing.EqualsTester; | ||
19 | +import org.junit.Test; | ||
20 | +import org.onlab.packet.IpAddress; | ||
21 | +import org.onlab.packet.IpPrefix; | ||
22 | + | ||
23 | +import java.util.ArrayList; | ||
24 | +import java.util.List; | ||
25 | + | ||
26 | +/** | ||
27 | + * Test for extended t value target ttribute. | ||
28 | + */ | ||
29 | +public class DefaultExtTargetTest { | ||
30 | + private List<IpPrefix> prefix = new ArrayList<>(); | ||
31 | + private List<IpPrefix> prefix1 = new ArrayList<>(); | ||
32 | + private IpAddress address = IpAddress.valueOf("192.168.1.1"); | ||
33 | + private IpPrefix opVal = IpPrefix.valueOf(address, 16); | ||
34 | + private IpPrefix opVal1 = IpPrefix.valueOf(address, 20); | ||
35 | + private ExtFlowTypes.ExtType type = ExtFlowTypes.ExtType.IPV4_DST_PFX; | ||
36 | + private ExtFlowTypes.ExtType typeThis = ExtFlowTypes.ExtType.WIDE_COMM_TARGET; | ||
37 | + | ||
38 | + @Test | ||
39 | + public void basics() { | ||
40 | + prefix.add(opVal); | ||
41 | + prefix1.add(opVal1); | ||
42 | + DefaultExtPrefix localSpeaker = new DefaultExtPrefix(prefix, type); | ||
43 | + DefaultExtPrefix remoteSpeaker = new DefaultExtPrefix(prefix, type); | ||
44 | + DefaultExtPrefix localSpeaker1 = new DefaultExtPrefix(prefix1, type); | ||
45 | + DefaultExtPrefix remoteSpeaker1 = new DefaultExtPrefix(prefix1, type); | ||
46 | + | ||
47 | + DefaultExtTarget data = new DefaultExtTarget(localSpeaker, remoteSpeaker, typeThis); | ||
48 | + DefaultExtTarget sameAsData = new DefaultExtTarget(localSpeaker, remoteSpeaker, typeThis); | ||
49 | + DefaultExtTarget diffData = new DefaultExtTarget(localSpeaker1, remoteSpeaker1, typeThis); | ||
50 | + new EqualsTester().addEqualityGroup(data, sameAsData) | ||
51 | + .addEqualityGroup(diffData).testEquals(); | ||
52 | + } | ||
53 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
apps/bgpflowspec/flowapi/src/test/java/org/onosproject/flowapi/DefaultExtTcpFlagTest.java
0 → 100644
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.flowapi; | ||
17 | + | ||
18 | +import com.google.common.testing.EqualsTester; | ||
19 | +import org.junit.Test; | ||
20 | + | ||
21 | +import java.util.ArrayList; | ||
22 | +import java.util.List; | ||
23 | + | ||
24 | +/** | ||
25 | + * Test for extended tcp flag value attribute. | ||
26 | + */ | ||
27 | +public class DefaultExtTcpFlagTest { | ||
28 | + | ||
29 | + private List<ExtOperatorValue> tcpFlag = new ArrayList<>(); | ||
30 | + private List<ExtOperatorValue> tcpFlag1 = new ArrayList<>(); | ||
31 | + private ExtOperatorValue opVal = new ExtOperatorValue((byte) 1, new byte[100]); | ||
32 | + private ExtOperatorValue opVal1 = new ExtOperatorValue((byte) 1, new byte[200]); | ||
33 | + private ExtFlowTypes.ExtType type = ExtFlowTypes.ExtType.TCP_FLAG_LIST; | ||
34 | + | ||
35 | + @Test | ||
36 | + public void basics() { | ||
37 | + tcpFlag.add(opVal); | ||
38 | + tcpFlag1.add(opVal1); | ||
39 | + DefaultExtTcpFlag data = new DefaultExtTcpFlag(tcpFlag, type); | ||
40 | + DefaultExtTcpFlag sameAsData = new DefaultExtTcpFlag(tcpFlag, type); | ||
41 | + DefaultExtTcpFlag diffData = new DefaultExtTcpFlag(tcpFlag1, type); | ||
42 | + new EqualsTester().addEqualityGroup(data, sameAsData) | ||
43 | + .addEqualityGroup(diffData).testEquals(); | ||
44 | + } | ||
45 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
apps/bgpflowspec/flowapi/src/test/java/org/onosproject/flowapi/DefaultExtTrafficActionTest.java
0 → 100644
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.flowapi; | ||
17 | + | ||
18 | +import com.google.common.testing.EqualsTester; | ||
19 | +import org.junit.Test; | ||
20 | + | ||
21 | +/** | ||
22 | + * Test for extended traffic action value attribute. | ||
23 | + */ | ||
24 | +public class DefaultExtTrafficActionTest { | ||
25 | + | ||
26 | + private boolean terminal = true; | ||
27 | + private boolean sample = true; | ||
28 | + private boolean rpd = true; | ||
29 | + private boolean terminal1 = false; | ||
30 | + private boolean sample1 = false; | ||
31 | + private boolean rpd1 = false; | ||
32 | + private ExtFlowTypes.ExtType type = ExtFlowTypes.ExtType.TRAFFIC_ACTION; | ||
33 | + | ||
34 | + @Test | ||
35 | + public void basics() { | ||
36 | + | ||
37 | + DefaultExtTrafficAction data = new DefaultExtTrafficAction(terminal, sample, rpd, type); | ||
38 | + DefaultExtTrafficAction sameAsData = new DefaultExtTrafficAction(terminal, sample, rpd, type); | ||
39 | + DefaultExtTrafficAction diffData = new DefaultExtTrafficAction(terminal1, sample1, rpd1, type); | ||
40 | + new EqualsTester().addEqualityGroup(data, sameAsData) | ||
41 | + .addEqualityGroup(diffData).testEquals(); | ||
42 | + } | ||
43 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
apps/bgpflowspec/flowapi/src/test/java/org/onosproject/flowapi/DefaultExtTrafficMarkingTest.java
0 → 100644
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.flowapi; | ||
17 | + | ||
18 | +import com.google.common.testing.EqualsTester; | ||
19 | +import org.junit.Test; | ||
20 | + | ||
21 | +/** | ||
22 | + * Test for extended traffic marking value attribute. | ||
23 | + */ | ||
24 | +public class DefaultExtTrafficMarkingTest { | ||
25 | + | ||
26 | + private byte marking = 01; | ||
27 | + private byte marking1 = 02; | ||
28 | + private ExtFlowTypes.ExtType type = ExtFlowTypes.ExtType.TRAFFIC_MARKING; | ||
29 | + | ||
30 | + @Test | ||
31 | + public void basics() { | ||
32 | + DefaultExtTrafficMarking data = new DefaultExtTrafficMarking(marking, type); | ||
33 | + DefaultExtTrafficMarking sameAsData = new DefaultExtTrafficMarking(marking, type); | ||
34 | + DefaultExtTrafficMarking diffData = new DefaultExtTrafficMarking(marking1, type); | ||
35 | + new EqualsTester().addEqualityGroup(data, sameAsData) | ||
36 | + .addEqualityGroup(diffData).testEquals(); | ||
37 | + } | ||
38 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
apps/bgpflowspec/flowapi/src/test/java/org/onosproject/flowapi/DefaultExtTrafficRateTest.java
0 → 100644
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.flowapi; | ||
17 | + | ||
18 | +import com.google.common.testing.EqualsTester; | ||
19 | +import org.junit.Test; | ||
20 | + | ||
21 | +/** | ||
22 | + * Test for extended traffic rate value attribute. | ||
23 | + */ | ||
24 | +public class DefaultExtTrafficRateTest { | ||
25 | + | ||
26 | + private Short asn = new Short((short) 1); | ||
27 | + private Float rate = new Float(1.0); | ||
28 | + private Short asn1 = new Short((short) 2); | ||
29 | + private Float rate1 = new Float(1.0); | ||
30 | + private ExtFlowTypes.ExtType type = ExtFlowTypes.ExtType.TRAFFIC_RATE; | ||
31 | + | ||
32 | + @Test | ||
33 | + public void basics() { | ||
34 | + DefaultExtTrafficRate data = new DefaultExtTrafficRate(asn, rate, type); | ||
35 | + DefaultExtTrafficRate sameAsData = new DefaultExtTrafficRate(asn, rate, type); | ||
36 | + DefaultExtTrafficRate diffData = new DefaultExtTrafficRate(asn1, rate1, type); | ||
37 | + new EqualsTester().addEqualityGroup(data, sameAsData) | ||
38 | + .addEqualityGroup(diffData).testEquals(); | ||
39 | + } | ||
40 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
apps/bgpflowspec/flowapi/src/test/java/org/onosproject/flowapi/DefaultExtTrafficRedirectTest.java
0 → 100644
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.flowapi; | ||
17 | + | ||
18 | +import com.google.common.testing.EqualsTester; | ||
19 | +import org.junit.Test; | ||
20 | + | ||
21 | +/** | ||
22 | + * Test for extended traffic redirect value attribute. | ||
23 | + */ | ||
24 | +public class DefaultExtTrafficRedirectTest { | ||
25 | + | ||
26 | + String redirect = new String("vpnid1"); | ||
27 | + String redirect1 = new String("vpnid2"); | ||
28 | + private ExtFlowTypes.ExtType type = ExtFlowTypes.ExtType.TRAFFIC_REDIRECT; | ||
29 | + | ||
30 | + @Test | ||
31 | + public void basics() { | ||
32 | + | ||
33 | + DefaultExtTrafficRedirect data = new DefaultExtTrafficRedirect(redirect, type); | ||
34 | + DefaultExtTrafficRedirect sameAsData = new DefaultExtTrafficRedirect(redirect, type); | ||
35 | + DefaultExtTrafficRedirect diffData = new DefaultExtTrafficRedirect(redirect1, type); | ||
36 | + new EqualsTester().addEqualityGroup(data, sameAsData) | ||
37 | + .addEqualityGroup(diffData).testEquals(); | ||
38 | + } | ||
39 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
apps/bgpflowspec/flowapi/src/test/java/org/onosproject/flowapi/DefaultExtWideCommunityIntTest.java
0 → 100644
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.flowapi; | ||
17 | + | ||
18 | +import com.google.common.testing.EqualsTester; | ||
19 | +import org.junit.Test; | ||
20 | + | ||
21 | +import java.util.ArrayList; | ||
22 | +import java.util.List; | ||
23 | + | ||
24 | +/** | ||
25 | + * Test for extended wide community value attribute. | ||
26 | + */ | ||
27 | +public class DefaultExtWideCommunityIntTest { | ||
28 | + | ||
29 | + private List<Integer> wCommInt = new ArrayList<>(); | ||
30 | + private List<Integer> wCommInt1 = new ArrayList<>(); | ||
31 | + private Integer opVal = new Integer(1); | ||
32 | + private Integer opVal1 = new Integer(2); | ||
33 | + private ExtFlowTypes.ExtType type = ExtFlowTypes.ExtType.WIDE_COMM_COMMUNITY; | ||
34 | + | ||
35 | + @Test | ||
36 | + public void basics() { | ||
37 | + wCommInt.add(opVal); | ||
38 | + wCommInt1.add(opVal1); | ||
39 | + DefaultExtWideCommunityInt data = new DefaultExtWideCommunityInt(wCommInt, type); | ||
40 | + DefaultExtWideCommunityInt sameAsData = new DefaultExtWideCommunityInt(wCommInt, type); | ||
41 | + DefaultExtWideCommunityInt diffData = new DefaultExtWideCommunityInt(wCommInt1, type); | ||
42 | + new EqualsTester().addEqualityGroup(data, sameAsData) | ||
43 | + .addEqualityGroup(diffData).testEquals(); | ||
44 | + } | ||
45 | +} | ||
... | \ 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.flowapi; | ||
17 | + | ||
18 | +import com.google.common.testing.EqualsTester; | ||
19 | +import org.junit.Test; | ||
20 | + | ||
21 | +import java.util.ArrayList; | ||
22 | +import java.util.List; | ||
23 | + | ||
24 | +/** | ||
25 | + * Test for extended flow container value attribute. | ||
26 | + */ | ||
27 | +public class ExtFlowContainerTest { | ||
28 | + | ||
29 | + private List<ExtFlowTypes> container = new ArrayList<>(); | ||
30 | + private List<ExtFlowTypes> container1 = new ArrayList<>(); | ||
31 | + private ExtFlowTypes.ExtType type = ExtFlowTypes.ExtType.EXT_FLOW_RULE_KEY; | ||
32 | + ExtFlowTypes val = new DefaultExtKeyName("Name", type); | ||
33 | + ExtFlowTypes val1 = new DefaultExtKeyName("Name1", type); | ||
34 | + | ||
35 | + @Test | ||
36 | + public void basics() { | ||
37 | + container.add(val); | ||
38 | + container1.add(val1); | ||
39 | + ExtFlowContainer data = new ExtFlowContainer(container); | ||
40 | + ExtFlowContainer sameAsData = new ExtFlowContainer(container); | ||
41 | + ExtFlowContainer diffData = new ExtFlowContainer(container1); | ||
42 | + new EqualsTester().addEqualityGroup(data, sameAsData) | ||
43 | + .addEqualityGroup(diffData).testEquals(); | ||
44 | + } | ||
45 | +} | ||
... | \ 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.flowapi; | ||
17 | + | ||
18 | +import org.junit.Test; | ||
19 | + | ||
20 | +import com.google.common.testing.EqualsTester; | ||
21 | + | ||
22 | +/** | ||
23 | + * Test for ExtOperatorValue flow specification component. | ||
24 | + */ | ||
25 | +public class ExtOperatorValueTest { | ||
26 | + ExtOperatorValue tlv1 = new ExtOperatorValue((byte) 1, new byte[100]); | ||
27 | + ExtOperatorValue sameAsTlv1 = new ExtOperatorValue((byte) 1, new byte[100]); | ||
28 | + ExtOperatorValue tlv2 = new ExtOperatorValue((byte) 1, new byte[200]); | ||
29 | + | ||
30 | + @Test | ||
31 | + public void testEquality() { | ||
32 | + new EqualsTester() | ||
33 | + .addEqualityGroup(tlv1, sameAsTlv1) | ||
34 | + .addEqualityGroup(tlv2) | ||
35 | + .testEquals(); | ||
36 | + } | ||
37 | +} |
apps/bgpflowspec/flowmgr/BUCK
0 → 100755
apps/bgpflowspec/flowmgr/pom.xml
0 → 100755
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<!-- | ||
3 | + ~ Copyright 2015 Open Networking Laboratory | ||
4 | + ~ | ||
5 | + ~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
6 | + ~ you may not use this file except in compliance with the License. | ||
7 | + ~ You may obtain a copy of the License at | ||
8 | + ~ | ||
9 | + ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
10 | + ~ | ||
11 | + ~ Unless required by applicable law or agreed to in writing, software | ||
12 | + ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
13 | + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
14 | + ~ See the License for the specific language governing permissions and | ||
15 | + ~ limitations under the License. | ||
16 | + --> | ||
17 | +<project | ||
18 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" | ||
19 | + xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
20 | + <modelVersion>4.0.0</modelVersion> | ||
21 | + <parent> | ||
22 | + <groupId>org.onosproject</groupId> | ||
23 | + <artifactId>onos-app-bgpflow</artifactId> | ||
24 | + <version>1.6.0-SNAPSHOT</version> | ||
25 | + <relativePath>../pom.xml</relativePath> | ||
26 | + </parent> | ||
27 | + | ||
28 | + <artifactId>onos-app-bgp-flowmgr</artifactId> | ||
29 | + <packaging>bundle</packaging> | ||
30 | + | ||
31 | + <dependencies> | ||
32 | + <dependency> | ||
33 | + <groupId>org.onosproject</groupId> | ||
34 | + <artifactId>onos-api</artifactId> | ||
35 | + </dependency> | ||
36 | + <dependency> | ||
37 | + <groupId>javax.ws.rs</groupId> | ||
38 | + <artifactId>javax.ws.rs-api</artifactId> | ||
39 | + <version>2.0.1</version> | ||
40 | + </dependency> | ||
41 | + <dependency> | ||
42 | + <groupId>org.apache.karaf.shell</groupId> | ||
43 | + <artifactId>org.apache.karaf.shell.console</artifactId> | ||
44 | + </dependency> | ||
45 | + <dependency> | ||
46 | + <groupId>org.onosproject</groupId> | ||
47 | + <artifactId>onos-app-bgp-flowapi</artifactId> | ||
48 | + <version>1.6.0-SNAPSHOT</version> | ||
49 | + </dependency> | ||
50 | + </dependencies> | ||
51 | +</project> |
apps/bgpflowspec/flowmgr/src/main/java/org/onosproject/flow/forwarder/BgpFlowForwarderService.java
0 → 100755
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.flow.forwarder; | ||
17 | + | ||
18 | +import org.onosproject.flowapi.ExtFlowContainer; | ||
19 | + | ||
20 | +/** | ||
21 | + * Abstraction of an entity which provides Bgp Flow Service. | ||
22 | + */ | ||
23 | +public interface BgpFlowForwarderService { | ||
24 | + | ||
25 | + /** | ||
26 | + * Install forwarding rule. | ||
27 | + * | ||
28 | + * @param container BgpFlow container | ||
29 | + * @return a true if success else false | ||
30 | + */ | ||
31 | + boolean installForwardingRule(ExtFlowContainer container); | ||
32 | + | ||
33 | + /** | ||
34 | + * Uninstall forwarding rule. | ||
35 | + * | ||
36 | + * @param container BgpFlow container | ||
37 | + * @return a true if success else false | ||
38 | + */ | ||
39 | + boolean unInstallForwardingRule(ExtFlowContainer container); | ||
40 | +} |
apps/bgpflowspec/flowmgr/src/main/java/org/onosproject/flow/forwarder/impl/BgpFlowForwarderImpl.java
0 → 100755
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.flow.forwarder.impl; | ||
17 | + | ||
18 | +import org.onosproject.core.ApplicationId; | ||
19 | +import org.onosproject.flow.forwarder.BgpFlowForwarderService; | ||
20 | + | ||
21 | +import org.onosproject.flowapi.ExtFlowContainer; | ||
22 | +import org.onosproject.net.Annotations; | ||
23 | +import org.onosproject.net.Device; | ||
24 | +import org.onosproject.net.DeviceId; | ||
25 | +import org.onosproject.net.behaviour.ExtensionSelectorResolver; | ||
26 | +import org.onosproject.net.device.DeviceService; | ||
27 | +import org.onosproject.net.driver.DriverHandler; | ||
28 | +import org.onosproject.net.driver.DriverService; | ||
29 | +import org.onosproject.net.flow.DefaultTrafficSelector; | ||
30 | +import org.onosproject.net.flow.DefaultTrafficTreatment; | ||
31 | +import org.onosproject.net.flow.TrafficSelector; | ||
32 | +import org.onosproject.net.flow.TrafficTreatment; | ||
33 | +import org.onosproject.net.flow.criteria.ExtensionSelector; | ||
34 | +import org.onosproject.net.flowobjective.DefaultForwardingObjective; | ||
35 | +import org.onosproject.net.flowobjective.FlowObjectiveService; | ||
36 | +import org.onosproject.net.flowobjective.ForwardingObjective; | ||
37 | +import org.onosproject.net.flowobjective.ForwardingObjective.Flag; | ||
38 | +import org.onosproject.net.flowobjective.Objective; | ||
39 | +import org.slf4j.Logger; | ||
40 | + | ||
41 | +import java.util.Iterator; | ||
42 | + | ||
43 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
44 | +import static org.onosproject.net.flow.criteria.ExtensionSelectorType.ExtensionSelectorTypes.EXT_MATCH_FLOW_TYPE; | ||
45 | +import static org.slf4j.LoggerFactory.getLogger; | ||
46 | + | ||
47 | +/** | ||
48 | + * Provides Bgp flow forwarder implementation. | ||
49 | + */ | ||
50 | +public class BgpFlowForwarderImpl implements BgpFlowForwarderService { | ||
51 | + | ||
52 | + protected DriverService driverService; | ||
53 | + protected DeviceService deviceService; | ||
54 | + protected FlowObjectiveService flowObjectiveService; | ||
55 | + private final Logger log = getLogger(getClass()); | ||
56 | + protected ApplicationId appId; | ||
57 | + | ||
58 | + private static final String BGP_FLOW_CONTAINER_NOT_NULL = "Bgp flow container cannot be null"; | ||
59 | + private static final String APP_ID_NOT_NULL = "Application-Id cannot be null"; | ||
60 | + public static final String FLOW_PEER = "flowPeer"; | ||
61 | + | ||
62 | + /** | ||
63 | + * Default constructor. | ||
64 | + */ | ||
65 | + public BgpFlowForwarderImpl() { | ||
66 | + } | ||
67 | + | ||
68 | + /** | ||
69 | + * Explicit constructor. | ||
70 | + * | ||
71 | + * @param appId Application id | ||
72 | + * @param flowObjectiveService flow service | ||
73 | + * @param deviceService device service | ||
74 | + * @param driverService driver service | ||
75 | + */ | ||
76 | + public BgpFlowForwarderImpl(ApplicationId appId, FlowObjectiveService flowObjectiveService, | ||
77 | + DeviceService deviceService, DriverService driverService) { | ||
78 | + this.appId = checkNotNull(appId, APP_ID_NOT_NULL); | ||
79 | + this.flowObjectiveService = flowObjectiveService; | ||
80 | + this.deviceService = deviceService; | ||
81 | + this.driverService = driverService; | ||
82 | + } | ||
83 | + | ||
84 | + @Override | ||
85 | + public boolean installForwardingRule(ExtFlowContainer container) { | ||
86 | + checkNotNull(container, BGP_FLOW_CONTAINER_NOT_NULL); | ||
87 | + return pushBgpFlowRuleForwarder(container, Objective.Operation.ADD); | ||
88 | + } | ||
89 | + | ||
90 | + @Override | ||
91 | + public boolean unInstallForwardingRule(ExtFlowContainer container) { | ||
92 | + checkNotNull(container, BGP_FLOW_CONTAINER_NOT_NULL); | ||
93 | + return pushBgpFlowRuleForwarder(container, Objective.Operation.REMOVE); | ||
94 | + } | ||
95 | + | ||
96 | + /** | ||
97 | + * Find the bgp device and push the rule. | ||
98 | + * | ||
99 | + * @param container is a flow rule container | ||
100 | + * @param type either add or remove the service rule | ||
101 | + * @return a true if success else false | ||
102 | + */ | ||
103 | + public boolean pushBgpFlowRuleForwarder(ExtFlowContainer container, | ||
104 | + Objective.Operation type) { | ||
105 | + DeviceId deviceId = null; | ||
106 | + | ||
107 | + Iterable<Device> devices = deviceService.getAvailableDevices(); | ||
108 | + Iterator<Device> itr = devices.iterator(); | ||
109 | + while (itr.hasNext()) { | ||
110 | + DeviceId tmp = itr.next().id(); | ||
111 | + if (tmp.toString().equals(container.deviceId())) { | ||
112 | + if (validatePeer(tmp)) { | ||
113 | + deviceId = tmp; | ||
114 | + break; | ||
115 | + } | ||
116 | + } | ||
117 | + } | ||
118 | + | ||
119 | + if (deviceId != null) { | ||
120 | + // pack traffic selector | ||
121 | + TrafficSelector.Builder selector = packTrafficSelector(deviceId, container); | ||
122 | + | ||
123 | + // pack traffic treatment | ||
124 | + TrafficTreatment.Builder treatment = packTrafficTreatment(container); | ||
125 | + | ||
126 | + sendBgpFlowRuleForwarder(selector, treatment, deviceId, type); | ||
127 | + } else { | ||
128 | + log.error("Bgp devices are not available.."); | ||
129 | + return false; | ||
130 | + } | ||
131 | + | ||
132 | + return true; | ||
133 | + } | ||
134 | + | ||
135 | + /** | ||
136 | + * Validates the device id is a flow peer or not. | ||
137 | + * | ||
138 | + * @param deviceId device to which the flow needed to be pushed. | ||
139 | + * @return true if success else false | ||
140 | + */ | ||
141 | + boolean validatePeer(DeviceId deviceId) { | ||
142 | + boolean ret = false; | ||
143 | + Device d = deviceService.getDevice(deviceId); | ||
144 | + Annotations a = d != null ? d.annotations() : null; | ||
145 | + String ipAddress = a.value(FLOW_PEER); | ||
146 | + if (ipAddress != null) { | ||
147 | + ret = true; | ||
148 | + } | ||
149 | + return ret; | ||
150 | + } | ||
151 | + | ||
152 | + /** | ||
153 | + * Traffic selector builder function. | ||
154 | + * | ||
155 | + * @param deviceId device id. | ||
156 | + * @param container container need to be pushed. | ||
157 | + * @return the traffic selector builder | ||
158 | + */ | ||
159 | + public TrafficSelector.Builder packTrafficSelector(DeviceId deviceId, ExtFlowContainer container) { | ||
160 | + TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); | ||
161 | + | ||
162 | + DriverHandler handler = driverService.createHandler(deviceId); | ||
163 | + ExtensionSelectorResolver resolver = handler.behaviour(ExtensionSelectorResolver.class); | ||
164 | + ExtensionSelector bgpExtSelector = resolver.getExtensionSelector(EXT_MATCH_FLOW_TYPE.type()); | ||
165 | + | ||
166 | + try { | ||
167 | + bgpExtSelector.setPropertyValue("container", container); | ||
168 | + } catch (Exception e) { | ||
169 | + log.error("Failed to get extension instruction for bgp flow {}", deviceId); | ||
170 | + } | ||
171 | + | ||
172 | + selector.extension(bgpExtSelector, deviceId); | ||
173 | + return selector; | ||
174 | + } | ||
175 | + | ||
176 | + /** | ||
177 | + * Traffic treatment builder function. | ||
178 | + * | ||
179 | + * @param container container need to be pushed. | ||
180 | + * @return the traffic treatment builder | ||
181 | + */ | ||
182 | + public TrafficTreatment.Builder packTrafficTreatment(ExtFlowContainer container) { | ||
183 | + TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); | ||
184 | + | ||
185 | + return treatment; | ||
186 | + } | ||
187 | + | ||
188 | + /** | ||
189 | + * Send bgp flow forwarder to bgp provider. | ||
190 | + * | ||
191 | + * @param selector traffic selector | ||
192 | + * @param treatment traffic treatment | ||
193 | + * @param deviceId device id | ||
194 | + * @param type operation type | ||
195 | + */ | ||
196 | + public void sendBgpFlowRuleForwarder(TrafficSelector.Builder selector, TrafficTreatment.Builder treatment, | ||
197 | + DeviceId deviceId, Objective.Operation type) { | ||
198 | + ForwardingObjective.Builder objective = DefaultForwardingObjective.builder().withTreatment(treatment.build()) | ||
199 | + .withSelector(selector.build()).fromApp(appId).makePermanent().withFlag(Flag.VERSATILE); | ||
200 | + if (type.equals(Objective.Operation.ADD)) { | ||
201 | + log.debug("ADD"); | ||
202 | + flowObjectiveService.forward(deviceId, objective.add()); | ||
203 | + } else { | ||
204 | + log.debug("REMOVE"); | ||
205 | + flowObjectiveService.forward(deviceId, objective.remove()); | ||
206 | + } | ||
207 | + } | ||
208 | +} |
apps/bgpflowspec/flowmgr/src/main/java/org/onosproject/flow/forwarder/impl/package-info.java
0 → 100755
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 | + | ||
17 | +/** | ||
18 | + * Bgp service manager for interacting with bgp provider. | ||
19 | + */ | ||
20 | +package org.onosproject.flow.forwarder.impl; |
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 | + | ||
17 | +/** | ||
18 | + * Service forwarder for bgp flow. | ||
19 | + */ | ||
20 | +package org.onosproject.flow.forwarder; |
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.flow.manager; | ||
17 | + | ||
18 | +import org.onosproject.flowapi.ExtFlowContainer; | ||
19 | + | ||
20 | +/** | ||
21 | + * Bgp flow service application. | ||
22 | + */ | ||
23 | +public interface BgpFlowService { | ||
24 | + | ||
25 | + /** | ||
26 | + * Bgp flow rule create interface. | ||
27 | + * | ||
28 | + * @param container flow container class | ||
29 | + * @return true if success else false | ||
30 | + */ | ||
31 | + boolean onBgpFlowCreated(ExtFlowContainer container); | ||
32 | + | ||
33 | + /** | ||
34 | + * Bgp flow rule delete interface. | ||
35 | + * | ||
36 | + * @param container flow container class | ||
37 | + * @return true if success else false | ||
38 | + */ | ||
39 | + boolean onBgpFlowDeleted(ExtFlowContainer container); | ||
40 | +} |
apps/bgpflowspec/flowmgr/src/main/java/org/onosproject/flow/manager/impl/BgpFlowManager.java
0 → 100755
1 | +/* | ||
2 | + * Copyright 2016 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.flow.manager.impl; | ||
17 | + | ||
18 | +import org.apache.felix.scr.annotations.Activate; | ||
19 | +import org.apache.felix.scr.annotations.Component; | ||
20 | +import org.apache.felix.scr.annotations.Deactivate; | ||
21 | +import org.apache.felix.scr.annotations.Reference; | ||
22 | +import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
23 | +import org.apache.felix.scr.annotations.Service; | ||
24 | +import org.onosproject.core.ApplicationId; | ||
25 | +import org.onosproject.core.CoreService; | ||
26 | +import org.onosproject.flow.forwarder.BgpFlowForwarderService; | ||
27 | +import org.onosproject.flow.forwarder.impl.BgpFlowForwarderImpl; | ||
28 | +import org.onosproject.flow.manager.BgpFlowService; | ||
29 | +import org.onosproject.flowapi.ExtFlowContainer; | ||
30 | +import org.onosproject.net.device.DeviceService; | ||
31 | +import org.onosproject.net.driver.DriverService; | ||
32 | +import org.onosproject.net.flowobjective.FlowObjectiveService; | ||
33 | +import org.slf4j.Logger; | ||
34 | + | ||
35 | +import static org.slf4j.LoggerFactory.getLogger; | ||
36 | + | ||
37 | +/** | ||
38 | + * Provides implementation of Bgp flow Service. | ||
39 | + */ | ||
40 | +@Component(immediate = true) | ||
41 | +@Service | ||
42 | +public class BgpFlowManager implements BgpFlowService { | ||
43 | + | ||
44 | + private final Logger log = getLogger(getClass()); | ||
45 | + private static final String APP_ID = "org.onosproject.app.bgpflow"; | ||
46 | + | ||
47 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
48 | + protected CoreService coreService; | ||
49 | + | ||
50 | + protected ApplicationId appId; | ||
51 | + private BgpFlowForwarderService bgpFlowForwarderService; | ||
52 | + | ||
53 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
54 | + protected DriverService driverService; | ||
55 | + | ||
56 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
57 | + protected DeviceService deviceService; | ||
58 | + | ||
59 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
60 | + protected FlowObjectiveService flowObjectiveService; | ||
61 | + | ||
62 | + @Activate | ||
63 | + public void activate() { | ||
64 | + appId = coreService.registerApplication(APP_ID); | ||
65 | + bgpFlowForwarderService = new BgpFlowForwarderImpl(appId, flowObjectiveService, deviceService, driverService); | ||
66 | + log.info("Started"); | ||
67 | + } | ||
68 | + | ||
69 | + @Deactivate | ||
70 | + public void deactivate() { | ||
71 | + log.info("Stopped"); | ||
72 | + } | ||
73 | + | ||
74 | + @Override | ||
75 | + public boolean onBgpFlowCreated(ExtFlowContainer container) { | ||
76 | + return bgpFlowForwarderService.installForwardingRule(container); | ||
77 | + } | ||
78 | + | ||
79 | + @Override | ||
80 | + public boolean onBgpFlowDeleted(ExtFlowContainer container) { | ||
81 | + return bgpFlowForwarderService.unInstallForwardingRule(container); | ||
82 | + } | ||
83 | +} |
apps/bgpflowspec/flowmgr/src/main/java/org/onosproject/flow/manager/impl/package-info.java
0 → 100755
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 | + | ||
17 | +/** | ||
18 | + * Bgp service manager for interacting provider. | ||
19 | + */ | ||
20 | +package org.onosproject.flow.manager.impl; |
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 | + | ||
17 | +/** | ||
18 | + * Bgp flow manager. | ||
19 | + */ | ||
20 | +package org.onosproject.flow.manager; |
apps/bgpflowspec/pom.xml
0 → 100755
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<!-- | ||
3 | + ~ Copyright 2016-present Open Networking Laboratory | ||
4 | + ~ | ||
5 | + ~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
6 | + ~ you may not use this file except in compliance with the License. | ||
7 | + ~ You may obtain a copy of the License at | ||
8 | + ~ | ||
9 | + ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
10 | + ~ | ||
11 | + ~ Unless required by applicable law or agreed to in writing, software | ||
12 | + ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
13 | + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
14 | + ~ See the License for the specific language governing permissions and | ||
15 | + ~ limitations under the License. | ||
16 | + --> | ||
17 | +<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
18 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
19 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
20 | + <modelVersion>4.0.0</modelVersion> | ||
21 | + | ||
22 | + <parent> | ||
23 | + <groupId>org.onosproject</groupId> | ||
24 | + <artifactId>onos-apps</artifactId> | ||
25 | + <version>1.6.0-SNAPSHOT</version> | ||
26 | + <relativePath>../pom.xml</relativePath> | ||
27 | + </parent> | ||
28 | + | ||
29 | + <artifactId>onos-app-bgpflow</artifactId> | ||
30 | + <packaging>pom</packaging> | ||
31 | + | ||
32 | + <description>ONOS bgp flow spec applications</description> | ||
33 | + | ||
34 | + <modules> | ||
35 | + <module>app</module> | ||
36 | + <module>flowapi</module> | ||
37 | + <module>flowmgr</module> | ||
38 | + <module>bgpweb</module> | ||
39 | + </modules> | ||
40 | + <dependencies> | ||
41 | + <dependency> | ||
42 | + <groupId>org.onosproject</groupId> | ||
43 | + <artifactId>onlab-junit</artifactId> | ||
44 | + <scope>test</scope> | ||
45 | + </dependency> | ||
46 | + <dependency> | ||
47 | + <groupId>com.google.guava</groupId> | ||
48 | + <artifactId>guava-testlib</artifactId> | ||
49 | + <scope>test</scope> | ||
50 | + </dependency> | ||
51 | + <dependency> | ||
52 | + <groupId>org.easymock</groupId> | ||
53 | + <artifactId>easymock</artifactId> | ||
54 | + <scope>test</scope> | ||
55 | + </dependency> | ||
56 | + <dependency> | ||
57 | + <groupId>org.onosproject</groupId> | ||
58 | + <artifactId>onlab-osgi</artifactId> | ||
59 | + <classifier>tests</classifier> | ||
60 | + <scope>test</scope> | ||
61 | + </dependency> | ||
62 | + <dependency> | ||
63 | + <groupId>org.onosproject</groupId> | ||
64 | + <artifactId>onos-api</artifactId> | ||
65 | + <scope>test</scope> | ||
66 | + <classifier>tests</classifier> | ||
67 | + </dependency> | ||
68 | + <dependency> | ||
69 | + <groupId>org.glassfish.jersey.containers</groupId> | ||
70 | + <artifactId>jersey-container-servlet</artifactId> | ||
71 | + </dependency> | ||
72 | + <dependency> | ||
73 | + <groupId>org.glassfish.jersey.test-framework</groupId> | ||
74 | + <artifactId>jersey-test-framework-core</artifactId> | ||
75 | + <scope>test</scope> | ||
76 | + </dependency> | ||
77 | + <dependency> | ||
78 | + <groupId>org.glassfish.jersey.test-framework.providers</groupId> | ||
79 | + <artifactId>jersey-test-framework-provider-jetty</artifactId> | ||
80 | + <scope>test</scope> | ||
81 | + </dependency> | ||
82 | + </dependencies> | ||
83 | +</project> |
... | @@ -42,6 +42,7 @@ | ... | @@ -42,6 +42,7 @@ |
42 | <module>reactive-routing</module> | 42 | <module>reactive-routing</module> |
43 | <module>virtualbng</module> | 43 | <module>virtualbng</module> |
44 | <module>bgprouter</module> | 44 | <module>bgprouter</module> |
45 | + <module>bgpflowspec</module> | ||
45 | <module>test</module> | 46 | <module>test</module> |
46 | <module>segmentrouting</module> | 47 | <module>segmentrouting</module> |
47 | <module>xos-integration</module> | 48 | <module>xos-integration</module> | ... | ... |
... | @@ -40,6 +40,7 @@ public class ExtensionSelectorType { | ... | @@ -40,6 +40,7 @@ public class ExtensionSelectorType { |
40 | NICIRA_MATCH_NSH_CH4(5), | 40 | NICIRA_MATCH_NSH_CH4(5), |
41 | NICIRA_MATCH_ENCAP_ETH_TYPE(6), | 41 | NICIRA_MATCH_ENCAP_ETH_TYPE(6), |
42 | OFDPA_MATCH_VLAN_VID(16), | 42 | OFDPA_MATCH_VLAN_VID(16), |
43 | + EXT_MATCH_FLOW_TYPE(20), | ||
43 | BMV2_MATCH_PARAMS(128); | 44 | BMV2_MATCH_PARAMS(128); |
44 | 45 | ||
45 | private ExtensionSelectorType type; | 46 | private ExtensionSelectorType type; | ... | ... |
... | @@ -4,6 +4,7 @@ COMPILE_DEPS = [ | ... | @@ -4,6 +4,7 @@ COMPILE_DEPS = [ |
4 | '//drivers/utilities:onos-drivers-utilities', | 4 | '//drivers/utilities:onos-drivers-utilities', |
5 | '//protocols/openflow/api:onos-protocols-openflow-api', | 5 | '//protocols/openflow/api:onos-protocols-openflow-api', |
6 | '//core/store/serializers:onos-core-serializers', | 6 | '//core/store/serializers:onos-core-serializers', |
7 | + '//apps/bgpflowspec/flowapi:onos-apps-bgpflowspec-flowapi', | ||
7 | ] | 8 | ] |
8 | 9 | ||
9 | TEST_DEPS = [ | 10 | TEST_DEPS = [ |
... | @@ -28,5 +29,6 @@ onos_app ( | ... | @@ -28,5 +29,6 @@ onos_app ( |
28 | ':onos-drivers-default', | 29 | ':onos-drivers-default', |
29 | '//lib:openflowj', | 30 | '//lib:openflowj', |
30 | '//protocols/openflow/api:onos-protocols-openflow-api', | 31 | '//protocols/openflow/api:onos-protocols-openflow-api', |
32 | + '//apps/bgpflowspec/flowapi:onos-apps-bgpflowspec-flowapi', | ||
31 | ] | 33 | ] |
32 | ) | 34 | ) | ... | ... |
... | @@ -44,6 +44,11 @@ | ... | @@ -44,6 +44,11 @@ |
44 | </dependency> | 44 | </dependency> |
45 | <dependency> | 45 | <dependency> |
46 | <groupId>org.onosproject</groupId> | 46 | <groupId>org.onosproject</groupId> |
47 | + <artifactId>onos-app-bgp-flowapi</artifactId> | ||
48 | + <version>${project.version}</version> | ||
49 | + </dependency> | ||
50 | + <dependency> | ||
51 | + <groupId>org.onosproject</groupId> | ||
47 | <artifactId>openflowj</artifactId> | 52 | <artifactId>openflowj</artifactId> |
48 | </dependency> | 53 | </dependency> |
49 | </dependencies> | 54 | </dependencies> | ... | ... |
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.driver.extensions; | ||
17 | + | ||
18 | +import org.onlab.util.KryoNamespace; | ||
19 | +import org.onosproject.flowapi.ExtFlowContainer; | ||
20 | +import org.onosproject.net.flow.AbstractExtension; | ||
21 | +import org.onosproject.net.flow.criteria.ExtensionSelector; | ||
22 | +import org.onosproject.net.flow.criteria.ExtensionSelectorType; | ||
23 | +import java.util.Objects; | ||
24 | + | ||
25 | +import static com.google.common.base.MoreObjects.toStringHelper; | ||
26 | + | ||
27 | +/** | ||
28 | + * Implementation of extension selector for multi value. | ||
29 | + */ | ||
30 | +public final class ExtMatchExtension extends AbstractExtension implements ExtensionSelector { | ||
31 | + private ExtFlowContainer container; | ||
32 | + | ||
33 | + private final KryoNamespace appKryo = new KryoNamespace.Builder().register(ExtMatchExtension.class).build(); | ||
34 | + | ||
35 | + /** | ||
36 | + * Creates an object of ExtMatchExtension. | ||
37 | + */ | ||
38 | + public ExtMatchExtension() { | ||
39 | + this.container = null; | ||
40 | + } | ||
41 | + | ||
42 | + /** | ||
43 | + * Returns the container. | ||
44 | + * | ||
45 | + * @return the container to match | ||
46 | + */ | ||
47 | + public ExtFlowContainer container() { | ||
48 | + return container; | ||
49 | + } | ||
50 | + | ||
51 | + @Override | ||
52 | + public ExtensionSelectorType type() { | ||
53 | + return ExtensionSelectorType.ExtensionSelectorTypes.EXT_MATCH_FLOW_TYPE.type(); | ||
54 | + } | ||
55 | + | ||
56 | + @Override | ||
57 | + public byte[] serialize() { | ||
58 | + return appKryo.serialize(container); | ||
59 | + } | ||
60 | + | ||
61 | + @Override | ||
62 | + public void deserialize(byte[] data) { | ||
63 | + container = ExtFlowContainer.of(appKryo.deserialize(data)); | ||
64 | + } | ||
65 | + | ||
66 | + @Override | ||
67 | + public String toString() { | ||
68 | + return toStringHelper(type().toString()) | ||
69 | + .add("container", container) | ||
70 | + .toString(); | ||
71 | + } | ||
72 | + | ||
73 | + @Override | ||
74 | + public int hashCode() { | ||
75 | + return Objects.hash(type(), container); | ||
76 | + } | ||
77 | + | ||
78 | + @Override | ||
79 | + public boolean equals(Object obj) { | ||
80 | + if (this == obj) { | ||
81 | + return true; | ||
82 | + } | ||
83 | + if (obj instanceof ExtMatchExtension) { | ||
84 | + ExtMatchExtension that = (ExtMatchExtension) obj; | ||
85 | + return Objects.equals(container, that.container) && | ||
86 | + Objects.equals(this.type(), that.type()); | ||
87 | + } | ||
88 | + return false; | ||
89 | + } | ||
90 | +} |
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.driver.extensions; | ||
17 | + | ||
18 | +import org.onosproject.net.behaviour.ExtensionSelectorResolver; | ||
19 | +import org.onosproject.net.driver.AbstractHandlerBehaviour; | ||
20 | +import org.onosproject.net.flow.criteria.ExtensionSelector; | ||
21 | +import org.onosproject.net.flow.criteria.ExtensionSelectorType; | ||
22 | + | ||
23 | +/** | ||
24 | + * Interpreter for bgp selector extensions. | ||
25 | + */ | ||
26 | +public class MultiExtensionSelectorInterpreter | ||
27 | + extends AbstractHandlerBehaviour | ||
28 | + implements ExtensionSelectorResolver { | ||
29 | + | ||
30 | + @Override | ||
31 | + public ExtensionSelector getExtensionSelector(ExtensionSelectorType type) { | ||
32 | + if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.EXT_MATCH_FLOW_TYPE.type())) { | ||
33 | + return new ExtMatchExtension(); | ||
34 | + } | ||
35 | + return null; | ||
36 | + } | ||
37 | +} |
... | @@ -141,6 +141,11 @@ | ... | @@ -141,6 +141,11 @@ |
141 | <behaviour api="org.onosproject.net.behaviour.Pipeliner" | 141 | <behaviour api="org.onosproject.net.behaviour.Pipeliner" |
142 | impl="org.onosproject.driver.pipeline.OpenVSwitchPipeline"/> | 142 | impl="org.onosproject.driver.pipeline.OpenVSwitchPipeline"/> |
143 | </driver> | 143 | </driver> |
144 | + <driver name="l3Device" extends="default" | ||
145 | + manufacturer="" hwVersion="" swVersion=""> | ||
146 | + <behaviour api="org.onosproject.net.behaviour.ExtensionSelectorResolver" | ||
147 | + impl="org.onosproject.driver.extensions.MultiExtensionSelectorInterpreter" /> | ||
148 | + </driver> | ||
144 | <driver name="aos" extends="ofdpa" | 149 | <driver name="aos" extends="ofdpa" |
145 | manufacturer="Accton" hwVersion=".*" swVersion="1.*"> | 150 | manufacturer="Accton" hwVersion=".*" swVersion="1.*"> |
146 | </driver> | 151 | </driver> | ... | ... |
... | @@ -231,6 +231,7 @@ public class BgpTopologyProvider extends AbstractProvider implements DeviceProvi | ... | @@ -231,6 +231,7 @@ public class BgpTopologyProvider extends AbstractProvider implements DeviceProvi |
231 | 231 | ||
232 | DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder(); | 232 | DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder(); |
233 | 233 | ||
234 | + newBuilder.set(AnnotationKeys.DRIVER, "l3Device"); | ||
234 | newBuilder.set(AnnotationKeys.TYPE, "L3"); | 235 | newBuilder.set(AnnotationKeys.TYPE, "L3"); |
235 | newBuilder.set(ROUTING_UNIVERSE, Long.toString(nodeNlri.getIdentifier())); | 236 | newBuilder.set(ROUTING_UNIVERSE, Long.toString(nodeNlri.getIdentifier())); |
236 | 237 | ... | ... |
... | @@ -35,5 +35,15 @@ | ... | @@ -35,5 +35,15 @@ |
35 | <groupId>org.osgi</groupId> | 35 | <groupId>org.osgi</groupId> |
36 | <artifactId>org.osgi.compendium</artifactId> | 36 | <artifactId>org.osgi.compendium</artifactId> |
37 | </dependency> | 37 | </dependency> |
38 | + <dependency> | ||
39 | + <groupId>org.onosproject</groupId> | ||
40 | + <artifactId>onos-app-bgp-flowapi</artifactId> | ||
41 | + <version>${project.version}</version> | ||
42 | + </dependency> | ||
43 | + <dependency> | ||
44 | + <groupId>org.onosproject</groupId> | ||
45 | + <artifactId>onos-bgp-ctl</artifactId> | ||
46 | + <version>1.6.0-SNAPSHOT</version> | ||
47 | + </dependency> | ||
38 | </dependencies> | 48 | </dependencies> |
39 | </project> | 49 | </project> | ... | ... |
... | @@ -18,8 +18,11 @@ package org.onosproject.provider.bgpcep.flow.impl; | ... | @@ -18,8 +18,11 @@ package org.onosproject.provider.bgpcep.flow.impl; |
18 | import java.util.ArrayList; | 18 | import java.util.ArrayList; |
19 | import java.util.Collection; | 19 | import java.util.Collection; |
20 | import java.util.Collections; | 20 | import java.util.Collections; |
21 | +import java.util.Iterator; | ||
21 | import java.util.LinkedList; | 22 | import java.util.LinkedList; |
22 | import java.util.List; | 23 | import java.util.List; |
24 | +import java.util.ListIterator; | ||
25 | +import java.util.Set; | ||
23 | 26 | ||
24 | import org.apache.felix.scr.annotations.Activate; | 27 | import org.apache.felix.scr.annotations.Activate; |
25 | import org.apache.felix.scr.annotations.Component; | 28 | import org.apache.felix.scr.annotations.Component; |
... | @@ -31,13 +34,63 @@ import org.onlab.packet.IpAddress; | ... | @@ -31,13 +34,63 @@ import org.onlab.packet.IpAddress; |
31 | import org.onlab.packet.IpPrefix; | 34 | import org.onlab.packet.IpPrefix; |
32 | import org.onlab.packet.MplsLabel; | 35 | import org.onlab.packet.MplsLabel; |
33 | import org.onosproject.bgp.controller.BgpController; | 36 | import org.onosproject.bgp.controller.BgpController; |
37 | +import org.onosproject.bgp.controller.BgpId; | ||
38 | +import org.onosproject.bgp.controller.BgpPeer; | ||
39 | +import org.onosproject.bgpio.protocol.flowspec.BgpFlowSpecNlri; | ||
40 | +import org.onosproject.bgpio.protocol.flowspec.BgpFlowSpecRouteKey; | ||
41 | +import org.onosproject.bgpio.types.BgpFsActionReDirect; | ||
42 | +import org.onosproject.bgpio.types.BgpFsActionTrafficAction; | ||
43 | +import org.onosproject.bgpio.types.BgpFsActionTrafficMarking; | ||
44 | +import org.onosproject.bgpio.types.BgpFsActionTrafficRate; | ||
45 | +import org.onosproject.bgpio.types.BgpFsDestinationPortNum; | ||
46 | +import org.onosproject.bgpio.types.BgpFsDestinationPrefix; | ||
47 | +import org.onosproject.bgpio.types.BgpFsDscpValue; | ||
48 | +import org.onosproject.bgpio.types.BgpFsFragment; | ||
49 | +import org.onosproject.bgpio.types.BgpFsIcmpCode; | ||
50 | +import org.onosproject.bgpio.types.BgpFsIcmpType; | ||
51 | +import org.onosproject.bgpio.types.BgpFsIpProtocol; | ||
52 | +import org.onosproject.bgpio.types.BgpFsOperatorValue; | ||
53 | +import org.onosproject.bgpio.types.BgpFsPacketLength; | ||
54 | +import org.onosproject.bgpio.types.BgpFsPortNum; | ||
55 | +import org.onosproject.bgpio.types.BgpFsSourcePortNum; | ||
56 | +import org.onosproject.bgpio.types.BgpFsSourcePrefix; | ||
57 | +import org.onosproject.bgpio.types.BgpFsTcpFlags; | ||
58 | +import org.onosproject.bgpio.types.BgpValueType; | ||
59 | +import org.onosproject.bgpio.types.WideCommunityAttrHeader; | ||
60 | +import org.onosproject.bgpio.types.WideCommunityExcludeTarget; | ||
61 | +import org.onosproject.bgpio.types.WideCommunityInteger; | ||
62 | +import org.onosproject.bgpio.types.WideCommunityIpV4Neighbour; | ||
63 | +import org.onosproject.bgpio.types.WideCommunityParameter; | ||
64 | +import org.onosproject.bgpio.types.WideCommunityTarget; | ||
65 | +import org.onosproject.bgpio.types.attr.WideCommunity; | ||
34 | import org.onosproject.core.ApplicationId; | 66 | import org.onosproject.core.ApplicationId; |
67 | +import org.onosproject.flowapi.ExtDscpValue; | ||
68 | +import org.onosproject.flowapi.ExtFlowContainer; | ||
69 | +import org.onosproject.flowapi.ExtFlowTypes; | ||
70 | +import org.onosproject.flowapi.ExtFragment; | ||
71 | +import org.onosproject.flowapi.ExtIcmpCode; | ||
72 | +import org.onosproject.flowapi.ExtIcmpType; | ||
73 | +import org.onosproject.flowapi.ExtIpProtocol; | ||
74 | +import org.onosproject.flowapi.ExtKeyName; | ||
75 | +import org.onosproject.flowapi.ExtOperatorValue; | ||
76 | +import org.onosproject.flowapi.ExtPacketLength; | ||
77 | +import org.onosproject.flowapi.ExtPort; | ||
78 | +import org.onosproject.flowapi.ExtPrefix; | ||
79 | +import org.onosproject.flowapi.ExtTarget; | ||
80 | +import org.onosproject.flowapi.ExtTcpFlag; | ||
81 | +import org.onosproject.flowapi.ExtTrafficAction; | ||
82 | +import org.onosproject.flowapi.ExtTrafficMarking; | ||
83 | +import org.onosproject.flowapi.ExtTrafficRate; | ||
84 | +import org.onosproject.flowapi.ExtTrafficRedirect; | ||
85 | +import org.onosproject.flowapi.ExtWideCommunityInt; | ||
35 | import org.onosproject.incubator.net.resource.label.LabelResourceId; | 86 | import org.onosproject.incubator.net.resource.label.LabelResourceId; |
36 | import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint; | 87 | import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint; |
37 | import org.onosproject.incubator.net.tunnel.Tunnel; | 88 | import org.onosproject.incubator.net.tunnel.Tunnel; |
38 | import org.onosproject.incubator.net.tunnel.TunnelId; | 89 | import org.onosproject.incubator.net.tunnel.TunnelId; |
39 | import org.onosproject.incubator.net.tunnel.TunnelService; | 90 | import org.onosproject.incubator.net.tunnel.TunnelService; |
40 | import org.onosproject.net.ConnectPoint; | 91 | import org.onosproject.net.ConnectPoint; |
92 | + | ||
93 | +import org.onosproject.net.Annotations; | ||
41 | import org.onosproject.net.Device; | 94 | import org.onosproject.net.Device; |
42 | import org.onosproject.net.DeviceId; | 95 | import org.onosproject.net.DeviceId; |
43 | import org.onosproject.net.Link; | 96 | import org.onosproject.net.Link; |
... | @@ -56,12 +109,15 @@ import org.onosproject.net.flow.FlowRuleProviderService; | ... | @@ -56,12 +109,15 @@ import org.onosproject.net.flow.FlowRuleProviderService; |
56 | import org.onosproject.net.flow.TrafficSelector; | 109 | import org.onosproject.net.flow.TrafficSelector; |
57 | import org.onosproject.net.flow.FlowEntry.FlowEntryState; | 110 | import org.onosproject.net.flow.FlowEntry.FlowEntryState; |
58 | import org.onosproject.net.flow.criteria.Criterion; | 111 | import org.onosproject.net.flow.criteria.Criterion; |
112 | +import org.onosproject.net.flow.criteria.ExtensionCriterion; | ||
113 | +import org.onosproject.net.flow.criteria.ExtensionSelector; | ||
59 | import org.onosproject.net.flow.criteria.IPCriterion; | 114 | import org.onosproject.net.flow.criteria.IPCriterion; |
60 | import org.onosproject.net.flow.criteria.MetadataCriterion; | 115 | import org.onosproject.net.flow.criteria.MetadataCriterion; |
61 | import org.onosproject.net.flow.criteria.MplsBosCriterion; | 116 | import org.onosproject.net.flow.criteria.MplsBosCriterion; |
62 | import org.onosproject.net.flow.criteria.MplsCriterion; | 117 | import org.onosproject.net.flow.criteria.MplsCriterion; |
63 | import org.onosproject.net.flow.criteria.PortCriterion; | 118 | import org.onosproject.net.flow.criteria.PortCriterion; |
64 | import org.onosproject.net.flow.criteria.TunnelIdCriterion; | 119 | import org.onosproject.net.flow.criteria.TunnelIdCriterion; |
120 | +import org.onosproject.net.flow.instructions.ExtensionPropertyException; | ||
65 | import org.onosproject.net.provider.AbstractProvider; | 121 | import org.onosproject.net.provider.AbstractProvider; |
66 | import org.onosproject.net.provider.ProviderId; | 122 | import org.onosproject.net.provider.ProviderId; |
67 | import org.onosproject.net.resource.ResourceService; | 123 | import org.onosproject.net.resource.ResourceService; |
... | @@ -125,6 +181,7 @@ public class BgpcepFlowRuleProvider extends AbstractProvider | ... | @@ -125,6 +181,7 @@ public class BgpcepFlowRuleProvider extends AbstractProvider |
125 | protected DeviceService deviceService; | 181 | protected DeviceService deviceService; |
126 | 182 | ||
127 | private FlowRuleProviderService providerService; | 183 | private FlowRuleProviderService providerService; |
184 | + public static final String FLOW_PEER = "flowPeer"; | ||
128 | private PcepLabelObject labelObj; | 185 | private PcepLabelObject labelObj; |
129 | public static final int OUT_LABEL_TYPE = 0; | 186 | public static final int OUT_LABEL_TYPE = 0; |
130 | public static final int IN_LABEL_TYPE = 1; | 187 | public static final int IN_LABEL_TYPE = 1; |
... | @@ -572,14 +629,19 @@ public class BgpcepFlowRuleProvider extends AbstractProvider | ... | @@ -572,14 +629,19 @@ public class BgpcepFlowRuleProvider extends AbstractProvider |
572 | case ADD: | 629 | case ADD: |
573 | if (criteria == null) { | 630 | if (criteria == null) { |
574 | processRule(fbe.target(), PcepFlowType.ADD); | 631 | processRule(fbe.target(), PcepFlowType.ADD); |
575 | - flowEntries.add(new DefaultFlowEntry(fbe.target(), FlowEntryState.ADDED, 0, 0, 0)); | 632 | + } else { |
633 | + handleMessage(fbe, BgpPeer.FlowSpecOperation.ADD, batch.deviceId()); | ||
576 | } | 634 | } |
635 | + flowEntries.add(new DefaultFlowEntry(fbe.target(), FlowEntryState.ADDED, 0, 0, 0)); | ||
577 | break; | 636 | break; |
578 | case REMOVE: | 637 | case REMOVE: |
579 | if (criteria == null) { | 638 | if (criteria == null) { |
580 | processRule(fbe.target(), PcepFlowType.REMOVE); | 639 | processRule(fbe.target(), PcepFlowType.REMOVE); |
581 | - flowEntries.add(new DefaultFlowEntry(fbe.target(), FlowEntryState.REMOVED, 0, 0, 0)); | 640 | + } else { |
641 | + handleMessage(fbe, BgpPeer.FlowSpecOperation.DELETE, batch.deviceId()); | ||
582 | } | 642 | } |
643 | + | ||
644 | + flowEntries.add(new DefaultFlowEntry(fbe.target(), FlowEntryState.REMOVED, 0, 0, 0)); | ||
583 | break; | 645 | break; |
584 | default: | 646 | default: |
585 | log.error("Unknown flow operation: {}", fbe); | 647 | log.error("Unknown flow operation: {}", fbe); |
... | @@ -590,4 +652,330 @@ public class BgpcepFlowRuleProvider extends AbstractProvider | ... | @@ -590,4 +652,330 @@ public class BgpcepFlowRuleProvider extends AbstractProvider |
590 | providerService.batchOperationCompleted(batch.id(), status); | 652 | providerService.batchOperationCompleted(batch.id(), status); |
591 | providerService.pushFlowMetrics(batch.deviceId(), flowEntries); | 653 | providerService.pushFlowMetrics(batch.deviceId(), flowEntries); |
592 | } | 654 | } |
655 | + | ||
656 | + public void handleMessage(FlowRuleBatchEntry fbe, BgpPeer.FlowSpecOperation operType, DeviceId deviceId) { | ||
657 | + Set<Criterion> set = fbe.target().selector().criteria(); | ||
658 | + Iterator iterator = set.iterator(); | ||
659 | + Criterion cr; | ||
660 | + | ||
661 | + while (iterator.hasNext()) { | ||
662 | + cr = (Criterion) iterator.next(); | ||
663 | + | ||
664 | + switch (cr.type()) { | ||
665 | + case EXTENSION: | ||
666 | + ExtensionCriterion extensionCriterion = (ExtensionCriterion) cr; | ||
667 | + ExtensionSelector extension = extensionCriterion.extensionSelector(); | ||
668 | + | ||
669 | + ExtFlowContainer container = null; | ||
670 | + List<ExtFlowTypes> bgpFlows = null; | ||
671 | + | ||
672 | + try { | ||
673 | + container = extension.getPropertyValue("container"); | ||
674 | + } catch (ExtensionPropertyException e) { | ||
675 | + e.printStackTrace(); | ||
676 | + } | ||
677 | + | ||
678 | + bgpFlows = container.container(); | ||
679 | + iterateAndSend(bgpFlows, operType, deviceId); | ||
680 | + break; | ||
681 | + default: | ||
682 | + log.error("This flow type is not supported: {}", cr.type()); | ||
683 | + } | ||
684 | + } | ||
685 | + } | ||
686 | + | ||
687 | + void iterateAndSend(List<ExtFlowTypes> bgpFlows, BgpPeer.FlowSpecOperation operType, DeviceId deviceId) { | ||
688 | + ListIterator<ExtFlowTypes> iterator = bgpFlows.listIterator(); | ||
689 | + ExtFlowTypes flow; | ||
690 | + ExtKeyName name = null; | ||
691 | + ExtPrefix ipcSource = null; | ||
692 | + ExtPrefix ipcDestination = null; | ||
693 | + IpPrefix prefix = null; | ||
694 | + ListIterator<IpPrefix> pfxItr = null; | ||
695 | + ExtTrafficRate flowRate = null; | ||
696 | + ExtTrafficAction flowAction = null; | ||
697 | + ExtTrafficMarking flowMarking = null; | ||
698 | + List<BgpValueType> flowSpecComponents = new ArrayList<>(); | ||
699 | + List<BgpFsOperatorValue> operatorValue; | ||
700 | + BgpFlowSpecNlri flowSpec = new BgpFlowSpecNlri(flowSpecComponents); | ||
701 | + BgpFsActionTrafficRate rate = null; | ||
702 | + BgpFsActionTrafficAction action = null; | ||
703 | + BgpFsActionReDirect redirection = null; | ||
704 | + BgpFsActionTrafficMarking marking = null; | ||
705 | + List<BgpValueType> flowSpecAction = new LinkedList<>(); | ||
706 | + | ||
707 | + ExtWideCommunityInt wcIntList = null; | ||
708 | + ListIterator<Integer> wcItr = null; | ||
709 | + WideCommunity wideCommunity = null; | ||
710 | + | ||
711 | + int flags = 0; | ||
712 | + int hopCount = 0; | ||
713 | + int community = 0; | ||
714 | + int contextAs = 0; | ||
715 | + int localAs = 0; | ||
716 | + WideCommunityInteger wCommInt; | ||
717 | + WideCommunityParameter wCommParam = null; | ||
718 | + List<BgpValueType> wcParam = new ArrayList<>(); | ||
719 | + WideCommunityTarget wcTarget = null; | ||
720 | + WideCommunityExcludeTarget wcExcludeTarget = null; | ||
721 | + WideCommunityAttrHeader wideCommunityHeader = null; | ||
722 | + | ||
723 | + while (iterator.hasNext()) { | ||
724 | + flow = iterator.next(); | ||
725 | + switch (flow.type()) { | ||
726 | + case EXT_FLOW_RULE_KEY: | ||
727 | + name = (ExtKeyName) flow; | ||
728 | + break; | ||
729 | + case IPV4_DST_PFX: | ||
730 | + ipcDestination = (ExtPrefix) flow; | ||
731 | + pfxItr = ipcDestination.prefix().listIterator(); | ||
732 | + prefix = pfxItr.next(); | ||
733 | + flowSpecComponents.add(new BgpFsDestinationPrefix((byte) prefix.prefixLength(), | ||
734 | + prefix)); | ||
735 | + break; | ||
736 | + case IPV4_SRC_PFX: | ||
737 | + ipcSource = (ExtPrefix) flow; | ||
738 | + pfxItr = ipcSource.prefix().listIterator(); | ||
739 | + prefix = pfxItr.next(); | ||
740 | + flowSpecComponents.add(new BgpFsSourcePrefix((byte) prefix.prefixLength(), | ||
741 | + prefix)); | ||
742 | + break; | ||
743 | + case IP_PROTO_LIST: | ||
744 | + operatorValue = convert(((ExtIpProtocol) flow).ipProtocol()); | ||
745 | + flowSpecComponents.add(new BgpFsIpProtocol(operatorValue)); | ||
746 | + break; | ||
747 | + case IN_PORT_LIST: | ||
748 | + operatorValue = convert(((ExtPort) flow).port()); | ||
749 | + flowSpecComponents.add(new BgpFsPortNum(operatorValue)); | ||
750 | + break; | ||
751 | + case DST_PORT_LIST: | ||
752 | + operatorValue = convert(((ExtPort) flow).port()); | ||
753 | + flowSpecComponents.add(new BgpFsDestinationPortNum(operatorValue)); | ||
754 | + break; | ||
755 | + case SRC_PORT_LIST: | ||
756 | + operatorValue = convert(((ExtPort) flow).port()); | ||
757 | + flowSpecComponents.add(new BgpFsSourcePortNum(operatorValue)); | ||
758 | + break; | ||
759 | + case ICMP_TYPE_LIST: | ||
760 | + operatorValue = convert(((ExtIcmpType) flow).icmpType()); | ||
761 | + flowSpecComponents.add(new BgpFsIcmpType(operatorValue)); | ||
762 | + break; | ||
763 | + case ICMP_CODE_LIST: | ||
764 | + operatorValue = convert(((ExtIcmpCode) flow).icmpCode()); | ||
765 | + flowSpecComponents.add(new BgpFsIcmpCode(operatorValue)); | ||
766 | + break; | ||
767 | + case TCP_FLAG_LIST: | ||
768 | + operatorValue = convert(((ExtTcpFlag) flow).tcpFlag()); | ||
769 | + flowSpecComponents.add(new BgpFsTcpFlags(operatorValue)); | ||
770 | + break; | ||
771 | + case PACKET_LENGTH_LIST: | ||
772 | + operatorValue = convert(((ExtPacketLength) flow).packetLength()); | ||
773 | + flowSpecComponents.add(new BgpFsPacketLength(operatorValue)); | ||
774 | + break; | ||
775 | + case DSCP_VALUE_LIST: | ||
776 | + operatorValue = convert(((ExtDscpValue) flow).dscpValue()); | ||
777 | + flowSpecComponents.add(new BgpFsDscpValue(operatorValue)); | ||
778 | + break; | ||
779 | + case FRAGMENT_LIST: | ||
780 | + operatorValue = convert(((ExtFragment) flow).fragment()); | ||
781 | + flowSpecComponents.add(new BgpFsFragment(operatorValue)); | ||
782 | + break; | ||
783 | + case TRAFFIC_RATE: | ||
784 | + flowRate = (ExtTrafficRate) flow; | ||
785 | + rate = new BgpFsActionTrafficRate(flowRate.asn(), flowRate.rate().floatValue()); | ||
786 | + flowSpecAction.add(rate); | ||
787 | + flowSpec.setFsActionTlv(flowSpecAction); | ||
788 | + break; | ||
789 | + case TRAFFIC_ACTION: | ||
790 | + flowAction = (ExtTrafficAction) flow; | ||
791 | + byte[] byteAction = processTrafficAction((ExtTrafficAction) flow); | ||
792 | + action = new BgpFsActionTrafficAction(byteAction); | ||
793 | + flowSpecAction.add(action); | ||
794 | + flowSpec.setFsActionTlv(flowSpecAction); | ||
795 | + break; | ||
796 | + case TRAFFIC_REDIRECT: | ||
797 | + byte[] byteRedirect = processTrafficRedirect((ExtTrafficRedirect) flow); | ||
798 | + redirection = new BgpFsActionReDirect(byteRedirect); | ||
799 | + flowSpecAction.add(redirection); | ||
800 | + flowSpec.setFsActionTlv(flowSpecAction); | ||
801 | + break; | ||
802 | + case TRAFFIC_MARKING: | ||
803 | + byte[] byteMarking = new byte[6]; | ||
804 | + flowMarking = (ExtTrafficMarking) flow; | ||
805 | + byteMarking[5] = flowMarking.marking(); | ||
806 | + marking = new BgpFsActionTrafficMarking(byteMarking); | ||
807 | + flowSpecAction.add(marking); | ||
808 | + flowSpec.setFsActionTlv(flowSpecAction); | ||
809 | + break; | ||
810 | + case WIDE_COMM_FLAGS: | ||
811 | + wcIntList = (ExtWideCommunityInt) flow; | ||
812 | + wcItr = wcIntList.communityInt().listIterator(); | ||
813 | + flags = wcItr.next().intValue(); | ||
814 | + break; | ||
815 | + case WIDE_COMM_HOP_COUNT: | ||
816 | + wcIntList = (ExtWideCommunityInt) flow; | ||
817 | + wcItr = wcIntList.communityInt().listIterator(); | ||
818 | + hopCount = wcItr.next().intValue(); | ||
819 | + break; | ||
820 | + case WIDE_COMM_COMMUNITY: | ||
821 | + wcIntList = (ExtWideCommunityInt) flow; | ||
822 | + wcItr = wcIntList.communityInt().listIterator(); | ||
823 | + community = wcItr.next().intValue(); | ||
824 | + break; | ||
825 | + case WIDE_COMM_CONTEXT_AS: | ||
826 | + wcIntList = (ExtWideCommunityInt) flow; | ||
827 | + wcItr = wcIntList.communityInt().listIterator(); | ||
828 | + contextAs = wcItr.next().intValue(); | ||
829 | + break; | ||
830 | + case WIDE_COMM_LOCAL_AS: | ||
831 | + wcIntList = (ExtWideCommunityInt) flow; | ||
832 | + wcItr = wcIntList.communityInt().listIterator(); | ||
833 | + localAs = wcItr.next().intValue(); | ||
834 | + break; | ||
835 | + case WIDE_COMM_TARGET: | ||
836 | + wcTarget = processWideCommTarget((ExtTarget) flow); | ||
837 | + break; | ||
838 | + case WIDE_COMM_EXT_TARGET: | ||
839 | + wcExcludeTarget = processWideCommExcTarget((ExtTarget) flow); | ||
840 | + break; | ||
841 | + case WIDE_COMM_PARAMETER: | ||
842 | + wcIntList = (ExtWideCommunityInt) flow; | ||
843 | + wCommInt = new WideCommunityInteger(wcIntList.communityInt()); | ||
844 | + wcParam.add(wCommInt); | ||
845 | + wCommParam = new WideCommunityParameter(wcParam); | ||
846 | + break; | ||
847 | + default: | ||
848 | + log.error("error: this type is not supported"); | ||
849 | + break; | ||
850 | + } | ||
851 | + } | ||
852 | + | ||
853 | + if ((flowAction != null) && flowAction.rpd()) { | ||
854 | + wideCommunityHeader = new WideCommunityAttrHeader((byte) flags, (byte) hopCount, (short) 0); | ||
855 | + wideCommunity = new WideCommunity(wideCommunityHeader, community, localAs, contextAs, | ||
856 | + wcTarget, wcExcludeTarget, wCommParam); | ||
857 | + } | ||
858 | + | ||
859 | + if (name == null) { | ||
860 | + log.error("BGP Flow key is required"); | ||
861 | + return; | ||
862 | + } | ||
863 | + | ||
864 | + BgpPeer peer = getPeer(deviceId); | ||
865 | + if (peer != null) { | ||
866 | + peer.updateFlowSpec(operType, new BgpFlowSpecRouteKey(name.keyName()), flowSpec, wideCommunity); | ||
867 | + } | ||
868 | + } | ||
869 | + | ||
870 | + byte[] processTrafficAction(ExtTrafficAction flow) { | ||
871 | + ExtTrafficAction flowAction = null; | ||
872 | + byte[] byteAction = new byte[6]; | ||
873 | + byte actionByte = 0; | ||
874 | + flowAction = (ExtTrafficAction) flow; | ||
875 | + if (flowAction.terminal()) { | ||
876 | + actionByte = (byte) (actionByte | (byte) 0x01); | ||
877 | + } | ||
878 | + if (flowAction.sample()) { | ||
879 | + actionByte = (byte) (actionByte | (byte) 0x02); | ||
880 | + } | ||
881 | + if (flowAction.rpd()) { | ||
882 | + actionByte = (byte) (actionByte | (byte) 0x04); | ||
883 | + } | ||
884 | + byteAction[5] = actionByte; | ||
885 | + return byteAction; | ||
886 | + } | ||
887 | + | ||
888 | + byte[] processTrafficRedirect(ExtTrafficRedirect flow) { | ||
889 | + ExtTrafficRedirect flowRedirect = null; | ||
890 | + byte[] byteRedirect = new byte[6]; | ||
891 | + byte[] tmp; | ||
892 | + int val; | ||
893 | + flowRedirect = (ExtTrafficRedirect) flow; | ||
894 | + val = Integer.decode(flowRedirect.redirect()).intValue(); | ||
895 | + tmp = intToByteStream(val); | ||
896 | + for (int i = 0; i < tmp.length; i++) { | ||
897 | + byteRedirect[i] = tmp [i]; | ||
898 | + } | ||
899 | + return byteRedirect; | ||
900 | + } | ||
901 | + | ||
902 | + WideCommunityTarget processWideCommTarget(ExtTarget flow) { | ||
903 | + ExtPrefix localSpeaker; | ||
904 | + ExtPrefix remoteSpeaker; | ||
905 | + ListIterator<IpPrefix> pfxItr = null; | ||
906 | + ListIterator<IpPrefix> pfxItr1 = null; | ||
907 | + List<BgpValueType> wcIpv4 = null; | ||
908 | + ExtTarget target = flow; | ||
909 | + WideCommunityIpV4Neighbour wcIpV4Neighbour = null; | ||
910 | + WideCommunityTarget wcTarget = null; | ||
911 | + localSpeaker = target.localSpeaker(); | ||
912 | + remoteSpeaker = target.remoteSpeaker(); | ||
913 | + wcIpV4Neighbour = new WideCommunityIpV4Neighbour(); | ||
914 | + | ||
915 | + pfxItr = localSpeaker.prefix().listIterator(); | ||
916 | + pfxItr1 = remoteSpeaker.prefix().listIterator(); | ||
917 | + while (pfxItr.hasNext()) { | ||
918 | + wcIpV4Neighbour.add(pfxItr.next().address(), pfxItr1.next().address()); | ||
919 | + } | ||
920 | + | ||
921 | + wcIpv4 = new ArrayList<>(); | ||
922 | + wcIpv4.add(wcIpV4Neighbour); | ||
923 | + wcTarget = new WideCommunityTarget(wcIpv4); | ||
924 | + return wcTarget; | ||
925 | + } | ||
926 | + | ||
927 | + WideCommunityExcludeTarget processWideCommExcTarget(ExtTarget flow) { | ||
928 | + ExtPrefix localSpeaker; | ||
929 | + ExtPrefix remoteSpeaker; | ||
930 | + ListIterator<IpPrefix> pfxItr = null; | ||
931 | + ListIterator<IpPrefix> pfxItr1 = null; | ||
932 | + List<BgpValueType> wcIpv4 = null; | ||
933 | + ExtTarget target = flow; | ||
934 | + localSpeaker = target.localSpeaker(); | ||
935 | + remoteSpeaker = target.remoteSpeaker(); | ||
936 | + WideCommunityIpV4Neighbour wcIpV4Neighbour = null; | ||
937 | + wcIpV4Neighbour = new WideCommunityIpV4Neighbour(); | ||
938 | + WideCommunityExcludeTarget wcExcludeTarget = null; | ||
939 | + | ||
940 | + pfxItr = localSpeaker.prefix().listIterator(); | ||
941 | + pfxItr1 = remoteSpeaker.prefix().listIterator(); | ||
942 | + while (pfxItr.hasNext()) { | ||
943 | + wcIpV4Neighbour.add(pfxItr.next().address(), pfxItr1.next().address()); | ||
944 | + } | ||
945 | + | ||
946 | + wcIpv4 = new ArrayList<>(); | ||
947 | + wcIpv4.add(wcIpV4Neighbour); | ||
948 | + wcExcludeTarget = new WideCommunityExcludeTarget(wcIpv4); | ||
949 | + return wcExcludeTarget; | ||
950 | + } | ||
951 | + | ||
952 | + BgpPeer getPeer(DeviceId deviceId) { | ||
953 | + Device d = deviceService.getDevice(deviceId); | ||
954 | + Annotations a = d != null ? d.annotations() : null; | ||
955 | + String ipAddress = a.value(FLOW_PEER); | ||
956 | + BgpId bgpId = BgpId.bgpId(IpAddress.valueOf(ipAddress)); | ||
957 | + BgpPeer peer = bgpController.getPeer(bgpId); | ||
958 | + return peer; | ||
959 | + } | ||
960 | + | ||
961 | + byte[] intToByteStream(int val) { | ||
962 | + return new byte[] { | ||
963 | + (byte) (val >>> 24), | ||
964 | + (byte) (val >>> 16), | ||
965 | + (byte) (val >>> 8), | ||
966 | + (byte) val}; | ||
967 | + } | ||
968 | + | ||
969 | + List<BgpFsOperatorValue> convert(List<ExtOperatorValue> opVal) { | ||
970 | + List<BgpFsOperatorValue> list = new ArrayList(); | ||
971 | + BgpFsOperatorValue operatorValue; | ||
972 | + Iterator iterator = opVal.iterator(); | ||
973 | + while (iterator.hasNext()) { | ||
974 | + ExtOperatorValue element = (ExtOperatorValue) iterator.next(); | ||
975 | + operatorValue = new BgpFsOperatorValue(element.option(), element.value()); | ||
976 | + list.add(operatorValue); | ||
977 | + } | ||
978 | + | ||
979 | + return list; | ||
980 | + } | ||
593 | } | 981 | } | ... | ... |
... | @@ -34,7 +34,7 @@ | ... | @@ -34,7 +34,7 @@ |
34 | <dependencies> | 34 | <dependencies> |
35 | <dependency> | 35 | <dependency> |
36 | <groupId>org.onosproject</groupId> | 36 | <groupId>org.onosproject</groupId> |
37 | - <artifactId>onos-pcep-controller-api</artifactId> | 37 | + <artifactId>onos-app-bgp-flowapi</artifactId> |
38 | <version>${project.version}</version> | 38 | <version>${project.version}</version> |
39 | </dependency> | 39 | </dependency> |
40 | <dependency> | 40 | <dependency> |
... | @@ -44,6 +44,15 @@ | ... | @@ -44,6 +44,15 @@ |
44 | </dependency> | 44 | </dependency> |
45 | <dependency> | 45 | <dependency> |
46 | <groupId>org.onosproject</groupId> | 46 | <groupId>org.onosproject</groupId> |
47 | + <artifactId>onos-bgpio</artifactId> | ||
48 | + </dependency> | ||
49 | + <dependency> | ||
50 | + <groupId>org.onosproject</groupId> | ||
51 | + <artifactId>onos-pcep-controller-api</artifactId> | ||
52 | + <version>${project.version}</version> | ||
53 | + </dependency> | ||
54 | + <dependency> | ||
55 | + <groupId>org.onosproject</groupId> | ||
47 | <artifactId>onos-pcep-provider-tunnel</artifactId> | 56 | <artifactId>onos-pcep-provider-tunnel</artifactId> |
48 | <version>${project.version}</version> | 57 | <version>${project.version}</version> |
49 | </dependency> | 58 | </dependency> |
... | @@ -52,6 +61,22 @@ | ... | @@ -52,6 +61,22 @@ |
52 | <artifactId>onos-pcepio</artifactId> | 61 | <artifactId>onos-pcepio</artifactId> |
53 | <version>${project.version}</version> | 62 | <version>${project.version}</version> |
54 | </dependency> | 63 | </dependency> |
64 | + <dependency> | ||
65 | + <groupId>org.onosproject</groupId> | ||
66 | + <artifactId>onos-api</artifactId> | ||
67 | + <classifier>tests</classifier> | ||
68 | + <scope>test</scope> | ||
69 | + </dependency> | ||
70 | + | ||
71 | + <dependency> | ||
72 | + <groupId>io.netty</groupId> | ||
73 | + <artifactId>netty</artifactId> | ||
74 | + </dependency> | ||
75 | + | ||
76 | + <dependency> | ||
77 | + <groupId>org.onosproject</groupId> | ||
78 | + <artifactId>onlab-junit</artifactId> | ||
79 | + </dependency> | ||
55 | </dependencies> | 80 | </dependencies> |
56 | 81 | ||
57 | </project> | 82 | </project> | ... | ... |
... | @@ -70,6 +70,11 @@ | ... | @@ -70,6 +70,11 @@ |
70 | </dependency> | 70 | </dependency> |
71 | 71 | ||
72 | <dependency> | 72 | <dependency> |
73 | + <groupId>org.onosproject</groupId> | ||
74 | + <artifactId>onos-app-bgp-flowapi</artifactId> | ||
75 | + <version>${project.version}</version> | ||
76 | + </dependency> | ||
77 | + <dependency> | ||
73 | <groupId>org.apache.felix</groupId> | 78 | <groupId>org.apache.felix</groupId> |
74 | <artifactId>org.apache.felix.scr.annotations</artifactId> | 79 | <artifactId>org.apache.felix.scr.annotations</artifactId> |
75 | </dependency> | 80 | </dependency> | ... | ... |
-
Please register or login to post a comment