Committed by
alshabib
Add a new method sendMsg(OFMessage msg, TableType type) in OpenFlowSwitch interf…
…ace to support multiple-table aware FlowRuleService. Other changes are caused due to the new method. Add type() in FlowRule interface to determine the table in which the flow rule need to be set. Change-Id: I6518a01f4a5fba23f09f70b619f3844b5e33ce8f
Showing
13 changed files
with
189 additions
and
3 deletions
... | @@ -40,6 +40,8 @@ public class DefaultFlowRule implements FlowRule { | ... | @@ -40,6 +40,8 @@ public class DefaultFlowRule implements FlowRule { |
40 | private final boolean permanent; | 40 | private final boolean permanent; |
41 | private final GroupId groupId; | 41 | private final GroupId groupId; |
42 | 42 | ||
43 | + private final Type type; | ||
44 | + | ||
43 | 45 | ||
44 | public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector, | 46 | public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector, |
45 | TrafficTreatment treatment, int priority, long flowId, | 47 | TrafficTreatment treatment, int priority, long flowId, |
... | @@ -55,12 +57,42 @@ public class DefaultFlowRule implements FlowRule { | ... | @@ -55,12 +57,42 @@ public class DefaultFlowRule implements FlowRule { |
55 | this.appId = (short) (flowId >>> 48); | 57 | this.appId = (short) (flowId >>> 48); |
56 | this.groupId = new DefaultGroupId((short) ((flowId >>> 32) & 0xFFFF)); | 58 | this.groupId = new DefaultGroupId((short) ((flowId >>> 32) & 0xFFFF)); |
57 | this.id = FlowId.valueOf(flowId); | 59 | this.id = FlowId.valueOf(flowId); |
60 | + this.type = Type.DEFAULT; | ||
58 | } | 61 | } |
59 | 62 | ||
60 | public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector, | 63 | public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector, |
61 | TrafficTreatment treatment, int priority, ApplicationId appId, | 64 | TrafficTreatment treatment, int priority, ApplicationId appId, |
62 | int timeout, boolean permanent) { | 65 | int timeout, boolean permanent) { |
63 | - this(deviceId, selector, treatment, priority, appId, new DefaultGroupId(0), timeout, permanent); | 66 | + this(deviceId, selector, treatment, priority, appId, new DefaultGroupId(0), |
67 | + timeout, permanent); | ||
68 | + } | ||
69 | + | ||
70 | + public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector, | ||
71 | + TrafficTreatment treatment, int priority, ApplicationId appId, | ||
72 | + int timeout, boolean permanent, Type type) { | ||
73 | + | ||
74 | + if (priority < FlowRule.MIN_PRIORITY) { | ||
75 | + throw new IllegalArgumentException("Priority cannot be less than " + MIN_PRIORITY); | ||
76 | + } | ||
77 | + | ||
78 | + this.deviceId = deviceId; | ||
79 | + this.priority = priority; | ||
80 | + this.selector = selector; | ||
81 | + this.treatment = treatment; | ||
82 | + this.appId = appId.id(); | ||
83 | + this.groupId = new DefaultGroupId(0); | ||
84 | + this.timeout = timeout; | ||
85 | + this.permanent = permanent; | ||
86 | + this.created = System.currentTimeMillis(); | ||
87 | + this.type = type; | ||
88 | + | ||
89 | + /* | ||
90 | + * id consists of the following. | ||
91 | + * | appId (16 bits) | groupId (16 bits) | flowId (32 bits) | | ||
92 | + */ | ||
93 | + this.id = FlowId.valueOf((((long) this.appId) << 48) | (((long) this.groupId.id()) << 32) | ||
94 | + | (this.hash() & 0xffffffffL)); | ||
95 | + | ||
64 | } | 96 | } |
65 | 97 | ||
66 | public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector, | 98 | public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector, |
... | @@ -80,6 +112,7 @@ public class DefaultFlowRule implements FlowRule { | ... | @@ -80,6 +112,7 @@ public class DefaultFlowRule implements FlowRule { |
80 | this.timeout = timeout; | 112 | this.timeout = timeout; |
81 | this.permanent = permanent; | 113 | this.permanent = permanent; |
82 | this.created = System.currentTimeMillis(); | 114 | this.created = System.currentTimeMillis(); |
115 | + this.type = Type.DEFAULT; | ||
83 | 116 | ||
84 | /* | 117 | /* |
85 | * id consists of the following. | 118 | * id consists of the following. |
... | @@ -100,10 +133,10 @@ public class DefaultFlowRule implements FlowRule { | ... | @@ -100,10 +133,10 @@ public class DefaultFlowRule implements FlowRule { |
100 | this.timeout = rule.timeout(); | 133 | this.timeout = rule.timeout(); |
101 | this.permanent = rule.isPermanent(); | 134 | this.permanent = rule.isPermanent(); |
102 | this.created = System.currentTimeMillis(); | 135 | this.created = System.currentTimeMillis(); |
136 | + this.type = rule.type(); | ||
103 | 137 | ||
104 | } | 138 | } |
105 | 139 | ||
106 | - | ||
107 | @Override | 140 | @Override |
108 | public FlowId id() { | 141 | public FlowId id() { |
109 | return id; | 142 | return id; |
... | @@ -198,4 +231,9 @@ public class DefaultFlowRule implements FlowRule { | ... | @@ -198,4 +231,9 @@ public class DefaultFlowRule implements FlowRule { |
198 | return permanent; | 231 | return permanent; |
199 | } | 232 | } |
200 | 233 | ||
234 | + @Override | ||
235 | + public Type type() { | ||
236 | + return type; | ||
237 | + } | ||
238 | + | ||
201 | } | 239 | } | ... | ... |
... | @@ -27,6 +27,22 @@ public interface FlowRule { | ... | @@ -27,6 +27,22 @@ public interface FlowRule { |
27 | static final int MAX_TIMEOUT = 60; | 27 | static final int MAX_TIMEOUT = 60; |
28 | static final int MIN_PRIORITY = 0; | 28 | static final int MIN_PRIORITY = 0; |
29 | 29 | ||
30 | + /** | ||
31 | + * The FlowRule type is used to determine in which table the flow rule | ||
32 | + * needs to be put for multi-table support switch. | ||
33 | + * For single table switch, Default is used. | ||
34 | + */ | ||
35 | + public static enum Type { | ||
36 | + /* Default type - used in flow rule for single table switch */ | ||
37 | + DEFAULT, | ||
38 | + /* Used in flow entry for IP table */ | ||
39 | + IP, | ||
40 | + /* Used in flow entry for MPLS table */ | ||
41 | + MPLS, | ||
42 | + /* Used in flow entry for ACL table */ | ||
43 | + ACL | ||
44 | + } | ||
45 | + | ||
30 | //TODO: build cookie value | 46 | //TODO: build cookie value |
31 | /** | 47 | /** |
32 | * Returns the ID of this flow. | 48 | * Returns the ID of this flow. |
... | @@ -93,4 +109,11 @@ public interface FlowRule { | ... | @@ -93,4 +109,11 @@ public interface FlowRule { |
93 | */ | 109 | */ |
94 | boolean isPermanent(); | 110 | boolean isPermanent(); |
95 | 111 | ||
112 | + /** | ||
113 | + * Returns the flow rule type. | ||
114 | + * | ||
115 | + * @return flow rule type | ||
116 | + */ | ||
117 | + Type type(); | ||
118 | + | ||
96 | } | 119 | } | ... | ... |
... | @@ -296,8 +296,11 @@ public class IntentTestsMocks { | ... | @@ -296,8 +296,11 @@ public class IntentTestsMocks { |
296 | public static class MockFlowRule implements FlowRule { | 296 | public static class MockFlowRule implements FlowRule { |
297 | 297 | ||
298 | int priority; | 298 | int priority; |
299 | + Type type; | ||
300 | + | ||
299 | public MockFlowRule(int priority) { | 301 | public MockFlowRule(int priority) { |
300 | this.priority = priority; | 302 | this.priority = priority; |
303 | + this.type = Type.DEFAULT; | ||
301 | } | 304 | } |
302 | 305 | ||
303 | @Override | 306 | @Override |
... | @@ -361,6 +364,11 @@ public class IntentTestsMocks { | ... | @@ -361,6 +364,11 @@ public class IntentTestsMocks { |
361 | final MockFlowRule other = (MockFlowRule) obj; | 364 | final MockFlowRule other = (MockFlowRule) obj; |
362 | return Objects.equals(this.priority, other.priority); | 365 | return Objects.equals(this.priority, other.priority); |
363 | } | 366 | } |
367 | + | ||
368 | + @Override | ||
369 | + public Type type() { | ||
370 | + return type; | ||
371 | + } | ||
364 | } | 372 | } |
365 | 373 | ||
366 | 374 | ... | ... |
... | @@ -53,6 +53,7 @@ import org.onosproject.net.PortNumber; | ... | @@ -53,6 +53,7 @@ import org.onosproject.net.PortNumber; |
53 | import org.onosproject.net.device.DefaultDeviceDescription; | 53 | import org.onosproject.net.device.DefaultDeviceDescription; |
54 | import org.onosproject.net.device.DefaultPortDescription; | 54 | import org.onosproject.net.device.DefaultPortDescription; |
55 | import org.onosproject.net.flow.CompletedBatchOperation; | 55 | import org.onosproject.net.flow.CompletedBatchOperation; |
56 | +import org.onosproject.net.flow.FlowRule; | ||
56 | import org.onosproject.net.flow.DefaultFlowEntry; | 57 | import org.onosproject.net.flow.DefaultFlowEntry; |
57 | import org.onosproject.net.flow.DefaultFlowRule; | 58 | import org.onosproject.net.flow.DefaultFlowRule; |
58 | import org.onosproject.net.flow.DefaultTrafficSelector; | 59 | import org.onosproject.net.flow.DefaultTrafficSelector; |
... | @@ -214,6 +215,7 @@ public final class KryoNamespaces { | ... | @@ -214,6 +215,7 @@ public final class KryoNamespaces { |
214 | DefaultHostDescription.class, | 215 | DefaultHostDescription.class, |
215 | DefaultFlowEntry.class, | 216 | DefaultFlowEntry.class, |
216 | StoredFlowEntry.class, | 217 | StoredFlowEntry.class, |
218 | + FlowRule.Type.class, | ||
217 | DefaultFlowRule.class, | 219 | DefaultFlowRule.class, |
218 | DefaultFlowEntry.class, | 220 | DefaultFlowEntry.class, |
219 | FlowEntry.FlowEntryState.class, | 221 | FlowEntry.FlowEntryState.class, | ... | ... |
... | @@ -27,6 +27,22 @@ import org.projectfloodlight.openflow.protocol.OFPortDesc; | ... | @@ -27,6 +27,22 @@ import org.projectfloodlight.openflow.protocol.OFPortDesc; |
27 | public interface OpenFlowSwitch { | 27 | public interface OpenFlowSwitch { |
28 | 28 | ||
29 | /** | 29 | /** |
30 | + * The TableType is used to determine in which table (TableID) each flow rule | ||
31 | + * needs to be put for multi-table support switch. | ||
32 | + * It is used only for multi-table support switch. | ||
33 | + */ | ||
34 | + public static enum TableType { | ||
35 | + /* IP table */ | ||
36 | + IP, | ||
37 | + /* MPLS table */ | ||
38 | + MPLS, | ||
39 | + /* ACL table */ | ||
40 | + ACL, | ||
41 | + /* Single table */ | ||
42 | + NONE, | ||
43 | + } | ||
44 | + | ||
45 | + /** | ||
30 | * Writes the message to the driver. | 46 | * Writes the message to the driver. |
31 | * | 47 | * |
32 | * @param msg the message to write | 48 | * @param msg the message to write |
... | @@ -41,6 +57,16 @@ public interface OpenFlowSwitch { | ... | @@ -41,6 +57,16 @@ public interface OpenFlowSwitch { |
41 | public void sendMsg(List<OFMessage> msgs); | 57 | public void sendMsg(List<OFMessage> msgs); |
42 | 58 | ||
43 | /** | 59 | /** |
60 | + * Writes to the OFMessage list to the driver. | ||
61 | + * TableType is used to determine the table ID for the OFMessage. | ||
62 | + * The switch driver that supports multi-table should implement the function. | ||
63 | + * | ||
64 | + * @param msg the message to be written | ||
65 | + * @param tableType the type of table in which the OFMessage needs to put | ||
66 | + */ | ||
67 | + public void sendMsg(OFMessage msg, TableType tableType); | ||
68 | + | ||
69 | + /** | ||
44 | * Handle a message from the switch. | 70 | * Handle a message from the switch. |
45 | * @param fromSwitch the message to handle | 71 | * @param fromSwitch the message to handle |
46 | */ | 72 | */ | ... | ... |
... | @@ -110,6 +110,13 @@ public abstract class AbstractOpenFlowSwitch implements OpenFlowSwitchDriver { | ... | @@ -110,6 +110,13 @@ public abstract class AbstractOpenFlowSwitch implements OpenFlowSwitchDriver { |
110 | } | 110 | } |
111 | 111 | ||
112 | @Override | 112 | @Override |
113 | + public void sendMsg(OFMessage msg, TableType tableType) { | ||
114 | + if (role == RoleState.MASTER) { | ||
115 | + this.write(msg); | ||
116 | + } | ||
117 | + } | ||
118 | + | ||
119 | + @Override | ||
113 | public abstract void write(OFMessage msg); | 120 | public abstract void write(OFMessage msg); |
114 | 121 | ||
115 | @Override | 122 | @Override | ... | ... |
... | @@ -111,6 +111,10 @@ public class RoleManagerTest { | ... | @@ -111,6 +111,10 @@ public class RoleManagerTest { |
111 | } | 111 | } |
112 | 112 | ||
113 | @Override | 113 | @Override |
114 | + public void sendMsg(OFMessage msg, TableType tableType) { | ||
115 | + } | ||
116 | + | ||
117 | + @Override | ||
114 | public void handleMessage(OFMessage fromSwitch) { | 118 | public void handleMessage(OFMessage fromSwitch) { |
115 | } | 119 | } |
116 | 120 | ... | ... |
... | @@ -669,7 +669,6 @@ public class OFSwitchImplCPqD13 extends AbstractOpenFlowSwitch { | ... | @@ -669,7 +669,6 @@ public class OFSwitchImplCPqD13 extends AbstractOpenFlowSwitch { |
669 | } | 669 | } |
670 | return subnetIps; | 670 | return subnetIps; |
671 | } | 671 | } |
672 | - | ||
673 | private static class RouteEntry { | 672 | private static class RouteEntry { |
674 | String prefix; | 673 | String prefix; |
675 | String mask; | 674 | String mask; | ... | ... |
openflow/drivers/src/main/java/org/onosproject/openflow/drivers/OFSwitchImplSpringOpenTTP.java
0 → 100644
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.openflow.drivers; | ||
17 | + | ||
18 | +import org.onosproject.openflow.controller.Dpid; | ||
19 | +import org.onosproject.openflow.controller.driver.AbstractOpenFlowSwitch; | ||
20 | +import org.projectfloodlight.openflow.protocol.OFMessage; | ||
21 | + | ||
22 | +import java.util.List; | ||
23 | + | ||
24 | +/** | ||
25 | + * Created by sanghoshin on 1/22/15. | ||
26 | + */ | ||
27 | +public class OFSwitchImplSpringOpenTTP extends AbstractOpenFlowSwitch { | ||
28 | + | ||
29 | + protected OFSwitchImplSpringOpenTTP(Dpid dp) { | ||
30 | + super(dp); | ||
31 | + } | ||
32 | + | ||
33 | + @Override | ||
34 | + public void write(OFMessage msg) { | ||
35 | + | ||
36 | + } | ||
37 | + | ||
38 | + @Override | ||
39 | + public void write(List<OFMessage> msgs) { | ||
40 | + | ||
41 | + } | ||
42 | + | ||
43 | + @Override | ||
44 | + public Boolean supportNxRole() { | ||
45 | + return null; | ||
46 | + } | ||
47 | + | ||
48 | + @Override | ||
49 | + public void startDriverHandshake() { | ||
50 | + | ||
51 | + } | ||
52 | + | ||
53 | + @Override | ||
54 | + public boolean isDriverHandshakeComplete() { | ||
55 | + return false; | ||
56 | + } | ||
57 | + | ||
58 | + @Override | ||
59 | + public void processDriverHandshakeMessage(OFMessage m) { | ||
60 | + | ||
61 | + } | ||
62 | + | ||
63 | +} |
... | @@ -310,6 +310,10 @@ public class OpenFlowDeviceProviderTest { | ... | @@ -310,6 +310,10 @@ public class OpenFlowDeviceProviderTest { |
310 | } | 310 | } |
311 | 311 | ||
312 | @Override | 312 | @Override |
313 | + public void sendMsg(OFMessage msg, TableType tableType) { | ||
314 | + } | ||
315 | + | ||
316 | + @Override | ||
313 | public void handleMessage(OFMessage fromSwitch) { | 317 | public void handleMessage(OFMessage fromSwitch) { |
314 | } | 318 | } |
315 | 319 | ... | ... |
... | @@ -414,6 +414,10 @@ public class OpenFlowLinkProviderTest { | ... | @@ -414,6 +414,10 @@ public class OpenFlowLinkProviderTest { |
414 | } | 414 | } |
415 | 415 | ||
416 | @Override | 416 | @Override |
417 | + public void sendMsg(OFMessage msg, TableType tableType) { | ||
418 | + } | ||
419 | + | ||
420 | + @Override | ||
417 | public void handleMessage(OFMessage fromSwitch) { | 421 | public void handleMessage(OFMessage fromSwitch) { |
418 | } | 422 | } |
419 | 423 | ... | ... |
... | @@ -347,6 +347,10 @@ public class OpenFlowPacketProviderTest { | ... | @@ -347,6 +347,10 @@ public class OpenFlowPacketProviderTest { |
347 | } | 347 | } |
348 | 348 | ||
349 | @Override | 349 | @Override |
350 | + public void sendMsg(OFMessage msg, TableType tableType) { | ||
351 | + } | ||
352 | + | ||
353 | + @Override | ||
350 | public void handleMessage(OFMessage fromSwitch) { | 354 | public void handleMessage(OFMessage fromSwitch) { |
351 | } | 355 | } |
352 | 356 | ... | ... |
... | @@ -186,6 +186,10 @@ public class FlowsResourceTest extends ResourceTest { | ... | @@ -186,6 +186,10 @@ public class FlowsResourceTest extends ResourceTest { |
186 | public boolean isPermanent() { | 186 | public boolean isPermanent() { |
187 | return false; | 187 | return false; |
188 | } | 188 | } |
189 | + | ||
190 | + public Type type() { | ||
191 | + return Type.DEFAULT; | ||
192 | + } | ||
189 | } | 193 | } |
190 | 194 | ||
191 | /** | 195 | /** | ... | ... |
-
Please register or login to post a comment