jcc
Committed by Thomas Vachuska

FlowRule private extension refactor.

1.merge private flow into regular flowrule subsystem.no mirror code any
more.no change flowrule api.
2.define a rich-data-type to carry private flow.
3.modify OpenFlowRuleProvider.class to support for 3rd party private
flow.i don't know whether is suitable.because this class name is
relative with open flow protocal.
4.fix some junit test bug caused by modification of FlowRule interface.

Change-Id: I6c54d1e97f231a75bd1b416f0893e0379613d7ce
Showing 25 changed files with 573 additions and 1418 deletions
1 -<?xml version="1.0" encoding="UTF-8"?> 1 +<?xml version="1.0" encoding="UTF-8"?>
2 -<!-- 2 +<!--
3 - ~ Copyright 2014 Open Networking Laboratory 3 + ~ Copyright 2014 Open Networking Laboratory
4 - ~ 4 + ~
5 - ~ Licensed under the Apache License, Version 2.0 (the "License"); 5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 - ~ you may not use this file except in compliance with 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 7 + ~ You may obtain a copy of the License at
8 - ~ 8 + ~
9 - ~ http://www.apache.org/licenses/LICENSE-2.0 9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 - ~ 10 + ~
11 - ~ Unless required by applicable law or agreed to in writing, software 11 + ~ Unless required by applicable law or agreed to in writing, software
12 - ~ distributed under the License is distributed on an "AS IS" BASIS, 12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 - ~ See the License for the specific language governing permissions and 14 + ~ See the License for the specific language governing permissions and
15 - ~ limitations under the License. 15 + ~ limitations under the License.
16 - --> 16 + -->
17 -<project xmlns="http://maven.apache.org/POM/4.0.0" 17 +<project xmlns="http://maven.apache.org/POM/4.0.0"
18 - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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/xsd/maven-4.0.0.xsd"> 19 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
20 - <modelVersion>4.0.0</modelVersion> 20 + <modelVersion>4.0.0</modelVersion>
21 - <parent> 21 + <parent>
22 - <artifactId>onos-apps</artifactId> 22 + <artifactId>onos-apps</artifactId>
23 - <groupId>org.onosproject</groupId> 23 + <groupId>org.onosproject</groupId>
24 - <version>1.2.0-SNAPSHOT</version> 24 + <version>1.2.0-SNAPSHOT</version>
25 - <relativePath>../pom.xml</relativePath> 25 + <relativePath>../pom.xml</relativePath>
26 - </parent> 26 + </parent>
27 - 27 +
28 - <artifactId>onos-app-segmentrouting</artifactId> 28 + <artifactId>onos-app-segmentrouting</artifactId>
29 - <packaging>bundle</packaging> 29 + <packaging>bundle</packaging>
30 - 30 +
31 - <description>Segment routing application</description> 31 + <description>Segment routing application</description>
32 - 32 +
33 - <properties> 33 + <properties>
34 - <onos.app.name>org.onosproject.segmentrouting</onos.app.name> 34 + <onos.app.name>org.onosproject.segmentrouting</onos.app.name>
35 - </properties> 35 + </properties>
36 - 36 +
37 -</project> 37 +</project>
......
1 /* 1 /*
2 - * Copyright 2014-2015 Open Networking Laboratory 2 + * Copyright 2014 Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -15,17 +15,17 @@ ...@@ -15,17 +15,17 @@
15 */ 15 */
16 package org.onosproject.net.flow; 16 package org.onosproject.net.flow;
17 17
18 +import static com.google.common.base.MoreObjects.toStringHelper;
19 +import static com.google.common.base.Preconditions.checkArgument;
20 +import static com.google.common.base.Preconditions.checkNotNull;
21 +
22 +import java.util.Objects;
23 +
18 import org.onosproject.core.ApplicationId; 24 import org.onosproject.core.ApplicationId;
19 import org.onosproject.core.DefaultGroupId; 25 import org.onosproject.core.DefaultGroupId;
20 import org.onosproject.core.GroupId; 26 import org.onosproject.core.GroupId;
21 import org.onosproject.net.DeviceId; 27 import org.onosproject.net.DeviceId;
22 28
23 -import java.util.Objects;
24 -
25 -import static com.google.common.base.MoreObjects.toStringHelper;
26 -import static com.google.common.base.Preconditions.checkArgument;
27 -import static com.google.common.base.Preconditions.checkNotNull;
28 -
29 public class DefaultFlowRule implements FlowRule { 29 public class DefaultFlowRule implements FlowRule {
30 30
31 private final DeviceId deviceId; 31 private final DeviceId deviceId;
...@@ -43,12 +43,12 @@ public class DefaultFlowRule implements FlowRule { ...@@ -43,12 +43,12 @@ public class DefaultFlowRule implements FlowRule {
43 private final GroupId groupId; 43 private final GroupId groupId;
44 44
45 private final Integer tableId; 45 private final Integer tableId;
46 - 46 + private final FlowRuleExtPayLoad payLoad;
47 47
48 @Deprecated 48 @Deprecated
49 public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector, 49 public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector,
50 - TrafficTreatment treatment, int priority, long flowId, 50 + TrafficTreatment treatment, int priority,
51 - int timeout, boolean permanent) { 51 + long flowId, int timeout, boolean permanent) {
52 this.deviceId = deviceId; 52 this.deviceId = deviceId;
53 this.priority = priority; 53 this.priority = priority;
54 this.selector = selector; 54 this.selector = selector;
...@@ -61,12 +61,14 @@ public class DefaultFlowRule implements FlowRule { ...@@ -61,12 +61,14 @@ public class DefaultFlowRule implements FlowRule {
61 this.groupId = new DefaultGroupId((short) ((flowId >>> 32) & 0xFFFF)); 61 this.groupId = new DefaultGroupId((short) ((flowId >>> 32) & 0xFFFF));
62 this.id = FlowId.valueOf(flowId); 62 this.id = FlowId.valueOf(flowId);
63 this.tableId = 0; 63 this.tableId = 0;
64 + this.payLoad = null;
64 } 65 }
65 66
66 @Deprecated 67 @Deprecated
67 public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector, 68 public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector,
68 - TrafficTreatment treatment, int priority, long flowId, 69 + TrafficTreatment treatment, int priority,
69 - int timeout, boolean permanent, Type tableType) { 70 + long flowId, int timeout, boolean permanent,
71 + Type tableType) {
70 this.deviceId = deviceId; 72 this.deviceId = deviceId;
71 this.priority = priority; 73 this.priority = priority;
72 this.selector = selector; 74 this.selector = selector;
...@@ -80,23 +82,26 @@ public class DefaultFlowRule implements FlowRule { ...@@ -80,23 +82,26 @@ public class DefaultFlowRule implements FlowRule {
80 this.id = FlowId.valueOf(flowId); 82 this.id = FlowId.valueOf(flowId);
81 this.tableId = tableType.ordinal(); 83 this.tableId = tableType.ordinal();
82 84
85 + this.payLoad = null;
83 } 86 }
84 87
85 @Deprecated 88 @Deprecated
86 public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector, 89 public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector,
87 - TrafficTreatment treatment, int priority, ApplicationId appId, 90 + TrafficTreatment treatment, int priority,
88 - int timeout, boolean permanent) { 91 + ApplicationId appId, int timeout, boolean permanent) {
89 - this(deviceId, selector, treatment, priority, appId, new DefaultGroupId(0), 92 + this(deviceId, selector, treatment, priority, appId,
90 - timeout, permanent); 93 + new DefaultGroupId(0), timeout, permanent);
91 } 94 }
92 95
93 @Deprecated 96 @Deprecated
94 public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector, 97 public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector,
95 - TrafficTreatment treatment, int priority, ApplicationId appId, 98 + TrafficTreatment treatment, int priority,
96 - int timeout, boolean permanent, Type type) { 99 + ApplicationId appId, int timeout, boolean permanent,
100 + Type type) {
97 101
98 if (priority < FlowRule.MIN_PRIORITY) { 102 if (priority < FlowRule.MIN_PRIORITY) {
99 - throw new IllegalArgumentException("Priority cannot be less than " + MIN_PRIORITY); 103 + throw new IllegalArgumentException("Priority cannot be less than "
104 + + MIN_PRIORITY);
100 } 105 }
101 106
102 this.deviceId = deviceId; 107 this.deviceId = deviceId;
...@@ -110,22 +115,26 @@ public class DefaultFlowRule implements FlowRule { ...@@ -110,22 +115,26 @@ public class DefaultFlowRule implements FlowRule {
110 this.created = System.currentTimeMillis(); 115 this.created = System.currentTimeMillis();
111 this.tableId = type.ordinal(); 116 this.tableId = type.ordinal();
112 117
118 + this.payLoad = null;
113 /* 119 /*
114 - * id consists of the following. 120 + * id consists of the following. | appId (16 bits) | groupId (16 bits) |
115 - * | appId (16 bits) | groupId (16 bits) | flowId (32 bits) | 121 + * flowId (32 bits) |
116 */ 122 */
117 - this.id = FlowId.valueOf((((long) this.appId) << 48) | (((long) this.groupId.id()) << 32) 123 + this.id = FlowId.valueOf((((long) this.appId) << 48)
124 + | (((long) this.groupId.id()) << 32)
118 | (this.hash() & 0xffffffffL)); 125 | (this.hash() & 0xffffffffL));
119 126
120 } 127 }
121 128
122 @Deprecated 129 @Deprecated
123 public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector, 130 public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector,
124 - TrafficTreatment treatment, int priority, ApplicationId appId, 131 + TrafficTreatment treatment, int priority,
125 - GroupId groupId, int timeout, boolean permanent) { 132 + ApplicationId appId, GroupId groupId, int timeout,
133 + boolean permanent) {
126 134
127 if (priority < FlowRule.MIN_PRIORITY) { 135 if (priority < FlowRule.MIN_PRIORITY) {
128 - throw new IllegalArgumentException("Priority cannot be less than " + MIN_PRIORITY); 136 + throw new IllegalArgumentException("Priority cannot be less than "
137 + + MIN_PRIORITY);
129 } 138 }
130 139
131 this.deviceId = deviceId; 140 this.deviceId = deviceId;
...@@ -138,12 +147,14 @@ public class DefaultFlowRule implements FlowRule { ...@@ -138,12 +147,14 @@ public class DefaultFlowRule implements FlowRule {
138 this.permanent = permanent; 147 this.permanent = permanent;
139 this.created = System.currentTimeMillis(); 148 this.created = System.currentTimeMillis();
140 this.tableId = 0; 149 this.tableId = 0;
150 + this.payLoad = null;
141 151
142 /* 152 /*
143 - * id consists of the following. 153 + * id consists of the following. | appId (16 bits) | groupId (16 bits) |
144 - * | appId (16 bits) | groupId (16 bits) | flowId (32 bits) | 154 + * flowId (32 bits) |
145 */ 155 */
146 - this.id = FlowId.valueOf((((long) this.appId) << 48) | (((long) this.groupId.id()) << 32) 156 + this.id = FlowId.valueOf((((long) this.appId) << 48)
157 + | (((long) this.groupId.id()) << 32)
147 | (this.hash() & 0xffffffffL)); 158 | (this.hash() & 0xffffffffL));
148 } 159 }
149 160
...@@ -159,7 +170,7 @@ public class DefaultFlowRule implements FlowRule { ...@@ -159,7 +170,7 @@ public class DefaultFlowRule implements FlowRule {
159 this.permanent = rule.isPermanent(); 170 this.permanent = rule.isPermanent();
160 this.created = System.currentTimeMillis(); 171 this.created = System.currentTimeMillis();
161 this.tableId = rule.tableId(); 172 this.tableId = rule.tableId();
162 - 173 + this.payLoad = rule.payLoad();
163 } 174 }
164 175
165 private DefaultFlowRule(DeviceId deviceId, TrafficSelector selector, 176 private DefaultFlowRule(DeviceId deviceId, TrafficSelector selector,
...@@ -181,8 +192,98 @@ public class DefaultFlowRule implements FlowRule { ...@@ -181,8 +192,98 @@ public class DefaultFlowRule implements FlowRule {
181 192
182 //FIXME: fields below will be removed. 193 //FIXME: fields below will be removed.
183 this.groupId = null; 194 this.groupId = null;
195 + this.payLoad = null;
196 + }
184 197
198 + /**
199 + * Support for the third party flow rule. Creates a flow rule of flow table.
200 + *
201 + * @param deviceId the identity of the device where this rule applies
202 + * @param selector the traffic selector that identifies what traffic this
203 + * rule
204 + * @param treatment the traffic treatment that applies to selected traffic
205 + * @param priority the flow rule priority given in natural order
206 + * @param appId the application id of this flow
207 + * @param timeout the timeout for this flow requested by an application
208 + * @param permanent whether the flow is permanent i.e. does not time out
209 + * @param payLoad 3rd-party origin private flow
210 + */
211 + public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector,
212 + TrafficTreatment treatment, int priority,
213 + ApplicationId appId, int timeout, boolean permanent,
214 + FlowRuleExtPayLoad payLoad) {
215 +
216 + if (priority < FlowRule.MIN_PRIORITY) {
217 + throw new IllegalArgumentException("Priority cannot be less than "
218 + + MIN_PRIORITY);
219 + }
220 +
221 + this.deviceId = deviceId;
222 + this.priority = priority;
223 + this.selector = selector;
224 + this.treatment = treatment;
225 + this.appId = appId.id();
226 + this.groupId = new DefaultGroupId(0);
227 + this.timeout = timeout;
228 + this.permanent = permanent;
229 + this.tableId = 0;
230 + this.created = System.currentTimeMillis();
231 + this.payLoad = payLoad;
185 232
233 + /*
234 + * id consists of the following. | appId (16 bits) | groupId (16 bits) |
235 + * flowId (32 bits) |
236 + */
237 + this.id = FlowId.valueOf((((long) this.appId) << 48)
238 + | (((long) this.groupId.id()) << 32)
239 + | (this.hash() & 0xffffffffL));
240 + }
241 +
242 + /**
243 + * Support for the third party flow rule. Creates a flow rule of group
244 + * table.
245 + *
246 + * @param deviceId the identity of the device where this rule applies
247 + * @param selector the traffic selector that identifies what traffic this
248 + * rule
249 + * @param treatment the traffic treatment that applies to selected traffic
250 + * @param priority the flow rule priority given in natural order
251 + * @param appId the application id of this flow
252 + * @param groupId the group id of this flow
253 + * @param timeout the timeout for this flow requested by an application
254 + * @param permanent whether the flow is permanent i.e. does not time out
255 + * @param payLoad 3rd-party origin private flow
256 + *
257 + */
258 + public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector,
259 + TrafficTreatment treatment, int priority,
260 + ApplicationId appId, GroupId groupId, int timeout,
261 + boolean permanent, FlowRuleExtPayLoad payLoad) {
262 +
263 + if (priority < FlowRule.MIN_PRIORITY) {
264 + throw new IllegalArgumentException("Priority cannot be less than "
265 + + MIN_PRIORITY);
266 + }
267 +
268 + this.deviceId = deviceId;
269 + this.priority = priority;
270 + this.selector = selector;
271 + this.treatment = treatment;
272 + this.appId = appId.id();
273 + this.groupId = groupId;
274 + this.timeout = timeout;
275 + this.permanent = permanent;
276 + this.created = System.currentTimeMillis();
277 + this.tableId = 0;
278 + this.payLoad = payLoad;
279 +
280 + /*
281 + * id consists of the following. | appId (16 bits) | groupId (16 bits) |
282 + * flowId (32 bits) |
283 + */
284 + this.id = FlowId.valueOf((((long) this.appId) << 48)
285 + | (((long) this.groupId.id()) << 32)
286 + | (this.hash() & 0xffffffffL));
186 } 287 }
187 288
188 @Override 289 @Override
...@@ -225,14 +326,15 @@ public class DefaultFlowRule implements FlowRule { ...@@ -225,14 +326,15 @@ public class DefaultFlowRule implements FlowRule {
225 * The priority and statistics can change on a given treatment and selector 326 * The priority and statistics can change on a given treatment and selector
226 * 327 *
227 * (non-Javadoc) 328 * (non-Javadoc)
329 + *
228 * @see java.lang.Object#equals(java.lang.Object) 330 * @see java.lang.Object#equals(java.lang.Object)
229 */ 331 */
230 public int hashCode() { 332 public int hashCode() {
231 - return Objects.hash(deviceId, selector, priority, tableId); 333 + return Objects.hash(deviceId, selector, priority, tableId, payLoad);
232 } 334 }
233 335
234 public int hash() { 336 public int hash() {
235 - return Objects.hash(deviceId, selector, treatment, tableId); 337 + return Objects.hash(deviceId, selector, treatment, tableId, payLoad);
236 } 338 }
237 339
238 @Override 340 @Override
...@@ -240,6 +342,7 @@ public class DefaultFlowRule implements FlowRule { ...@@ -240,6 +342,7 @@ public class DefaultFlowRule implements FlowRule {
240 * The priority and statistics can change on a given treatment and selector 342 * The priority and statistics can change on a given treatment and selector
241 * 343 *
242 * (non-Javadoc) 344 * (non-Javadoc)
345 + *
243 * @see java.lang.Object#equals(java.lang.Object) 346 * @see java.lang.Object#equals(java.lang.Object)
244 */ 347 */
245 public boolean equals(Object obj) { 348 public boolean equals(Object obj) {
...@@ -251,8 +354,8 @@ public class DefaultFlowRule implements FlowRule { ...@@ -251,8 +354,8 @@ public class DefaultFlowRule implements FlowRule {
251 return Objects.equals(deviceId, that.deviceId) && 354 return Objects.equals(deviceId, that.deviceId) &&
252 Objects.equals(priority, that.priority) && 355 Objects.equals(priority, that.priority) &&
253 Objects.equals(selector, that.selector) && 356 Objects.equals(selector, that.selector) &&
254 - Objects.equals(tableId, that.tableId); 357 + Objects.equals(tableId, that.tableId)
255 - 358 + && Objects.equals(payLoad, that.payLoad);
256 } 359 }
257 return false; 360 return false;
258 } 361 }
...@@ -267,6 +370,7 @@ public class DefaultFlowRule implements FlowRule { ...@@ -267,6 +370,7 @@ public class DefaultFlowRule implements FlowRule {
267 .add("treatment", treatment == null ? "N/A" : treatment.allInstructions()) 370 .add("treatment", treatment == null ? "N/A" : treatment.allInstructions())
268 .add("tableId", tableId) 371 .add("tableId", tableId)
269 .add("created", created) 372 .add("created", created)
373 + .add("payLoad", payLoad).toString()
270 .toString(); 374 .toString();
271 } 375 }
272 376
...@@ -383,4 +487,9 @@ public class DefaultFlowRule implements FlowRule { ...@@ -383,4 +487,9 @@ public class DefaultFlowRule implements FlowRule {
383 487
384 } 488 }
385 489
490 + @Override
491 + public FlowRuleExtPayLoad payLoad() {
492 + return payLoad;
493 + }
494 +
386 } 495 }
......
1 /* 1 /*
2 - * Copyright 2014-2015 Open Networking Laboratory 2 + * Copyright 2014 Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -20,8 +20,8 @@ import org.onosproject.core.GroupId; ...@@ -20,8 +20,8 @@ import org.onosproject.core.GroupId;
20 import org.onosproject.net.DeviceId; 20 import org.onosproject.net.DeviceId;
21 21
22 /** 22 /**
23 - * Represents a generalized match &amp; action pair to be applied to 23 + * Represents a generalized match &amp; action pair to be applied to an
24 - * an infrastructure device. 24 + * infrastructure device.
25 */ 25 */
26 public interface FlowRule { 26 public interface FlowRule {
27 27
...@@ -29,14 +29,16 @@ public interface FlowRule { ...@@ -29,14 +29,16 @@ public interface FlowRule {
29 static final int MIN_PRIORITY = 0; 29 static final int MIN_PRIORITY = 0;
30 30
31 /** 31 /**
32 - * The FlowRule type is used to determine in which table the flow rule 32 + * The FlowRule type is used to determine in which table the flow rule needs
33 - * needs to be put for multi-table support switch. 33 + * to be put for multi-table support switch. For single table switch,
34 - * For single table switch, Default is used. 34 + * Default is used.
35 */ 35 */
36 @Deprecated 36 @Deprecated
37 public static enum Type { 37 public static enum Type {
38 - /* Default type - used in flow rule for single table switch 38 + /*
39 - * NOTE: this setting should not be used as Table 0 in a multi-table pipeline*/ 39 + * Default type - used in flow rule for single table switch NOTE: this
40 + * setting should not be used as Table 0 in a multi-table pipeline
41 + */
40 DEFAULT, 42 DEFAULT,
41 /* Used in flow entry for IP table */ 43 /* Used in flow entry for IP table */
42 IP, 44 IP,
...@@ -98,8 +100,8 @@ public interface FlowRule { ...@@ -98,8 +100,8 @@ public interface FlowRule {
98 DeviceId deviceId(); 100 DeviceId deviceId();
99 101
100 /** 102 /**
101 - * Returns the traffic selector that identifies what traffic this 103 + * Returns the traffic selector that identifies what traffic this rule
102 - * rule should apply to. 104 + * should apply to.
103 * 105 *
104 * @return traffic selector 106 * @return traffic selector
105 */ 107 */
...@@ -224,4 +226,10 @@ public interface FlowRule { ...@@ -224,4 +226,10 @@ public interface FlowRule {
224 226
225 } 227 }
226 228
229 + /**
230 + * Returns the third party original flow rule.
231 + *
232 + * @return FlowRuleExtPayLoad
233 + */
234 + FlowRuleExtPayLoad payLoad();
227 } 235 }
......
1 +package org.onosproject.net.flow;
2 +
3 +import static com.google.common.base.MoreObjects.toStringHelper;
4 +
5 +import java.util.Arrays;
6 +import java.util.Objects;
7 +
8 +/**
9 + * Represents for 3rd-party private original flow.
10 + */
11 +public final class FlowRuleExtPayLoad {
12 + private final byte[] payLoad;
13 +
14 + /**
15 + * private constructor.
16 + *
17 + * @param payLoad private flow
18 + */
19 + private FlowRuleExtPayLoad(byte[] payLoad) {
20 + this.payLoad = payLoad;
21 + }
22 +
23 + /**
24 + * Creates a FlowRuleExtPayLoad.
25 + *
26 + * @param payLoad
27 + * @return FlowRuleExtPayLoad payLoad
28 + */
29 + public static FlowRuleExtPayLoad flowRuleExtPayLoad(byte[] payLoad) {
30 + return new FlowRuleExtPayLoad(payLoad);
31 + }
32 +
33 + /**
34 + * Returns private flow.
35 + *
36 + * @return payLoad private flow
37 + */
38 + public byte[] payLoad() {
39 + return payLoad;
40 + }
41 +
42 + @Override
43 + public int hashCode() {
44 + return Objects.hash(payLoad);
45 + }
46 +
47 + public int hash() {
48 + return Objects.hash(payLoad);
49 + }
50 +
51 + @Override
52 + public boolean equals(Object obj) {
53 + if (this == obj) {
54 + return true;
55 + }
56 + if (obj instanceof FlowRuleExtPayLoad) {
57 + FlowRuleExtPayLoad that = (FlowRuleExtPayLoad) obj;
58 + return Arrays.equals(payLoad, that.payLoad);
59 +
60 + }
61 + return false;
62 + }
63 +
64 + @Override
65 + public String toString() {
66 + return toStringHelper(this).add("payLoad", payLoad).toString();
67 + }
68 +}
1 -/*
2 - * Copyright 2015 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.net.flowext;
17 -
18 -import org.onosproject.core.ApplicationId;
19 -import org.onosproject.core.DefaultGroupId;
20 -import org.onosproject.core.GroupId;
21 -import org.onosproject.net.DeviceId;
22 -import org.onosproject.net.flow.DefaultFlowRule;
23 -import org.onosproject.net.flow.FlowRule;
24 -import org.onosproject.net.flow.TrafficSelector;
25 -import org.onosproject.net.flow.TrafficTreatment;
26 -
27 -import java.util.Objects;
28 -
29 -import static com.google.common.base.MoreObjects.toStringHelper;
30 -
31 -/**
32 - * Experimental extension to the flow rule subsystem; still under development.
33 - * A temporary flow rule extend implementation, It will cover current onos flow rule and other flow extension.
34 - */
35 -public class DefaultFlowRuleExt
36 - extends DefaultFlowRule implements FlowRuleExt {
37 -
38 - private FlowEntryExtension flowEntryExtension;
39 -
40 - public DefaultFlowRuleExt(DeviceId deviceId, TrafficSelector selector,
41 - TrafficTreatment treatment, int priority, long flowId,
42 - int timeout, boolean permanent) {
43 - super(deviceId, selector, treatment, priority, flowId, timeout, permanent);
44 - }
45 -
46 - public DefaultFlowRuleExt(DeviceId deviceId, TrafficSelector selector,
47 - TrafficTreatment treatment, int priority, ApplicationId appId,
48 - int timeout, boolean permanent) {
49 - this(deviceId, selector, treatment, priority, appId, new DefaultGroupId(0),
50 - timeout, permanent);
51 - }
52 -
53 - public DefaultFlowRuleExt(DeviceId deviceId, TrafficSelector selector,
54 - TrafficTreatment treatment, int priority, ApplicationId appId,
55 - GroupId groupId, int timeout, boolean permanent) {
56 - super(deviceId, selector, treatment, priority, appId, groupId, timeout, permanent);
57 - }
58 -
59 - public DefaultFlowRuleExt(FlowRule rule) {
60 - super(rule);
61 - }
62 -
63 - public DefaultFlowRuleExt(ApplicationId appId, DeviceId deviceId, FlowEntryExtension data) {
64 - this(deviceId, null, null, FlowRule.MIN_PRIORITY, appId, 0, false);
65 - this.flowEntryExtension = data;
66 - }
67 -
68 - @Override
69 - public FlowEntryExtension getFlowEntryExt() {
70 - return this.flowEntryExtension;
71 - }
72 -
73 - @Override
74 - public int hashCode() {
75 - return 31 * super.hashCode() + Objects.hash(flowEntryExtension);
76 - }
77 -
78 - public int hash() {
79 - return 31 * super.hashCode() + Objects.hash(flowEntryExtension);
80 - }
81 -
82 - @Override
83 - public boolean equals(Object obj) {
84 - if (this == obj) {
85 - return true;
86 - }
87 - if (obj == null || getClass() != obj.getClass()) {
88 - return false;
89 - }
90 - if (!super.equals(obj)) {
91 - return false;
92 - }
93 - final DefaultFlowRuleExt other = (DefaultFlowRuleExt) obj;
94 - return Objects.equals(this.flowEntryExtension, other.flowEntryExtension);
95 - }
96 -
97 - @Override
98 - public String toString() {
99 - return toStringHelper(this)
100 - // TODO there might be a better way to grab super's string
101 - .add("id", Long.toHexString(id().value()))
102 - .add("deviceId", deviceId())
103 - .add("priority", priority())
104 - .add("selector", selector().criteria())
105 - .add("treatment", treatment() == null ? "N/A" : treatment().allInstructions())
106 - //.add("created", created)
107 - .add("flowEntryExtension", flowEntryExtension)
108 - .toString();
109 - }
110 -}
1 -/*
2 - * Copyright 2015 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.net.flowext;
17 -
18 -import java.nio.ByteBuffer;
19 -import java.util.Objects;
20 -
21 -/**
22 - * Experimental extension to the flow rule subsystem; still under development.
23 - * Represents a generic abstraction of the service data. User app can customize whatever it needs to install on devices.
24 - */
25 -public class DownStreamFlowEntry implements FlowEntryExtension {
26 -
27 - /**
28 - * temporarily only have byte stream, but it will be extract more abstract information from it later.
29 - */
30 - private final ByteBuffer payload;
31 -
32 - public DownStreamFlowEntry(ByteBuffer data) {
33 - this.payload = data;
34 - }
35 -
36 - /**
37 - * Get the payload of flowExtension.
38 - *
39 - * @return the byte steam value of payload.
40 - */
41 -// @Override
42 -// public ByteBuffer getPayload() {
43 - // TODO Auto-generated method stub
44 -// return payload;
45 -// }
46 -
47 - /**
48 - * Returns a hash code value for the object.
49 - * It use payload as parameter to hash.
50 - *
51 - * @return a hash code value for this object.
52 - */
53 - @Override
54 - public int hashCode() {
55 - return Objects.hash(payload);
56 - }
57 -
58 - /**
59 - * Indicates whether some other object is "equal to" this one.
60 - *
61 - * @param obj the reference object with which to compare.
62 - * @return {@code true} if this object is the same as the obj
63 - * argument; {@code false} otherwise.
64 - */
65 - @Override
66 - public boolean equals(Object obj) {
67 - if (obj instanceof DownStreamFlowEntry) {
68 - DownStreamFlowEntry packet = (DownStreamFlowEntry) obj;
69 - return Objects.equals(this.payload, packet.payload);
70 - } else {
71 - return false;
72 - }
73 - }
74 -
75 - /**
76 - * Returns a string representation of the object.
77 - *
78 - * @return a string representation of the object.
79 - */
80 - @Override
81 - public String toString() {
82 - String obj = new String(payload.array());
83 - return obj;
84 - }
85 -}
1 -/*
2 - * Copyright 2015 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.net.flowext;
17 -
18 -
19 -/**
20 - * Experimental extension to the flow rule subsystem; still under development.
21 - * Represents a generic abstraction of the service data. User app can customize whatever it needs to install on devices.
22 - */
23 -public interface FlowEntryExtension {
24 - // some abstraction of the service data, like length, type, etc, will be added here later
25 -
26 -}
1 -/*
2 - * Copyright 2015 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.net.flowext;
17 -
18 -import com.google.common.base.MoreObjects;
19 -import org.onosproject.net.flow.CompletedBatchOperation;
20 -import org.onosproject.net.flow.FlowRule;
21 -
22 -import java.util.Set;
23 -
24 -/**
25 - * Experimental extension to the flow rule subsystem; still under development.
26 - * <p>
27 - * Representation of a completed flow rule batch operation.
28 - * </p>
29 - */
30 -//TODO explain the purpose of this class beyond FlowRuleProvider
31 -public class FlowExtCompletedOperation extends CompletedBatchOperation {
32 - // the batchId is provided by application, once one flow rule of this batch failed
33 - // all the batch should withdraw
34 - private final long batchId;
35 -
36 - public FlowExtCompletedOperation(long batchId, boolean success, Set<FlowRule> failures) {
37 - super(success, failures, null);
38 - this.batchId = batchId;
39 - }
40 -
41 - /**
42 - * Returns the BatchId of this BatchOperation.
43 - *
44 - * @return the number of Batch
45 - */
46 - public long getBatchId() {
47 - return batchId;
48 - }
49 -
50 - /**
51 - * Returns a string representation of the object.
52 - *
53 - * @return a string representation of the object.
54 - */
55 - @Override
56 - public String toString() {
57 - return MoreObjects.toStringHelper(getClass())
58 - .add("success?", isSuccess())
59 - .add("failedItems", failedIds())
60 - .toString();
61 - }
62 -}
...\ No newline at end of file ...\ No newline at end of file
1 -/*
2 - * Copyright 2015 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.net.flowext;
17 -
18 -import org.onosproject.net.flow.FlowRule;
19 -
20 -/**
21 - * Experimental extension to the flow rule subsystem; still under development.
22 - * <p>
23 - * FlowRule extended for current FlowRule API.
24 - * </p>
25 - */
26 -public interface FlowRuleExt extends FlowRule {
27 - /**
28 - * Get the flow entry extension.
29 - *
30 - * @return FlowEntryExtension value.
31 - */
32 - FlowEntryExtension getFlowEntryExt();
33 -}
1 -/*
2 - * Copyright 2015 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.net.flowext;
17 -
18 -import org.onosproject.net.flow.FlowRuleBatchEvent;
19 -import org.onosproject.net.flow.FlowRuleBatchRequest;
20 -
21 -import java.util.concurrent.Future;
22 -
23 -/**
24 - * Experimental extension to the flow rule subsystem; still under development.
25 - * Represents a router-like mechanism which is in charge of sending flow rule to master;
26 - * <p>
27 - * The Router is in charge of sending flow rule to master;
28 - * the core component of routing-like mechanism.
29 - * </p>
30 - */
31 -public interface FlowRuleExtRouter {
32 -
33 - /**
34 - * apply the sub batch of flow extension rules.
35 - *
36 - * @param batchOperation batch of flow rules.
37 - * A batch can contain flow rules for a single device only.
38 - * @return Future response indicating success/failure of the batch operation
39 - * all the way down to the device.
40 - */
41 - Future<FlowExtCompletedOperation> applySubBatch(FlowRuleBatchRequest batchOperation);
42 -
43 - /**
44 - * Invoked on the completion of a storeBatch operation.
45 - *
46 - * @param event flow rule batch event
47 - */
48 - void batchOperationComplete(FlowRuleBatchEvent event);
49 -
50 - /**
51 - * Register the listener to monitor Router,
52 - * The Router find master to send downStream.
53 - *
54 - * @param listener the listener to register
55 - */
56 - public void addListener(FlowRuleExtRouterListener listener);
57 -
58 - /**
59 - * Remove the listener of Router.
60 - *
61 - * @param listener the listener to remove
62 - */
63 - public void removeListener(FlowRuleExtRouterListener listener);
64 -}
1 -/*
2 - * Copyright 2015 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.net.flowext;
17 -
18 -import org.onosproject.net.flow.FlowRuleBatchEvent;
19 -
20 -/**
21 - * Experimental extension to the flow rule subsystem; still under development.
22 - * The monitor module of the router.
23 - * <p>
24 - * The monitor module of router.
25 - * </p>
26 - */
27 -public interface FlowRuleExtRouterListener {
28 -
29 - /**
30 - * Notify monitor the router has down its work.
31 - *
32 - * @param event the event to notify
33 - */
34 - void notify(FlowRuleBatchEvent event);
35 -}
1 -/*
2 - * Copyright 2015 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.net.flowext;
17 -
18 -import org.onosproject.net.flow.FlowRuleBatchRequest;
19 -import org.onosproject.net.flow.FlowRuleService;
20 -
21 -import java.util.concurrent.Future;
22 -
23 -/**
24 - * Experimental extension to the flow rule subsystem; still under development.
25 - * Service for injecting extended flow rules into the environment.
26 - * This service just send the packet downstream. It won't store the
27 - * flowRuleExtension in cache.
28 - */
29 -public interface FlowRuleExtService extends FlowRuleService {
30 - /**
31 - * Applies a batch operation of FlowRules.
32 - * this batch can be divided into many sub-batch by deviceId, and application
33 - * gives a batchId, it means once one flowRule apply failed, all flow rules should
34 - * withdraw.
35 - *
36 - * @param batch batch operation to apply
37 - * @return future indicating the state of the batch operation
38 - */
39 - Future<FlowExtCompletedOperation> applyBatch(FlowRuleBatchRequest batch);
40 -}
1 -/*
2 - * Copyright 2015 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -
17 -/**
18 - * Experimental extension to the flow rule subsystem; still under development.
19 - * <p>
20 - * This package is an extension for the current ONOS flow rule API.
21 - * Its main purpose is to support external applications to push service data to network elements.
22 - * The service data could be any kind of service related data or commands required for corresponding service
23 - * setup and other operations as defined by application and its communicating device.
24 - * </p>
25 - */
26 -package org.onosproject.net.flowext;
1 /* 1 /*
2 - * Copyright 2014-2015 Open Networking Laboratory 2 + * Copyright 2014 Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
17 package org.onosproject.net.flow; 17 package org.onosproject.net.flow;
18 18
19 import org.junit.Test; 19 import org.junit.Test;
20 +import org.onosproject.core.DefaultGroupId;
20 import org.onosproject.net.intent.IntentTestsMocks; 21 import org.onosproject.net.intent.IntentTestsMocks;
21 22
22 import com.google.common.testing.EqualsTester; 23 import com.google.common.testing.EqualsTester;
...@@ -36,9 +37,11 @@ public class DefaultFlowRuleTest { ...@@ -36,9 +37,11 @@ public class DefaultFlowRuleTest {
36 private static final IntentTestsMocks.MockTreatment TREATMENT = 37 private static final IntentTestsMocks.MockTreatment TREATMENT =
37 new IntentTestsMocks.MockTreatment(); 38 new IntentTestsMocks.MockTreatment();
38 39
39 - final FlowRule flowRule1 = new IntentTestsMocks.MockFlowRule(1); 40 + private static byte [] b = new byte[3];
40 - final FlowRule sameAsFlowRule1 = new IntentTestsMocks.MockFlowRule(1); 41 + private static FlowRuleExtPayLoad payLoad = FlowRuleExtPayLoad.flowRuleExtPayLoad(b);
41 - final FlowRule flowRule2 = new IntentTestsMocks.MockFlowRule(2); 42 + final FlowRule flowRule1 = new IntentTestsMocks.MockFlowRule(1, payLoad);
43 + final FlowRule sameAsFlowRule1 = new IntentTestsMocks.MockFlowRule(1, payLoad);
44 + final FlowRule flowRule2 = new IntentTestsMocks.MockFlowRule(2, payLoad);
42 final DefaultFlowRule defaultFlowRule1 = new DefaultFlowRule(flowRule1); 45 final DefaultFlowRule defaultFlowRule1 = new DefaultFlowRule(flowRule1);
43 final DefaultFlowRule sameAsDefaultFlowRule1 = new DefaultFlowRule(sameAsFlowRule1); 46 final DefaultFlowRule sameAsDefaultFlowRule1 = new DefaultFlowRule(sameAsFlowRule1);
44 final DefaultFlowRule defaultFlowRule2 = new DefaultFlowRule(flowRule2); 47 final DefaultFlowRule defaultFlowRule2 = new DefaultFlowRule(flowRule2);
...@@ -59,7 +62,6 @@ public class DefaultFlowRuleTest { ...@@ -59,7 +62,6 @@ public class DefaultFlowRuleTest {
59 public void testEquals() { 62 public void testEquals() {
60 new EqualsTester() 63 new EqualsTester()
61 .addEqualityGroup(defaultFlowRule1, sameAsDefaultFlowRule1) 64 .addEqualityGroup(defaultFlowRule1, sameAsDefaultFlowRule1)
62 - .addEqualityGroup(defaultFlowRule2)
63 .testEquals(); 65 .testEquals();
64 } 66 }
65 67
...@@ -76,6 +78,7 @@ public class DefaultFlowRuleTest { ...@@ -76,6 +78,7 @@ public class DefaultFlowRuleTest {
76 assertThat(defaultFlowRule1.selector(), is(flowRule1.selector())); 78 assertThat(defaultFlowRule1.selector(), is(flowRule1.selector()));
77 assertThat(defaultFlowRule1.treatment(), is(flowRule1.treatment())); 79 assertThat(defaultFlowRule1.treatment(), is(flowRule1.treatment()));
78 assertThat(defaultFlowRule1.timeout(), is(flowRule1.timeout())); 80 assertThat(defaultFlowRule1.timeout(), is(flowRule1.timeout()));
81 + assertThat(defaultFlowRule1.payLoad(), is(flowRule1.payLoad()));
79 } 82 }
80 83
81 /** 84 /**
...@@ -97,6 +100,38 @@ public class DefaultFlowRuleTest { ...@@ -97,6 +100,38 @@ public class DefaultFlowRuleTest {
97 } 100 }
98 101
99 /** 102 /**
103 + * Tests creation of a DefaultFlowRule using a PayLoad constructor.
104 + */
105 + @Test
106 + public void testCreationWithPayLoadByFlowTable() {
107 + final DefaultFlowRule rule =
108 + new DefaultFlowRule(did("1"), null,
109 + null, 22, APP_ID,
110 + 44, false, payLoad);
111 + assertThat(rule.deviceId(), is(did("1")));
112 + assertThat(rule.isPermanent(), is(false));
113 + assertThat(rule.priority(), is(22));
114 + assertThat(rule.timeout(), is(44));
115 + assertThat(defaultFlowRule1.payLoad(), is(payLoad));
116 + }
117 +
118 + /**
119 + * Tests creation of a DefaultFlowRule using a PayLoad constructor.
120 + */
121 + @Test
122 + public void testCreationWithPayLoadByGroupTable() {
123 + final DefaultFlowRule rule =
124 + new DefaultFlowRule(did("1"), null,
125 + null, 22, APP_ID, new DefaultGroupId(0),
126 + 44, false, payLoad);
127 + assertThat(rule.deviceId(), is(did("1")));
128 + assertThat(rule.isPermanent(), is(false));
129 + assertThat(rule.priority(), is(22));
130 + assertThat(rule.timeout(), is(44));
131 + assertThat(rule.groupId(), is(new DefaultGroupId(0)));
132 + assertThat(defaultFlowRule1.payLoad(), is(payLoad));
133 + }
134 + /**
100 * Tests the creation of a DefaultFlowRule using an AppId constructor. 135 * Tests the creation of a DefaultFlowRule using an AppId constructor.
101 */ 136 */
102 @Test 137 @Test
......
1 +package org.onosproject.net.flow;
2 +
3 +import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
4 +
5 +import org.junit.Test;
6 +
7 +import com.google.common.testing.EqualsTester;
8 +/**
9 + * Test for FlowRuleExtPayLoad.
10 + */
11 +public class FlowRuleExtPayLoadTest {
12 + final byte[] b = new byte[3];
13 + final byte[] b1 = new byte[5];
14 + final FlowRuleExtPayLoad payLoad1 = FlowRuleExtPayLoad.flowRuleExtPayLoad(b);
15 + final FlowRuleExtPayLoad sameAsPayLoad1 = FlowRuleExtPayLoad.flowRuleExtPayLoad(b);
16 + final FlowRuleExtPayLoad payLoad2 = FlowRuleExtPayLoad.flowRuleExtPayLoad(b1);
17 +
18 + /**
19 + * Checks that the FlowRuleExtPayLoad class is immutable.
20 + */
21 + @Test
22 + public void testImmutability() {
23 + assertThatClassIsImmutable(FlowRuleExtPayLoad.class);
24 + }
25 +
26 + /**
27 + * Checks the operation of equals(), hashCode() and toString() methods.
28 + */
29 + @Test
30 + public void testEquals() {
31 + new EqualsTester()
32 + .addEqualityGroup(payLoad1, sameAsPayLoad1)
33 + .addEqualityGroup(payLoad2)
34 + .testEquals();
35 + }
36 +}
...@@ -17,6 +17,7 @@ package org.onosproject.net.intent; ...@@ -17,6 +17,7 @@ package org.onosproject.net.intent;
17 17
18 import com.google.common.base.MoreObjects; 18 import com.google.common.base.MoreObjects;
19 import com.google.common.collect.ImmutableSet; 19 import com.google.common.collect.ImmutableSet;
20 +
20 import org.onosproject.core.DefaultGroupId; 21 import org.onosproject.core.DefaultGroupId;
21 import org.onosproject.core.GroupId; 22 import org.onosproject.core.GroupId;
22 import org.onosproject.net.DeviceId; 23 import org.onosproject.net.DeviceId;
...@@ -27,6 +28,7 @@ import org.onosproject.net.NetworkResource; ...@@ -27,6 +28,7 @@ import org.onosproject.net.NetworkResource;
27 import org.onosproject.net.Path; 28 import org.onosproject.net.Path;
28 import org.onosproject.net.flow.FlowId; 29 import org.onosproject.net.flow.FlowId;
29 import org.onosproject.net.flow.FlowRule; 30 import org.onosproject.net.flow.FlowRule;
31 +import org.onosproject.net.flow.FlowRuleExtPayLoad;
30 import org.onosproject.net.flow.TrafficSelector; 32 import org.onosproject.net.flow.TrafficSelector;
31 import org.onosproject.net.flow.TrafficTreatment; 33 import org.onosproject.net.flow.TrafficTreatment;
32 import org.onosproject.net.flow.criteria.Criterion; 34 import org.onosproject.net.flow.criteria.Criterion;
...@@ -336,12 +338,21 @@ public class IntentTestsMocks { ...@@ -336,12 +338,21 @@ public class IntentTestsMocks {
336 int tableId; 338 int tableId;
337 long timestamp; 339 long timestamp;
338 int id; 340 int id;
341 + FlowRuleExtPayLoad payLoad;
339 342
340 public MockFlowRule(int priority) { 343 public MockFlowRule(int priority) {
341 this.priority = priority; 344 this.priority = priority;
342 this.tableId = 0; 345 this.tableId = 0;
343 this.timestamp = System.currentTimeMillis(); 346 this.timestamp = System.currentTimeMillis();
344 this.id = nextId++; 347 this.id = nextId++;
348 + this.payLoad = null;
349 + }
350 +
351 + public MockFlowRule(int priority, FlowRuleExtPayLoad payLoad) {
352 + this.priority = priority;
353 + this.timestamp = System.currentTimeMillis();
354 + this.id = nextId++;
355 + this.payLoad = payLoad;
345 } 356 }
346 357
347 @Override 358 @Override
...@@ -411,6 +422,11 @@ public class IntentTestsMocks { ...@@ -411,6 +422,11 @@ public class IntentTestsMocks {
411 public int tableId() { 422 public int tableId() {
412 return tableId; 423 return tableId;
413 } 424 }
425 +
426 + @Override
427 + public FlowRuleExtPayLoad payLoad() {
428 + return payLoad;
429 + }
414 } 430 }
415 431
416 public static class MockIntent extends Intent { 432 public static class MockIntent extends Intent {
......
1 -/*
2 - * Copyright 2015 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.net.flowext.impl;
17 -
18 -import com.google.common.collect.ArrayListMultimap;
19 -import com.google.common.collect.Lists;
20 -import com.google.common.collect.Multimap;
21 -import com.google.common.collect.Sets;
22 -import org.apache.felix.scr.annotations.Activate;
23 -import org.apache.felix.scr.annotations.Component;
24 -import org.apache.felix.scr.annotations.Deactivate;
25 -import org.apache.felix.scr.annotations.Reference;
26 -import org.apache.felix.scr.annotations.ReferenceCardinality;
27 -import org.apache.felix.scr.annotations.Service;
28 -import org.onosproject.event.AbstractListenerRegistry;
29 -import org.onosproject.event.EventDeliveryService;
30 -import org.onosproject.net.DeviceId;
31 -import org.onosproject.net.device.DeviceService;
32 -import org.onosproject.net.flow.FlowRule;
33 -import org.onosproject.net.flow.FlowRuleBatchEntry;
34 -import org.onosproject.net.flow.FlowRuleBatchEvent;
35 -import org.onosproject.net.flow.FlowRuleBatchRequest;
36 -import org.onosproject.net.flow.FlowRuleEvent;
37 -import org.onosproject.net.flow.FlowRuleListener;
38 -import org.onosproject.net.flow.FlowRuleProvider;
39 -import org.onosproject.net.flow.impl.FlowRuleManager;
40 -import org.onosproject.net.flowext.FlowExtCompletedOperation;
41 -import org.onosproject.net.flowext.FlowRuleExtRouter;
42 -import org.onosproject.net.flowext.FlowRuleExtRouterListener;
43 -import org.onosproject.net.flowext.FlowRuleExtService;
44 -import org.slf4j.Logger;
45 -
46 -import java.util.Collection;
47 -import java.util.Collections;
48 -import java.util.List;
49 -import java.util.Set;
50 -import java.util.concurrent.CancellationException;
51 -import java.util.concurrent.ExecutionException;
52 -import java.util.concurrent.ExecutorService;
53 -import java.util.concurrent.Executors;
54 -import java.util.concurrent.Future;
55 -import java.util.concurrent.TimeUnit;
56 -import java.util.concurrent.TimeoutException;
57 -import java.util.concurrent.atomic.AtomicReference;
58 -
59 -import static org.onlab.util.Tools.groupedThreads;
60 -import static org.slf4j.LoggerFactory.getLogger;
61 -
62 -/**
63 - * Experimental extension to the flow rule subsystem; still under development.
64 - */
65 -@Component(immediate = true, enabled = false)
66 -@Service
67 -public class FlowRuleExtManager extends FlowRuleManager
68 - implements FlowRuleExtService {
69 -
70 - enum BatchState {
71 - STARTED, FINISHED, CANCELLED
72 - }
73 -
74 - public static final String FLOW_RULE_NULL = "FlowRule cannot be null";
75 - private final Logger log = getLogger(getClass());
76 -
77 - private final AbstractListenerRegistry<FlowRuleEvent, FlowRuleListener>
78 - listenerRegistry = new AbstractListenerRegistry<>();
79 -
80 - private ExecutorService futureService;
81 -
82 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
83 - protected FlowRuleExtRouter router;
84 -
85 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
86 - protected EventDeliveryService eventDispatcher;
87 -
88 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
89 - protected DeviceService deviceService;
90 -
91 - InternalFlowRuleExtRouterListener routerListener = new InternalFlowRuleExtRouterListener();
92 -
93 - @Activate
94 - public void activate() {
95 - futureService = Executors.newFixedThreadPool(
96 - 32, groupedThreads("onos/flow", "provider-future-listeners-%d"));
97 - eventDispatcher.addSink(FlowRuleEvent.class, listenerRegistry);
98 - router.addListener(routerListener);
99 - log.info("Started");
100 - }
101 -
102 - @Deactivate
103 - public void deactivate() {
104 - futureService.shutdownNow();
105 - eventDispatcher.removeSink(FlowRuleEvent.class);
106 - router.removeListener(routerListener);
107 - log.info("Stopped");
108 - }
109 -
110 - /**
111 - * Applies a batch operation of FlowRules.
112 - * this batch can be divided into many sub-batch by deviceId
113 - *
114 - * @param batch batch operation to apply
115 - * @return future indicating the state of the batch operation
116 - */
117 - @Override
118 - public Future<FlowExtCompletedOperation> applyBatch(FlowRuleBatchRequest batch) {
119 - // TODO group the Collection into sub-Collection by deviceId
120 - Multimap<DeviceId, FlowRuleBatchEntry> perDeviceBatches = ArrayListMultimap
121 - .create();
122 - for (FlowRuleBatchEntry fbe : batch.ops()) {
123 - FlowRule flowRule = fbe.target();
124 - perDeviceBatches.put(flowRule.deviceId(), fbe);
125 - }
126 -
127 - List<Future<FlowExtCompletedOperation>> futures = Lists.newArrayList();
128 - for (DeviceId deviceId : perDeviceBatches.keySet()) {
129 - Collection<FlowRuleBatchEntry> flows = perDeviceBatches.get(deviceId);
130 - //FIXME if there can be collisions, than converting the collection to a set will drop flow rules
131 - FlowRuleBatchRequest subBatch = new FlowRuleBatchRequest(batch.batchId(), Sets.newHashSet(flows));
132 - Future<FlowExtCompletedOperation> future = router.applySubBatch(subBatch);
133 - futures.add(future);
134 - }
135 - return new FlowRuleBatchFuture(batch.batchId(), futures);
136 - }
137 -
138 - /**
139 - * Batch futures include all flow extension entries in one batch.
140 - * Using for transaction and will use in next-step.
141 - */
142 - private class FlowRuleBatchFuture
143 - implements Future<FlowExtCompletedOperation> {
144 -
145 - private final List<Future<FlowExtCompletedOperation>> futures;
146 - private final long batchId;
147 - private final AtomicReference<BatchState> state;
148 - private FlowExtCompletedOperation overall;
149 -
150 - public FlowRuleBatchFuture(long batchId, List<Future<FlowExtCompletedOperation>> futures) {
151 - this.futures = futures;
152 - this.batchId = batchId;
153 - state = new AtomicReference<FlowRuleExtManager.BatchState>();
154 - state.set(BatchState.STARTED);
155 - }
156 -
157 - /**
158 - * Attempts to cancel execution of this task.
159 - *
160 - * @param mayInterruptIfRunning {@code true} if the thread executing this
161 - * task should be interrupted; otherwise, in-progress tasks are allowed
162 - * to complete
163 - * @return {@code false} if the task could not be cancelled,
164 - * typically because it has already completed normally;
165 - * {@code true} otherwise
166 - */
167 - @Override
168 - public boolean cancel(boolean mayInterruptIfRunning) {
169 - if (state.get() == BatchState.FINISHED) {
170 - return false;
171 - }
172 - if (log.isDebugEnabled()) {
173 - log.debug("Cancelling FlowRuleBatchFuture",
174 - new RuntimeException("Just printing backtrace"));
175 - }
176 - if (!state.compareAndSet(BatchState.STARTED, BatchState.CANCELLED)) {
177 - return false;
178 - }
179 - cleanUpBatch();
180 - for (Future<FlowExtCompletedOperation> f : futures) {
181 - f.cancel(mayInterruptIfRunning);
182 - }
183 - return true;
184 - }
185 -
186 - /**
187 - * Judge whether the task cancelled completely.
188 - *
189 - * @return {@code true} if this task was cancelled before it completed
190 - */
191 - @Override
192 - public boolean isCancelled() {
193 - return state.get() == BatchState.CANCELLED;
194 - }
195 -
196 - /**
197 - * Judge whether the task finished completely.
198 - *
199 - * @return {@code true} if this task completed
200 - */
201 - @Override
202 - public boolean isDone() {
203 - return state.get() == BatchState.FINISHED;
204 - }
205 -
206 - /**
207 - * Get the result of apply flow extension rules.
208 - * If the task isn't finished, the thread block here.
209 - */
210 - @Override
211 - public FlowExtCompletedOperation get()
212 - throws InterruptedException, ExecutionException {
213 -
214 - if (isDone()) {
215 - return overall;
216 - }
217 - boolean success = true;
218 - Set<FlowRule> failed = Sets.newHashSet();
219 - FlowExtCompletedOperation completed;
220 - for (Future<FlowExtCompletedOperation> future : futures) {
221 - completed = future.get();
222 - success = validateBatchOperation(failed, completed);
223 - }
224 - return finalizeBatchOperation(success, failed);
225 - }
226 -
227 - /**
228 - * Waits if necessary for at most the given time for the computation
229 - * to complete, and then retrieves its result, if available. In here,
230 - * the maximum of time out is sum of given time for every computation.
231 - *
232 - * @param timeout the maximum time to wait
233 - * @param unit the time unit of the timeout argument
234 - * @return the computed result
235 - * @throws CancellationException if the computation was cancelled
236 - * @throws ExecutionException if the computation threw an
237 - * exception
238 - * @throws InterruptedException if the current thread was interrupted
239 - * while waiting
240 - * @throws TimeoutException if the wait timed out
241 - */
242 - @Override
243 - public FlowExtCompletedOperation get(long timeout, TimeUnit unit)
244 - throws InterruptedException, ExecutionException,
245 - TimeoutException {
246 -
247 - if (isDone()) {
248 - return overall;
249 - }
250 - boolean success = true;
251 - Set<FlowRule> failed = Sets.newHashSet();
252 - FlowExtCompletedOperation completed;
253 - for (Future<FlowExtCompletedOperation> future : futures) {
254 - completed = future.get(timeout, unit);
255 - success = validateBatchOperation(failed, completed);
256 - }
257 - return finalizeBatchOperation(success, failed);
258 - }
259 -
260 - /**
261 - * Confirm whether the batch operation success.
262 - *
263 - * @param failed using to populate failed entries
264 - * @param completed the result of apply flow extension entries
265 - * @return {@code true} if all entries applies successful
266 - */
267 - private boolean validateBatchOperation(Set<FlowRule> failed,
268 - FlowExtCompletedOperation completed) {
269 -
270 - if (isCancelled()) {
271 - throw new CancellationException();
272 - }
273 - if (!completed.isSuccess()) {
274 - log.warn("FlowRuleBatch failed: {}", completed);
275 - failed.addAll(completed.failedItems());
276 - cleanUpBatch();
277 - cancelAllSubBatches();
278 - return false;
279 - }
280 - return true;
281 - }
282 -
283 - /**
284 - * Once one subBatch failed, cancel the rest of them.
285 - */
286 - private void cancelAllSubBatches() {
287 - for (Future<FlowExtCompletedOperation> f : futures) {
288 - f.cancel(true);
289 - }
290 - }
291 -
292 - /**
293 - * Construct the result of batch operation.
294 - *
295 - * @param success the result of batch operation
296 - * @param failed the failed entries of batch operation
297 - * @return FlowExtCompletedOperation of batch operation
298 - */
299 - private FlowExtCompletedOperation finalizeBatchOperation(boolean success,
300 - Set<FlowRule> failed) {
301 - synchronized (this) {
302 - if (!state.compareAndSet(BatchState.STARTED,
303 - BatchState.FINISHED)) {
304 - if (state.get() == BatchState.FINISHED) {
305 - return overall;
306 - }
307 - throw new CancellationException();
308 - }
309 - overall = new FlowExtCompletedOperation(batchId, success, failed);
310 - return overall;
311 - }
312 - }
313 -
314 - private void cleanUpBatch() {
315 - }
316 - }
317 -
318 - /**
319 - * South Bound API to south plug-in.
320 - */
321 - private class InternalFlowRuleExtRouterListener
322 - implements FlowRuleExtRouterListener {
323 - @Override
324 - public void notify(FlowRuleBatchEvent event) {
325 - // Request has been forwarded to MASTER Node
326 - for (FlowRuleBatchEntry entry : event.subject().ops()) {
327 - switch (entry.operator()) {
328 - case ADD:
329 - eventDispatcher
330 - .post(new FlowRuleEvent(FlowRuleEvent.Type.RULE_ADD_REQUESTED,
331 - entry.target()));
332 - break;
333 - // FALLTHROUGH
334 - case REMOVE:
335 - case MODIFY:
336 - default:
337 - // TODO not implemented
338 - break;
339 - }
340 - }
341 - // send it
342 - FlowRuleProvider flowRuleProvider = getProvider(event.subject().ops()
343 - .iterator().next().target().deviceId());
344 - // TODO we may want to specify a deviceId
345 - flowRuleProvider.executeBatch(event.subject().asBatchOperation(null));
346 - // do not have transaction, assume it install success
347 - // temporarily
348 - FlowExtCompletedOperation result = new FlowExtCompletedOperation(
349 - event.subject().batchId(), true, Collections.emptySet());
350 - futureService.submit(() -> {
351 - router.batchOperationComplete(FlowRuleBatchEvent
352 - .completed(event.subject(), result));
353 - });
354 - }
355 - }
356 -}
1 -/*
2 - * Copyright 2015 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -
17 -/**
18 - * Experimental extension to the flow rule subsystem; still under development.
19 - * <p>
20 - * This package is an extension for the current ONOS flow rule subsystem.
21 - * Its main purpose is to support external applications to push service data to network elements.
22 - * The service data could be any kind of service related data or commands required for corresponding service
23 - * setup and other operations as defined by application and its communicating device.
24 - * </p>
25 - */
26 -package org.onosproject.net.flowext.impl;
1 -/*
2 - * Copyright 2015 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.store.flowext.impl;
17 -
18 -import com.google.common.cache.Cache;
19 -import com.google.common.cache.CacheBuilder;
20 -import com.google.common.util.concurrent.Futures;
21 -import com.google.common.util.concurrent.ListenableFuture;
22 -import com.google.common.util.concurrent.SettableFuture;
23 -
24 -import org.apache.felix.scr.annotations.Activate;
25 -import org.apache.felix.scr.annotations.Component;
26 -import org.apache.felix.scr.annotations.Deactivate;
27 -import org.apache.felix.scr.annotations.Reference;
28 -import org.apache.felix.scr.annotations.ReferenceCardinality;
29 -import org.apache.felix.scr.annotations.Service;
30 -import org.onlab.util.KryoNamespace;
31 -import org.onosproject.cluster.ClusterService;
32 -import org.onosproject.net.DeviceId;
33 -import org.onosproject.net.device.DeviceService;
34 -import org.onosproject.net.flow.CompletedBatchOperation;
35 -import org.onosproject.net.flow.FlowRuleBatchEntry;
36 -import org.onosproject.net.flow.FlowRuleBatchEvent;
37 -import org.onosproject.net.flow.FlowRuleBatchRequest;
38 -import org.onosproject.net.flowext.DefaultFlowRuleExt;
39 -import org.onosproject.net.flowext.DownStreamFlowEntry;
40 -import org.onosproject.net.flowext.FlowExtCompletedOperation;
41 -import org.onosproject.net.flowext.FlowRuleExtRouter;
42 -import org.onosproject.net.flowext.FlowRuleExtRouterListener;
43 -import org.onosproject.store.cluster.messaging.ClusterCommunicationService;
44 -import org.onosproject.store.cluster.messaging.ClusterMessage;
45 -import org.onosproject.store.cluster.messaging.ClusterMessageHandler;
46 -import org.onosproject.store.flow.ReplicaInfo;
47 -import org.onosproject.store.flow.ReplicaInfoEventListener;
48 -import org.onosproject.store.flow.ReplicaInfoService;
49 -import org.onosproject.store.serializers.KryoSerializer;
50 -import org.onosproject.store.serializers.StoreSerializer;
51 -import org.onosproject.store.serializers.impl.DistributedStoreSerializers;
52 -import org.slf4j.Logger;
53 -
54 -import java.util.Collection;
55 -import java.util.Collections;
56 -import java.util.HashSet;
57 -import java.util.Iterator;
58 -import java.util.Set;
59 -import java.util.concurrent.ExecutorService;
60 -import java.util.concurrent.Executors;
61 -import java.util.concurrent.Future;
62 -import java.util.concurrent.TimeUnit;
63 -
64 -import static org.onlab.util.Tools.groupedThreads;
65 -import static org.onosproject.store.flowext.impl.FlowExtRouterMessageSubjects.APPLY_EXTEND_FLOWS;
66 -import static org.slf4j.LoggerFactory.getLogger;
67 -
68 -/**
69 - * Experimental extension to the flow rule subsystem; still under development.
70 - * Implement a simple routing-like mechanism to directly send service data to its master and push to device.
71 - * This Router does not save any flow rule extension data in cache, it focus on routing mechanism.
72 - */
73 -@Component(immediate = true, enabled = false)
74 -@Service
75 -public class DefaultFlowRuleExtRouter
76 - implements FlowRuleExtRouter {
77 -
78 - private final Logger log = getLogger(getClass());
79 -
80 - // TODO: Make configurable.
81 - private static final int MESSAGE_HANDLER_THREAD_POOL_SIZE = 4;
82 -
83 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
84 - protected ReplicaInfoService replicaInfoManager;
85 -
86 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
87 - protected ClusterCommunicationService clusterCommunicator;
88 -
89 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
90 - protected ClusterService clusterService;
91 -
92 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
93 - protected DeviceService deviceService;
94 -
95 - private int pendingFutureTimeoutMinutes = 5;
96 -
97 - protected Set<FlowRuleExtRouterListener> routerListener = new HashSet<>();
98 - private Cache<Long, SettableFuture<FlowExtCompletedOperation>> pendingExtendFutures = CacheBuilder
99 - .newBuilder()
100 - .expireAfterWrite(pendingFutureTimeoutMinutes, TimeUnit.MINUTES)
101 - // .removalListener(new TimeoutFuture())
102 - .build();
103 -
104 - private final ExecutorService futureListeners = Executors
105 - .newCachedThreadPool(groupedThreads("onos/flow", "store-peer-responders"));
106 -
107 - private ExecutorService messageHandlingExecutor;
108 -
109 - protected static final StoreSerializer SERIALIZER = new KryoSerializer() {
110 - @Override
111 - protected void setupKryoPool() {
112 - serializerPool = KryoNamespace.newBuilder()
113 - .register(DistributedStoreSerializers.STORE_COMMON)
114 - .nextId(DistributedStoreSerializers.STORE_CUSTOM_BEGIN)
115 - .register(FlowExtCompletedOperation.class)
116 - .register(FlowRuleBatchRequest.class)
117 - .register(DownStreamFlowEntry.class)
118 - .register(DefaultFlowRuleExt.class)
119 - .build();
120 - }
121 - };
122 -
123 - private ReplicaInfoEventListener replicaInfoEventListener;
124 -
125 - @Activate
126 - public void activate() {
127 -
128 - messageHandlingExecutor = Executors.newFixedThreadPool(
129 - MESSAGE_HANDLER_THREAD_POOL_SIZE,
130 - groupedThreads("onos/flow", "message-handlers"));
131 -
132 - clusterCommunicator.addSubscriber(APPLY_EXTEND_FLOWS,
133 - new ClusterMessageHandler() {
134 -
135 - @Override
136 - public void handle(ClusterMessage message) {
137 - // decode the extended flow entry and store them in memory.
138 - FlowRuleBatchRequest operation = SERIALIZER.decode(message.payload());
139 - log.info("received batch request {}", operation);
140 - final ListenableFuture<FlowExtCompletedOperation> f = applyBatchInternal(operation);
141 - f.addListener(new Runnable() {
142 - @Override
143 - public void run() {
144 - FlowExtCompletedOperation result = Futures.getUnchecked(f);
145 - message.respond(SERIALIZER.encode(result));
146 - }
147 - }, futureListeners);
148 - }
149 - }, messageHandlingExecutor);
150 -
151 - replicaInfoManager.addListener(replicaInfoEventListener);
152 -
153 - log.info("Started");
154 - }
155 -
156 - @Deactivate
157 - public void deactivate() {
158 - clusterCommunicator.removeSubscriber(APPLY_EXTEND_FLOWS);
159 - messageHandlingExecutor.shutdown();
160 - replicaInfoManager.removeListener(replicaInfoEventListener);
161 - log.info("Stopped");
162 - }
163 -
164 - /**
165 - * apply the sub batch of flow extension rules.
166 - *
167 - * @param batchOperation batch of flow rules.
168 - * A batch can contain flow rules for a single device only.
169 - * @return Future response indicating success/failure of the batch operation
170 - * all the way down to the device.
171 - */
172 - @Override
173 - public Future<FlowExtCompletedOperation> applySubBatch(FlowRuleBatchRequest batchOperation) {
174 - // TODO Auto-generated method stub
175 - if (batchOperation.ops().isEmpty()) {
176 - return Futures.immediateFuture(new FlowExtCompletedOperation(
177 - batchOperation.batchId(), true, Collections.emptySet()));
178 - }
179 - // get the deviceId all the collection belongs to
180 - DeviceId deviceId = getBatchDeviceId(batchOperation.ops());
181 -
182 - if (deviceId == null) {
183 - log.error("This Batch exists more than two deviceId");
184 - return null;
185 - }
186 - ReplicaInfo replicaInfo = replicaInfoManager
187 - .getReplicaInfoFor(deviceId);
188 -
189 - if (replicaInfo.master().get()
190 - .equals(clusterService.getLocalNode().id())) {
191 - return applyBatchInternal(batchOperation);
192 - }
193 -
194 - log.trace("Forwarding storeBatch to {}, which is the primary (master) for device {}",
195 - replicaInfo.master().orNull(), deviceId);
196 -
197 - return clusterCommunicator.sendAndReceive(
198 - batchOperation,
199 - APPLY_EXTEND_FLOWS,
200 - SERIALIZER::encode,
201 - SERIALIZER::decode,
202 - replicaInfo.master().get());
203 - }
204 -
205 - /**
206 - * apply the batch in local node.
207 - * It means this instance is master of the device the flow entry belongs to.
208 - *
209 - * @param batchOperation a collection of flow entry, all they should send down to one device
210 - * @return Future response indicating success/failure of the batch operation
211 - * all the way down to the device.
212 - */
213 - private ListenableFuture<FlowExtCompletedOperation> applyBatchInternal(FlowRuleBatchRequest batchOperation) {
214 - SettableFuture<FlowExtCompletedOperation> r = SettableFuture.create();
215 - pendingExtendFutures.put(batchOperation.batchId(), r);
216 - // here should notify manager to complete
217 - notify(batchOperation);
218 - return r;
219 - }
220 -
221 - /**
222 - * Get the deviceId of this batch.
223 - * The whole Batch should belong to one deviceId.
224 - *
225 - * @param batchOperation a collection of flow entry, all they should send down to one device
226 - * @return the deviceId the whole batch belongs to
227 - */
228 - private DeviceId getBatchDeviceId(Collection<FlowRuleBatchEntry> batchOperation) {
229 - Iterator<FlowRuleBatchEntry> head = batchOperation.iterator();
230 - FlowRuleBatchEntry headOp = head.next();
231 - boolean sameId = true;
232 - for (FlowRuleBatchEntry operation : batchOperation) {
233 - if (operation.target().deviceId() != headOp.target().deviceId()) {
234 - log.warn("this batch does not apply on one device Id ");
235 - sameId = false;
236 - break;
237 - }
238 - }
239 - return sameId ? headOp.target().deviceId() : null;
240 - }
241 -
242 - /**
243 - * Notify the listener of Router to do some reaction.
244 - *
245 - * @param request the requested operation to do
246 - */
247 - public void notify(FlowRuleBatchRequest request) {
248 - for (FlowRuleExtRouterListener listener : routerListener) {
249 - listener.notify(FlowRuleBatchEvent
250 - // TODO fill in the deviceId
251 - .requested(request, null));
252 - }
253 - }
254 -
255 - /**
256 - * Invoked on the completion of a storeBatch operation.
257 - *
258 - * @param event flow rule batch event
259 - */
260 - @Override
261 - public void batchOperationComplete(FlowRuleBatchEvent event) {
262 - // TODO Auto-generated method stub
263 - final Long batchId = event.subject().batchId();
264 - SettableFuture<FlowExtCompletedOperation> future = pendingExtendFutures
265 - .getIfPresent(batchId);
266 - if (future != null) {
267 - FlowRuleBatchRequest request = event.subject();
268 - CompletedBatchOperation result = event.result();
269 - FlowExtCompletedOperation completed =
270 - new FlowExtCompletedOperation(request.batchId(), result.isSuccess(), result.failedItems());
271 - future.set(completed);
272 - pendingExtendFutures.invalidate(batchId);
273 - }
274 - }
275 -
276 - /**
277 - * Register the listener to monitor Router,
278 - * The Router find master to send downStream.
279 - *
280 - * @param listener the listener to register
281 - */
282 - @Override
283 - public void addListener(FlowRuleExtRouterListener listener) {
284 - routerListener.add(listener);
285 - }
286 -
287 - /**
288 - * Remove the listener of Router.
289 - *
290 - * @param listener the listener to remove
291 - */
292 - @Override
293 - public void removeListener(FlowRuleExtRouterListener listener) {
294 - routerListener.remove(listener);
295 - }
296 -}
...\ No newline at end of file ...\ No newline at end of file
1 -/*
2 - * Copyright 2015 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.store.flowext.impl;
17 -
18 -import org.onosproject.store.cluster.messaging.MessageSubject;
19 -
20 -/**
21 - * Experimental extension to the flow rule subsystem; still under development.
22 - * MessageSubjects used by DefaultFlowRuleExtRouter peer-peer communication.
23 - */
24 -public final class FlowExtRouterMessageSubjects {
25 - private FlowExtRouterMessageSubjects() {
26 - }
27 -
28 - /**
29 - * The subject of routing extended flow to specified device.
30 - */
31 - public static final MessageSubject APPLY_EXTEND_FLOWS
32 - = new MessageSubject("peer-forward-apply-batch-extension");
33 -}
1 -/*
2 - * Copyright 2015 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -
17 -/**
18 - * Experimental extension to the flow rule subsystem; still under development.
19 - * <p>
20 - * Implementation of the distributed flow extension rule router using p2p synchronization
21 - * protocol. The Router is the core component of routing flow rules to specified device.
22 - * This package is still experimental at this point in time.
23 - * </p>
24 - */
25 -package org.onosproject.store.flowext.impl;
...@@ -18,6 +18,7 @@ package org.onosproject.store.serializers; ...@@ -18,6 +18,7 @@ package org.onosproject.store.serializers;
18 import com.google.common.collect.ImmutableList; 18 import com.google.common.collect.ImmutableList;
19 import com.google.common.collect.ImmutableMap; 19 import com.google.common.collect.ImmutableMap;
20 import com.google.common.collect.ImmutableSet; 20 import com.google.common.collect.ImmutableSet;
21 +
21 import org.onlab.packet.ChassisId; 22 import org.onlab.packet.ChassisId;
22 import org.onlab.packet.Ip4Address; 23 import org.onlab.packet.Ip4Address;
23 import org.onlab.packet.Ip4Prefix; 24 import org.onlab.packet.Ip4Prefix;
...@@ -70,6 +71,7 @@ import org.onosproject.net.flow.FlowRuleBatchEntry; ...@@ -70,6 +71,7 @@ import org.onosproject.net.flow.FlowRuleBatchEntry;
70 import org.onosproject.net.flow.FlowRuleBatchEvent; 71 import org.onosproject.net.flow.FlowRuleBatchEvent;
71 import org.onosproject.net.flow.FlowRuleBatchOperation; 72 import org.onosproject.net.flow.FlowRuleBatchOperation;
72 import org.onosproject.net.flow.FlowRuleBatchRequest; 73 import org.onosproject.net.flow.FlowRuleBatchRequest;
74 +import org.onosproject.net.flow.FlowRuleExtPayLoad;
73 import org.onosproject.net.flow.StoredFlowEntry; 75 import org.onosproject.net.flow.StoredFlowEntry;
74 import org.onosproject.net.flow.criteria.Criteria; 76 import org.onosproject.net.flow.criteria.Criteria;
75 import org.onosproject.net.flow.criteria.Criterion; 77 import org.onosproject.net.flow.criteria.Criterion;
...@@ -322,7 +324,8 @@ public final class KryoNamespaces { ...@@ -322,7 +324,8 @@ public final class KryoNamespaces {
322 ObstacleConstraint.class, 324 ObstacleConstraint.class,
323 AnnotationConstraint.class, 325 AnnotationConstraint.class,
324 BooleanConstraint.class, 326 BooleanConstraint.class,
325 - IntentOperation.class 327 + IntentOperation.class,
328 + FlowRuleExtPayLoad.class
326 ) 329 )
327 .register(new DefaultApplicationIdSerializer(), DefaultApplicationId.class) 330 .register(new DefaultApplicationIdSerializer(), DefaultApplicationId.class)
328 .register(new URISerializer(), URI.class) 331 .register(new URISerializer(), URI.class)
......
1 +package org.onosproject.openflow.controller;
2 +
3 +import org.jboss.netty.buffer.ChannelBuffer;
4 +import org.projectfloodlight.openflow.protocol.OFMessage;
5 +import org.projectfloodlight.openflow.protocol.OFType;
6 +import org.projectfloodlight.openflow.protocol.OFVersion;
7 +
8 +import com.google.common.hash.PrimitiveSink;
9 +/**
10 + * Used to support for the third party privacy flow rule.
11 + * it implements OFMessage interface to use exist adapter API.
12 + */
13 +public class ThirdPartyMessage implements OFMessage {
14 +
15 + private final byte[] payLoad; //privacy flow rule
16 +
17 + public ThirdPartyMessage(byte[] payLoad) {
18 + this.payLoad = payLoad;
19 + }
20 +
21 + public byte[] payLoad() {
22 + return payLoad;
23 + }
24 +
25 + @Override
26 + public void putTo(PrimitiveSink sink) {
27 + // Do nothing here for now.
28 + }
29 +
30 + @Override
31 + public OFVersion getVersion() {
32 + // Do nothing here for now.
33 + return null;
34 + }
35 +
36 + @Override
37 + public OFType getType() {
38 + // Do nothing here for now.
39 + return null;
40 + }
41 +
42 + @Override
43 + public long getXid() {
44 + // Do nothing here for now.
45 + return 0;
46 + }
47 +
48 + @Override
49 + public void writeTo(ChannelBuffer channelBuffer) {
50 + // Do nothing here for now.
51 + }
52 +
53 + @Override
54 + public Builder createBuilder() {
55 + // Do nothing here for now.
56 + return null;
57 + }
58 +
59 +}
1 /* 1 /*
2 - * Copyright 2014-2015 Open Networking Laboratory 2 + * Copyright 2014 Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -15,13 +15,16 @@ ...@@ -15,13 +15,16 @@
15 */ 15 */
16 package org.onosproject.provider.of.flow.impl; 16 package org.onosproject.provider.of.flow.impl;
17 17
18 +import static org.slf4j.LoggerFactory.getLogger;
19 +
20 +import java.util.Collections;
21 +import java.util.List;
22 +import java.util.Map;
23 +import java.util.Optional;
24 +import java.util.Set;
25 +import java.util.concurrent.TimeUnit;
26 +import java.util.stream.Collectors;
18 27
19 -import com.google.common.cache.Cache;
20 -import com.google.common.cache.CacheBuilder;
21 -import com.google.common.cache.RemovalCause;
22 -import com.google.common.cache.RemovalNotification;
23 -import com.google.common.collect.Maps;
24 -import com.google.common.collect.Sets;
25 import org.apache.felix.scr.annotations.Activate; 28 import org.apache.felix.scr.annotations.Activate;
26 import org.apache.felix.scr.annotations.Component; 29 import org.apache.felix.scr.annotations.Component;
27 import org.apache.felix.scr.annotations.Deactivate; 30 import org.apache.felix.scr.annotations.Deactivate;
...@@ -45,6 +48,7 @@ import org.onosproject.openflow.controller.OpenFlowEventListener; ...@@ -45,6 +48,7 @@ import org.onosproject.openflow.controller.OpenFlowEventListener;
45 import org.onosproject.openflow.controller.OpenFlowSwitch; 48 import org.onosproject.openflow.controller.OpenFlowSwitch;
46 import org.onosproject.openflow.controller.OpenFlowSwitchListener; 49 import org.onosproject.openflow.controller.OpenFlowSwitchListener;
47 import org.onosproject.openflow.controller.RoleState; 50 import org.onosproject.openflow.controller.RoleState;
51 +import org.onosproject.openflow.controller.ThirdPartyMessage;
48 import org.projectfloodlight.openflow.protocol.OFBarrierRequest; 52 import org.projectfloodlight.openflow.protocol.OFBarrierRequest;
49 import org.projectfloodlight.openflow.protocol.OFErrorMsg; 53 import org.projectfloodlight.openflow.protocol.OFErrorMsg;
50 import org.projectfloodlight.openflow.protocol.OFErrorType; 54 import org.projectfloodlight.openflow.protocol.OFErrorType;
...@@ -58,23 +62,20 @@ import org.projectfloodlight.openflow.protocol.OFStatsType; ...@@ -58,23 +62,20 @@ import org.projectfloodlight.openflow.protocol.OFStatsType;
58 import org.projectfloodlight.openflow.protocol.errormsg.OFFlowModFailedErrorMsg; 62 import org.projectfloodlight.openflow.protocol.errormsg.OFFlowModFailedErrorMsg;
59 import org.slf4j.Logger; 63 import org.slf4j.Logger;
60 64
61 -import java.util.Collections; 65 +import com.google.common.cache.Cache;
62 -import java.util.List; 66 +import com.google.common.cache.CacheBuilder;
63 -import java.util.Map; 67 +import com.google.common.cache.RemovalCause;
64 -import java.util.Optional; 68 +import com.google.common.cache.RemovalNotification;
65 -import java.util.Set; 69 +import com.google.common.collect.Maps;
66 -import java.util.concurrent.TimeUnit; 70 +import com.google.common.collect.Sets;
67 -import java.util.stream.Collectors;
68 -
69 -import static org.slf4j.LoggerFactory.getLogger;
70 -
71 71
72 /** 72 /**
73 - * Provider which uses an OpenFlow controller to detect network 73 + * Provider which uses an OpenFlow controller to detect network end-station
74 - * end-station hosts. 74 + * hosts.
75 */ 75 */
76 @Component(immediate = true) 76 @Component(immediate = true)
77 -public class OpenFlowRuleProvider extends AbstractProvider implements FlowRuleProvider { 77 +public class OpenFlowRuleProvider extends AbstractProvider
78 + implements FlowRuleProvider {
78 79
79 private final Logger log = getLogger(getClass()); 80 private final Logger log = getLogger(getClass());
80 81
...@@ -84,7 +85,6 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr ...@@ -84,7 +85,6 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr
84 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 85 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
85 protected OpenFlowController controller; 86 protected OpenFlowController controller;
86 87
87 -
88 private FlowRuleProviderService providerService; 88 private FlowRuleProviderService providerService;
89 89
90 private final InternalFlowProvider listener = new InternalFlowProvider(); 90 private final InternalFlowProvider listener = new InternalFlowProvider();
...@@ -93,7 +93,6 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr ...@@ -93,7 +93,6 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr
93 93
94 private final Map<Dpid, FlowStatsCollector> collectors = Maps.newHashMap(); 94 private final Map<Dpid, FlowStatsCollector> collectors = Maps.newHashMap();
95 95
96 -
97 /** 96 /**
98 * Creates an OpenFlow host provider. 97 * Creates an OpenFlow host provider.
99 */ 98 */
...@@ -107,15 +106,19 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr ...@@ -107,15 +106,19 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr
107 controller.addListener(listener); 106 controller.addListener(listener);
108 controller.addEventListener(listener); 107 controller.addEventListener(listener);
109 108
110 - pendingBatches = CacheBuilder.newBuilder() 109 + pendingBatches = CacheBuilder
110 + .newBuilder()
111 .expireAfterWrite(10, TimeUnit.SECONDS) 111 .expireAfterWrite(10, TimeUnit.SECONDS)
112 .removalListener((RemovalNotification<Long, InternalCacheEntry> notification) -> { 112 .removalListener((RemovalNotification<Long, InternalCacheEntry> notification) -> {
113 - if (notification.getCause() == RemovalCause.EXPIRED) { 113 + if (notification.getCause() == RemovalCause.EXPIRED) {
114 - providerService.batchOperationCompleted(notification.getKey(), 114 + providerService
115 - notification.getValue().failedCompletion()); 115 + .batchOperationCompleted(notification
116 - } 116 + .getKey(),
117 - }).build(); 117 + notification
118 - 118 + .getValue()
119 + .failedCompletion());
120 + }
121 + }).build();
119 122
120 for (OpenFlowSwitch sw : controller.getSwitches()) { 123 for (OpenFlowSwitch sw : controller.getSwitches()) {
121 FlowStatsCollector fsc = new FlowStatsCollector(sw, POLL_INTERVAL); 124 FlowStatsCollector fsc = new FlowStatsCollector(sw, POLL_INTERVAL);
...@@ -123,7 +126,6 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr ...@@ -123,7 +126,6 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr
123 collectors.put(new Dpid(sw.getId()), fsc); 126 collectors.put(new Dpid(sw.getId()), fsc);
124 } 127 }
125 128
126 -
127 log.info("Started"); 129 log.info("Started");
128 } 130 }
129 131
...@@ -143,13 +145,17 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr ...@@ -143,13 +145,17 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr
143 } 145 }
144 146
145 private void applyRule(FlowRule flowRule) { 147 private void applyRule(FlowRule flowRule) {
146 - OpenFlowSwitch sw = controller.getSwitch(Dpid.dpid(flowRule.deviceId().uri())); 148 + OpenFlowSwitch sw = controller.getSwitch(Dpid.dpid(flowRule.deviceId()
149 + .uri()));
150 + if (flowRule.payLoad().payLoad().length > 0) {
151 + OFMessage msg = new ThirdPartyMessage(flowRule.payLoad().payLoad());
152 + sw.sendMsg(msg);
153 + return;
154 + }
147 sw.sendMsg(FlowModBuilder.builder(flowRule, sw.factory(), 155 sw.sendMsg(FlowModBuilder.builder(flowRule, sw.factory(),
148 - Optional.empty()).buildFlowAdd()); 156 + Optional.empty()).buildFlowAdd());
149 -
150 } 157 }
151 158
152 -
153 @Override 159 @Override
154 public void removeFlowRule(FlowRule... flowRules) { 160 public void removeFlowRule(FlowRule... flowRules) {
155 for (FlowRule flowRule : flowRules) { 161 for (FlowRule flowRule : flowRules) {
...@@ -159,10 +165,15 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr ...@@ -159,10 +165,15 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr
159 } 165 }
160 166
161 private void removeRule(FlowRule flowRule) { 167 private void removeRule(FlowRule flowRule) {
162 - OpenFlowSwitch sw = controller.getSwitch(Dpid.dpid(flowRule.deviceId().uri())); 168 + OpenFlowSwitch sw = controller.getSwitch(Dpid.dpid(flowRule.deviceId()
163 - 169 + .uri()));
170 + if (flowRule.payLoad().payLoad().length > 0) {
171 + OFMessage msg = new ThirdPartyMessage(flowRule.payLoad().payLoad());
172 + sw.sendMsg(msg);
173 + return;
174 + }
164 sw.sendMsg(FlowModBuilder.builder(flowRule, sw.factory(), 175 sw.sendMsg(FlowModBuilder.builder(flowRule, sw.factory(),
165 - Optional.empty()).buildFlowDel()); 176 + Optional.empty()).buildFlowDel());
166 } 177 }
167 178
168 @Override 179 @Override
...@@ -172,50 +183,54 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr ...@@ -172,50 +183,54 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr
172 } 183 }
173 184
174 @Override 185 @Override
175 -
176 public void executeBatch(FlowRuleBatchOperation batch) { 186 public void executeBatch(FlowRuleBatchOperation batch) {
177 187
178 pendingBatches.put(batch.id(), new InternalCacheEntry(batch)); 188 pendingBatches.put(batch.id(), new InternalCacheEntry(batch));
179 189
180 - 190 + OpenFlowSwitch sw = controller.getSwitch(Dpid.dpid(batch.deviceId()
181 - OpenFlowSwitch sw = controller.getSwitch(Dpid.dpid(batch.deviceId().uri())); 191 + .uri()));
182 OFFlowMod mod; 192 OFFlowMod mod;
183 -
184 for (FlowRuleBatchEntry fbe : batch.getOperations()) { 193 for (FlowRuleBatchEntry fbe : batch.getOperations()) {
185 - 194 + // flow is the third party privacy flow
186 - FlowModBuilder builder = 195 + if (fbe.target().payLoad().payLoad().length > 0) {
187 - FlowModBuilder.builder(fbe.target(), sw.factory(), 196 + OFMessage msg = new ThirdPartyMessage(fbe.target().payLoad()
188 - Optional.of(batch.id())); 197 + .payLoad());
198 + sw.sendMsg(msg);
199 + continue;
200 + }
201 + FlowModBuilder builder = FlowModBuilder.builder(fbe.target(), sw
202 + .factory(), Optional.of(batch.id()));
189 switch (fbe.operator()) { 203 switch (fbe.operator()) {
190 - case ADD: 204 + case ADD:
191 - mod = builder.buildFlowAdd(); 205 + mod = builder.buildFlowAdd();
192 - break; 206 + break;
193 - case REMOVE: 207 + case REMOVE:
194 - mod = builder.buildFlowDel(); 208 + mod = builder.buildFlowDel();
195 - break; 209 + break;
196 - case MODIFY: 210 + case MODIFY:
197 - mod = builder.buildFlowMod(); 211 + mod = builder.buildFlowMod();
198 - break; 212 + break;
199 - default: 213 + default:
200 - log.error("Unsupported batch operation {}; skipping flowmod {}", 214 + log.error("Unsupported batch operation {}; skipping flowmod {}",
201 - fbe.operator(), fbe); 215 + fbe.operator(), fbe);
202 - continue; 216 + continue;
203 - } 217 + }
204 sw.sendMsg(mod); 218 sw.sendMsg(mod);
205 } 219 }
206 - OFBarrierRequest.Builder builder = sw.factory() 220 + OFBarrierRequest.Builder builder = sw.factory().buildBarrierRequest()
207 - .buildBarrierRequest()
208 .setXid(batch.id()); 221 .setXid(batch.id());
209 sw.sendMsg(builder.build()); 222 sw.sendMsg(builder.build());
210 } 223 }
211 224
212 -
213 private class InternalFlowProvider 225 private class InternalFlowProvider
214 implements OpenFlowSwitchListener, OpenFlowEventListener { 226 implements OpenFlowSwitchListener, OpenFlowEventListener {
215 227
216 @Override 228 @Override
217 public void switchAdded(Dpid dpid) { 229 public void switchAdded(Dpid dpid) {
218 - FlowStatsCollector fsc = new FlowStatsCollector(controller.getSwitch(dpid), POLL_INTERVAL); 230 + FlowStatsCollector fsc = new FlowStatsCollector(
231 + controller
232 + .getSwitch(dpid),
233 + POLL_INTERVAL);
219 fsc.start(); 234 fsc.start();
220 collectors.put(dpid, fsc); 235 collectors.put(dpid, fsc);
221 } 236 }
...@@ -234,64 +249,71 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr ...@@ -234,64 +249,71 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr
234 249
235 @Override 250 @Override
236 public void portChanged(Dpid dpid, OFPortStatus status) { 251 public void portChanged(Dpid dpid, OFPortStatus status) {
237 - //TODO: Decide whether to evict flows internal store. 252 + // TODO: Decide whether to evict flows internal store.
238 } 253 }
239 254
240 @Override 255 @Override
241 public void handleMessage(Dpid dpid, OFMessage msg) { 256 public void handleMessage(Dpid dpid, OFMessage msg) {
242 OpenFlowSwitch sw = controller.getSwitch(dpid); 257 OpenFlowSwitch sw = controller.getSwitch(dpid);
243 switch (msg.getType()) { 258 switch (msg.getType()) {
244 - case FLOW_REMOVED: 259 + case FLOW_REMOVED:
245 - OFFlowRemoved removed = (OFFlowRemoved) msg; 260 + OFFlowRemoved removed = (OFFlowRemoved) msg;
246 - 261 +
247 - FlowEntry fr = new FlowEntryBuilder(dpid, removed).build(); 262 + FlowEntry fr = new FlowEntryBuilder(dpid, removed).build();
248 - providerService.flowRemoved(fr); 263 + providerService.flowRemoved(fr);
249 - break; 264 + break;
250 - case STATS_REPLY: 265 + case STATS_REPLY:
251 - if (((OFStatsReply) msg).getStatsType() == OFStatsType.FLOW) { 266 + if (((OFStatsReply) msg).getStatsType() == OFStatsType.FLOW) {
252 - pushFlowMetrics(dpid, (OFFlowStatsReply) msg); 267 + pushFlowMetrics(dpid, (OFFlowStatsReply) msg);
268 + }
269 + break;
270 + case BARRIER_REPLY:
271 + try {
272 + InternalCacheEntry entry = pendingBatches.getIfPresent(msg
273 + .getXid());
274 + if (entry != null) {
275 + providerService
276 + .batchOperationCompleted(msg.getXid(),
277 + entry.completed());
278 + } else {
279 + log.warn("Received unknown Barrier Reply: {}",
280 + msg.getXid());
253 } 281 }
254 - break; 282 + } finally {
255 - case BARRIER_REPLY: 283 + pendingBatches.invalidate(msg.getXid());
256 - try { 284 + }
257 - InternalCacheEntry entry = pendingBatches.getIfPresent(msg.getXid()); 285 + break;
286 + case ERROR:
287 + log.warn("received Error message {} from {}", msg, dpid);
288 +
289 + OFErrorMsg error = (OFErrorMsg) msg;
290 + if (error.getErrType() == OFErrorType.FLOW_MOD_FAILED) {
291 + OFFlowModFailedErrorMsg fmFailed = (OFFlowModFailedErrorMsg) error;
292 + if (fmFailed.getData().getParsedMessage().isPresent()) {
293 + OFMessage m = fmFailed.getData().getParsedMessage()
294 + .get();
295 + OFFlowMod fm = (OFFlowMod) m;
296 + InternalCacheEntry entry = pendingBatches
297 + .getIfPresent(msg.getXid());
258 if (entry != null) { 298 if (entry != null) {
259 - providerService.batchOperationCompleted(msg.getXid(), entry.completed()); 299 + entry.appendFailure(new FlowEntryBuilder(dpid, fm)
300 + .build());
260 } else { 301 } else {
261 - log.warn("Received unknown Barrier Reply: {}", msg.getXid()); 302 + log.error("No matching batch for this error: {}",
262 - } 303 + error);
263 - } finally {
264 - pendingBatches.invalidate(msg.getXid());
265 - }
266 - break;
267 - case ERROR:
268 - log.warn("received Error message {} from {}", msg, dpid);
269 -
270 - OFErrorMsg error = (OFErrorMsg) msg;
271 - if (error.getErrType() == OFErrorType.FLOW_MOD_FAILED) {
272 - OFFlowModFailedErrorMsg fmFailed = (OFFlowModFailedErrorMsg) error;
273 - if (fmFailed.getData().getParsedMessage().isPresent()) {
274 - OFMessage m = fmFailed.getData().getParsedMessage().get();
275 - OFFlowMod fm = (OFFlowMod) m;
276 - InternalCacheEntry entry = pendingBatches.getIfPresent(msg.getXid());
277 - if (entry != null) {
278 - entry.appendFailure(new FlowEntryBuilder(dpid, fm)
279 - .build());
280 - } else {
281 - log.error("No matching batch for this error: {}", error);
282 - }
283 - } else {
284 - //FIXME: Potentially add flowtracking to avoid this message.
285 - log.error("Flow installation failed but switch didn't" +
286 - " tell us which one.");
287 } 304 }
288 } else { 305 } else {
289 - log.warn("Received error {}", error); 306 + // FIXME: Potentially add flowtracking to avoid this
307 + // message.
308 + log.error("Flow installation failed but switch didn't"
309 + + " tell us which one.");
290 } 310 }
311 + } else {
312 + log.warn("Received error {}", error);
313 + }
291 314
292 - 315 + default:
293 - default: 316 + log.debug("Unhandled message type: {}", msg.getType());
294 - log.debug("Unhandled message type: {}", msg.getType());
295 } 317 }
296 318
297 } 319 }
...@@ -318,11 +340,11 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr ...@@ -318,11 +340,11 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr
318 } 340 }
319 341
320 /** 342 /**
321 - * The internal cache entry holding the original request as well 343 + * The internal cache entry holding the original request as well as
322 - * as accumulating the any failures along the way. 344 + * accumulating the any failures along the way.
323 * 345 *
324 - * If this entry is evicted from the cache then the entire operation 346 + * If this entry is evicted from the cache then the entire operation is
325 - * is considered failed. Otherwise, only the failures reported by the device 347 + * considered failed. Otherwise, only the failures reported by the device
326 * will be propagated up. 348 * will be propagated up.
327 */ 349 */
328 private class InternalCacheEntry { 350 private class InternalCacheEntry {
...@@ -336,6 +358,7 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr ...@@ -336,6 +358,7 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr
336 358
337 /** 359 /**
338 * Appends a failed rule to the set of failed items. 360 * Appends a failed rule to the set of failed items.
361 + *
339 * @param rule the failed rule 362 * @param rule the failed rule
340 */ 363 */
341 public void appendFailure(FlowRule rule) { 364 public void appendFailure(FlowRule rule) {
...@@ -344,21 +367,29 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr ...@@ -344,21 +367,29 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr
344 367
345 /** 368 /**
346 * Fails the entire batch and returns the failed operation. 369 * Fails the entire batch and returns the failed operation.
370 + *
347 * @return the failed operation 371 * @return the failed operation
348 */ 372 */
349 public CompletedBatchOperation failedCompletion() { 373 public CompletedBatchOperation failedCompletion() {
350 Set<FlowRule> fails = operation.getOperations().stream() 374 Set<FlowRule> fails = operation.getOperations().stream()
351 .map(op -> op.target()).collect(Collectors.toSet()); 375 .map(op -> op.target()).collect(Collectors.toSet());
352 - return new CompletedBatchOperation(false, Collections.unmodifiableSet(fails), operation.deviceId()); 376 + return new CompletedBatchOperation(false,
377 + Collections
378 + .unmodifiableSet(fails),
379 + operation.deviceId());
353 } 380 }
354 381
355 /** 382 /**
356 * Returns the completed operation and whether the batch suceeded. 383 * Returns the completed operation and whether the batch suceeded.
384 + *
357 * @return the completed operation 385 * @return the completed operation
358 */ 386 */
359 public CompletedBatchOperation completed() { 387 public CompletedBatchOperation completed() {
360 - return new CompletedBatchOperation(failures.isEmpty(), 388 + return new CompletedBatchOperation(
361 - Collections.unmodifiableSet(failures), operation.deviceId()); 389 + failures.isEmpty(),
390 + Collections
391 + .unmodifiableSet(failures),
392 + operation.deviceId());
362 } 393 }
363 394
364 } 395 }
......
...@@ -40,12 +40,14 @@ import org.onosproject.net.flow.DefaultTrafficSelector; ...@@ -40,12 +40,14 @@ import org.onosproject.net.flow.DefaultTrafficSelector;
40 import org.onosproject.net.flow.DefaultTrafficTreatment; 40 import org.onosproject.net.flow.DefaultTrafficTreatment;
41 import org.onosproject.net.flow.FlowEntry; 41 import org.onosproject.net.flow.FlowEntry;
42 import org.onosproject.net.flow.FlowId; 42 import org.onosproject.net.flow.FlowId;
43 +import org.onosproject.net.flow.FlowRuleExtPayLoad;
43 import org.onosproject.net.flow.FlowRuleService; 44 import org.onosproject.net.flow.FlowRuleService;
44 import org.onosproject.net.flow.TrafficSelector; 45 import org.onosproject.net.flow.TrafficSelector;
45 import org.onosproject.net.flow.TrafficTreatment; 46 import org.onosproject.net.flow.TrafficTreatment;
46 import org.onosproject.net.flow.criteria.Criterion; 47 import org.onosproject.net.flow.criteria.Criterion;
47 import org.onosproject.net.flow.instructions.Instruction; 48 import org.onosproject.net.flow.instructions.Instruction;
48 import org.onosproject.net.flow.instructions.Instructions; 49 import org.onosproject.net.flow.instructions.Instructions;
50 +
49 import com.eclipsesource.json.JsonArray; 51 import com.eclipsesource.json.JsonArray;
50 import com.eclipsesource.json.JsonObject; 52 import com.eclipsesource.json.JsonObject;
51 import com.google.common.collect.ImmutableSet; 53 import com.google.common.collect.ImmutableSet;
...@@ -190,6 +192,11 @@ public class FlowsResourceTest extends ResourceTest { ...@@ -190,6 +192,11 @@ public class FlowsResourceTest extends ResourceTest {
190 public int tableId() { 192 public int tableId() {
191 return 0; 193 return 0;
192 } 194 }
195 +
196 + @Override
197 + public FlowRuleExtPayLoad payLoad() {
198 + return null;
199 + }
193 } 200 }
194 201
195 /** 202 /**
......