Committed by
Gerrit Code Review
Added interfaces configuration to allow vRouter to be selective about what
interfaces to use. Change-Id: I4eb069760df0995d9e831e024ddbc0493bccce0b
Showing
3 changed files
with
53 additions
and
2 deletions
... | @@ -16,10 +16,16 @@ | ... | @@ -16,10 +16,16 @@ |
16 | 16 | ||
17 | package org.onosproject.routing.config; | 17 | package org.onosproject.routing.config; |
18 | 18 | ||
19 | +import com.fasterxml.jackson.databind.JsonNode; | ||
20 | +import com.fasterxml.jackson.databind.node.ArrayNode; | ||
19 | import org.onosproject.core.ApplicationId; | 21 | import org.onosproject.core.ApplicationId; |
20 | import org.onosproject.net.ConnectPoint; | 22 | import org.onosproject.net.ConnectPoint; |
21 | import org.onosproject.net.config.Config; | 23 | import org.onosproject.net.config.Config; |
22 | 24 | ||
25 | +import java.util.ArrayList; | ||
26 | +import java.util.Collections; | ||
27 | +import java.util.List; | ||
28 | + | ||
23 | /** | 29 | /** |
24 | * Routing configuration. | 30 | * Routing configuration. |
25 | */ | 31 | */ |
... | @@ -28,6 +34,7 @@ public class RouterConfig extends Config<ApplicationId> { | ... | @@ -28,6 +34,7 @@ public class RouterConfig extends Config<ApplicationId> { |
28 | private static final String CP_CONNECT_POINT = "controlPlaneConnectPoint"; | 34 | private static final String CP_CONNECT_POINT = "controlPlaneConnectPoint"; |
29 | private static final String OSPF_ENABLED = "ospfEnabled"; | 35 | private static final String OSPF_ENABLED = "ospfEnabled"; |
30 | private static final String PIM_ENABLED = "pimEnabled"; | 36 | private static final String PIM_ENABLED = "pimEnabled"; |
37 | + private static final String INTERFACES = "interfaces"; | ||
31 | 38 | ||
32 | /** | 39 | /** |
33 | * Returns the routing control plane connect point. | 40 | * Returns the routing control plane connect point. |
... | @@ -55,4 +62,24 @@ public class RouterConfig extends Config<ApplicationId> { | ... | @@ -55,4 +62,24 @@ public class RouterConfig extends Config<ApplicationId> { |
55 | public boolean pimEnabled() { | 62 | public boolean pimEnabled() { |
56 | return object.path(PIM_ENABLED).asBoolean(false); | 63 | return object.path(PIM_ENABLED).asBoolean(false); |
57 | } | 64 | } |
65 | + | ||
66 | + /** | ||
67 | + * Returns the list of interfaces enabled on this router. | ||
68 | + * | ||
69 | + * @return list of interface names that are enabled, or an empty list if | ||
70 | + * all available interfaces should be used | ||
71 | + */ | ||
72 | + public List<String> getInterfaces() { | ||
73 | + JsonNode intfNode = object.path(INTERFACES); | ||
74 | + if (intfNode.isMissingNode() || !intfNode.isArray()) { | ||
75 | + return Collections.emptyList(); | ||
76 | + } | ||
77 | + ArrayNode array = (ArrayNode) intfNode; | ||
78 | + List<String> interfaces = new ArrayList<>(array.size()); | ||
79 | + for (JsonNode intf : array) { | ||
80 | + interfaces.add(intf.asText()); | ||
81 | + } | ||
82 | + return interfaces; | ||
83 | + } | ||
84 | + | ||
58 | } | 85 | } | ... | ... |
... | @@ -50,6 +50,9 @@ import org.onosproject.routing.RoutingService; | ... | @@ -50,6 +50,9 @@ import org.onosproject.routing.RoutingService; |
50 | import org.onosproject.routing.config.RouterConfig; | 50 | import org.onosproject.routing.config.RouterConfig; |
51 | import org.slf4j.Logger; | 51 | import org.slf4j.Logger; |
52 | 52 | ||
53 | +import java.util.Collections; | ||
54 | +import java.util.List; | ||
55 | + | ||
53 | import static org.slf4j.LoggerFactory.getLogger; | 56 | import static org.slf4j.LoggerFactory.getLogger; |
54 | 57 | ||
55 | /** | 58 | /** |
... | @@ -69,6 +72,7 @@ public class ControlPlaneRedirectManager { | ... | @@ -69,6 +72,7 @@ public class ControlPlaneRedirectManager { |
69 | 72 | ||
70 | private ConnectPoint controlPlaneConnectPoint; | 73 | private ConnectPoint controlPlaneConnectPoint; |
71 | private boolean ospfEnabled = false; | 74 | private boolean ospfEnabled = false; |
75 | + private List<String> interfaces = Collections.emptyList(); | ||
72 | 76 | ||
73 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 77 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
74 | protected CoreService coreService; | 78 | protected CoreService coreService; |
... | @@ -119,6 +123,7 @@ public class ControlPlaneRedirectManager { | ... | @@ -119,6 +123,7 @@ public class ControlPlaneRedirectManager { |
119 | 123 | ||
120 | controlPlaneConnectPoint = config.getControlPlaneConnectPoint(); | 124 | controlPlaneConnectPoint = config.getControlPlaneConnectPoint(); |
121 | ospfEnabled = config.getOspfEnabled(); | 125 | ospfEnabled = config.getOspfEnabled(); |
126 | + interfaces = config.getInterfaces(); | ||
122 | 127 | ||
123 | updateDevice(); | 128 | updateDevice(); |
124 | } | 129 | } |
... | @@ -130,6 +135,7 @@ public class ControlPlaneRedirectManager { | ... | @@ -130,6 +135,7 @@ public class ControlPlaneRedirectManager { |
130 | 135 | ||
131 | interfaceService.getInterfaces().stream() | 136 | interfaceService.getInterfaces().stream() |
132 | .filter(intf -> intf.connectPoint().deviceId().equals(deviceId)) | 137 | .filter(intf -> intf.connectPoint().deviceId().equals(deviceId)) |
138 | + .filter(intf -> interfaces.isEmpty() || interfaces.contains(intf.name())) | ||
133 | .forEach(this::provisionInterface); | 139 | .forEach(this::provisionInterface); |
134 | 140 | ||
135 | log.info("Set up interfaces on {}", controlPlaneConnectPoint.deviceId()); | 141 | log.info("Set up interfaces on {}", controlPlaneConnectPoint.deviceId()); | ... | ... |
... | @@ -67,8 +67,10 @@ import org.slf4j.LoggerFactory; | ... | @@ -67,8 +67,10 @@ import org.slf4j.LoggerFactory; |
67 | 67 | ||
68 | import java.util.Collection; | 68 | import java.util.Collection; |
69 | import java.util.HashMap; | 69 | import java.util.HashMap; |
70 | +import java.util.List; | ||
70 | import java.util.Map; | 71 | import java.util.Map; |
71 | import java.util.Set; | 72 | import java.util.Set; |
73 | +import java.util.stream.Collectors; | ||
72 | 74 | ||
73 | /** | 75 | /** |
74 | * Programs routes to a single OpenFlow switch. | 76 | * Programs routes to a single OpenFlow switch. |
... | @@ -108,6 +110,8 @@ public class SingleSwitchFibInstaller { | ... | @@ -108,6 +110,8 @@ public class SingleSwitchFibInstaller { |
108 | 110 | ||
109 | private ConnectPoint controlPlaneConnectPoint; | 111 | private ConnectPoint controlPlaneConnectPoint; |
110 | 112 | ||
113 | + private List<String> interfaces; | ||
114 | + | ||
111 | private ApplicationId routerAppId; | 115 | private ApplicationId routerAppId; |
112 | 116 | ||
113 | // Reference count for how many times a next hop is used by a route | 117 | // Reference count for how many times a next hop is used by a route |
... | @@ -161,15 +165,29 @@ public class SingleSwitchFibInstaller { | ... | @@ -161,15 +165,29 @@ public class SingleSwitchFibInstaller { |
161 | log.info("Control Plane Connect Point: {}", controlPlaneConnectPoint); | 165 | log.info("Control Plane Connect Point: {}", controlPlaneConnectPoint); |
162 | 166 | ||
163 | deviceId = routerConfig.getControlPlaneConnectPoint().deviceId(); | 167 | deviceId = routerConfig.getControlPlaneConnectPoint().deviceId(); |
164 | - | ||
165 | log.info("Router device ID is {}", deviceId); | 168 | log.info("Router device ID is {}", deviceId); |
166 | 169 | ||
170 | + interfaces = routerConfig.getInterfaces(); | ||
171 | + log.info("Using interfaces: {}", interfaces.isEmpty() ? "all" : interfaces); | ||
172 | + | ||
167 | updateDevice(); | 173 | updateDevice(); |
168 | } | 174 | } |
169 | 175 | ||
170 | private void updateDevice() { | 176 | private void updateDevice() { |
171 | if (deviceId != null && deviceService.isAvailable(deviceId)) { | 177 | if (deviceId != null && deviceService.isAvailable(deviceId)) { |
172 | - processIntfFilters(true, interfaceService.getInterfaces()); | 178 | + |
179 | + Set<Interface> intfs; | ||
180 | + if (interfaces.isEmpty()) { | ||
181 | + intfs = interfaceService.getInterfaces(); | ||
182 | + } else { | ||
183 | + // TODO need to fix by making interface names globally unique | ||
184 | + intfs = interfaceService.getInterfaces().stream() | ||
185 | + .filter(intf -> intf.connectPoint().deviceId().equals(deviceId)) | ||
186 | + .filter(intf -> interfaces.contains(intf.name())) | ||
187 | + .collect(Collectors.toSet()); | ||
188 | + } | ||
189 | + | ||
190 | + processIntfFilters(true, intfs); | ||
173 | } | 191 | } |
174 | } | 192 | } |
175 | 193 | ... | ... |
-
Please register or login to post a comment