Committed by
Gerrit Code Review
ControlPlaneRedirectManager.java, Cleaning flows on Deactivating the app
Change-Id: I06c9c2dd286f02ad84a1c01bfa5b7202988b0402
Showing
2 changed files
with
35 additions
and
9 deletions
... | @@ -27,6 +27,7 @@ import org.onlab.packet.EthType; | ... | @@ -27,6 +27,7 @@ import org.onlab.packet.EthType; |
27 | import org.onlab.packet.IpPrefix; | 27 | import org.onlab.packet.IpPrefix; |
28 | import org.onlab.packet.MacAddress; | 28 | import org.onlab.packet.MacAddress; |
29 | import org.onlab.packet.VlanId; | 29 | import org.onlab.packet.VlanId; |
30 | +import org.onosproject.app.ApplicationService; | ||
30 | import org.onosproject.core.ApplicationId; | 31 | import org.onosproject.core.ApplicationId; |
31 | import org.onosproject.core.CoreService; | 32 | import org.onosproject.core.CoreService; |
32 | import org.onosproject.incubator.net.intf.Interface; | 33 | import org.onosproject.incubator.net.intf.Interface; |
... | @@ -85,7 +86,7 @@ public class ControlPlaneRedirectManager { | ... | @@ -85,7 +86,7 @@ public class ControlPlaneRedirectManager { |
85 | private static final int ACL_PRIORITY = 40001; | 86 | private static final int ACL_PRIORITY = 40001; |
86 | private static final int OSPF_IP_PROTO = 0x59; | 87 | private static final int OSPF_IP_PROTO = 0x59; |
87 | 88 | ||
88 | - private static final String APP_NAME = "org.onosproject.cpredirect"; | 89 | + private static final String APP_NAME = "org.onosproject.vrouter"; |
89 | private ApplicationId appId; | 90 | private ApplicationId appId; |
90 | 91 | ||
91 | private ConnectPoint controlPlaneConnectPoint; | 92 | private ConnectPoint controlPlaneConnectPoint; |
... | @@ -114,6 +115,9 @@ public class ControlPlaneRedirectManager { | ... | @@ -114,6 +115,9 @@ public class ControlPlaneRedirectManager { |
114 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 115 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
115 | protected HostService hostService; | 116 | protected HostService hostService; |
116 | 117 | ||
118 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
119 | + protected ApplicationService applicationService; | ||
120 | + | ||
117 | private final InternalDeviceListener deviceListener = new InternalDeviceListener(); | 121 | private final InternalDeviceListener deviceListener = new InternalDeviceListener(); |
118 | private final InternalNetworkConfigListener networkConfigListener = | 122 | private final InternalNetworkConfigListener networkConfigListener = |
119 | new InternalNetworkConfigListener(); | 123 | new InternalNetworkConfigListener(); |
... | @@ -129,7 +133,10 @@ public class ControlPlaneRedirectManager { | ... | @@ -129,7 +133,10 @@ public class ControlPlaneRedirectManager { |
129 | hostService.addListener(hostListener); | 133 | hostService.addListener(hostListener); |
130 | interfaceService.addListener(interfaceListener); | 134 | interfaceService.addListener(interfaceListener); |
131 | 135 | ||
132 | - updateConfig(); | 136 | + updateConfig(true); |
137 | + applicationService.registerDeactivateHook(this.appId, () -> { | ||
138 | + this.updateConfig(false); | ||
139 | + }); | ||
133 | } | 140 | } |
134 | 141 | ||
135 | @Deactivate | 142 | @Deactivate |
... | @@ -140,7 +147,14 @@ public class ControlPlaneRedirectManager { | ... | @@ -140,7 +147,14 @@ public class ControlPlaneRedirectManager { |
140 | interfaceService.removeListener(interfaceListener); | 147 | interfaceService.removeListener(interfaceListener); |
141 | } | 148 | } |
142 | 149 | ||
143 | - private void updateConfig() { | 150 | + /** |
151 | + * Installs or removes interface configuration | ||
152 | + * based on the flag used on activate or deactivate. | ||
153 | + * | ||
154 | + * @param operation true on activate application, false on deactivate | ||
155 | + * the application | ||
156 | + **/ | ||
157 | + private void updateConfig(boolean operation) { | ||
144 | ApplicationId routingAppId = | 158 | ApplicationId routingAppId = |
145 | coreService.registerApplication(RoutingService.ROUTER_APP_ID); | 159 | coreService.registerApplication(RoutingService.ROUTER_APP_ID); |
146 | 160 | ||
... | @@ -156,10 +170,17 @@ public class ControlPlaneRedirectManager { | ... | @@ -156,10 +170,17 @@ public class ControlPlaneRedirectManager { |
156 | ospfEnabled = config.getOspfEnabled(); | 170 | ospfEnabled = config.getOspfEnabled(); |
157 | interfaces = config.getInterfaces(); | 171 | interfaces = config.getInterfaces(); |
158 | 172 | ||
159 | - updateDevice(); | 173 | + updateDevice(operation); |
160 | } | 174 | } |
161 | 175 | ||
162 | - private void updateDevice() { | 176 | + /** |
177 | + * Installs or removes interface configuration for each interface | ||
178 | + * based on the flag used on activate or deactivate. | ||
179 | + * | ||
180 | + * @param operation true on activate application, false on deactivate | ||
181 | + * the application | ||
182 | + **/ | ||
183 | + private void updateDevice(boolean operation) { | ||
163 | if (controlPlaneConnectPoint != null && | 184 | if (controlPlaneConnectPoint != null && |
164 | deviceService.isAvailable(controlPlaneConnectPoint.deviceId())) { | 185 | deviceService.isAvailable(controlPlaneConnectPoint.deviceId())) { |
165 | DeviceId deviceId = controlPlaneConnectPoint.deviceId(); | 186 | DeviceId deviceId = controlPlaneConnectPoint.deviceId(); |
... | @@ -167,7 +188,7 @@ public class ControlPlaneRedirectManager { | ... | @@ -167,7 +188,7 @@ public class ControlPlaneRedirectManager { |
167 | interfaceService.getInterfaces().stream() | 188 | interfaceService.getInterfaces().stream() |
168 | .filter(intf -> intf.connectPoint().deviceId().equals(deviceId)) | 189 | .filter(intf -> intf.connectPoint().deviceId().equals(deviceId)) |
169 | .filter(intf -> interfaces.isEmpty() || interfaces.contains(intf.name())) | 190 | .filter(intf -> interfaces.isEmpty() || interfaces.contains(intf.name())) |
170 | - .forEach(this::provisionInterface); | 191 | + .forEach(operation ? this::provisionInterface : this::removeInterface); |
171 | 192 | ||
172 | log.info("Set up interfaces on {}", controlPlaneConnectPoint.deviceId()); | 193 | log.info("Set up interfaces on {}", controlPlaneConnectPoint.deviceId()); |
173 | } | 194 | } |
... | @@ -383,7 +404,7 @@ public class ControlPlaneRedirectManager { | ... | @@ -383,7 +404,7 @@ public class ControlPlaneRedirectManager { |
383 | case DEVICE_AVAILABILITY_CHANGED: | 404 | case DEVICE_AVAILABILITY_CHANGED: |
384 | if (deviceService.isAvailable(event.subject().id())) { | 405 | if (deviceService.isAvailable(event.subject().id())) { |
385 | log.info("Device connected {}", event.subject().id()); | 406 | log.info("Device connected {}", event.subject().id()); |
386 | - updateDevice(); | 407 | + updateDevice(true); |
387 | } | 408 | } |
388 | break; | 409 | break; |
389 | case DEVICE_UPDATED: | 410 | case DEVICE_UPDATED: |
... | @@ -410,7 +431,7 @@ public class ControlPlaneRedirectManager { | ... | @@ -410,7 +431,7 @@ public class ControlPlaneRedirectManager { |
410 | switch (event.type()) { | 431 | switch (event.type()) { |
411 | case CONFIG_ADDED: | 432 | case CONFIG_ADDED: |
412 | case CONFIG_UPDATED: | 433 | case CONFIG_UPDATED: |
413 | - updateConfig(); | 434 | + updateConfig(true); |
414 | break; | 435 | break; |
415 | case CONFIG_REGISTERED: | 436 | case CONFIG_REGISTERED: |
416 | case CONFIG_UNREGISTERED: | 437 | case CONFIG_UNREGISTERED: | ... | ... |
... | @@ -24,6 +24,7 @@ import org.onlab.packet.IpAddress; | ... | @@ -24,6 +24,7 @@ import org.onlab.packet.IpAddress; |
24 | import org.onlab.packet.IpPrefix; | 24 | import org.onlab.packet.IpPrefix; |
25 | import org.onlab.packet.MacAddress; | 25 | import org.onlab.packet.MacAddress; |
26 | import org.onlab.packet.VlanId; | 26 | import org.onlab.packet.VlanId; |
27 | +import org.onosproject.app.ApplicationService; | ||
27 | import org.onosproject.core.ApplicationId; | 28 | import org.onosproject.core.ApplicationId; |
28 | import org.onosproject.core.CoreService; | 29 | import org.onosproject.core.CoreService; |
29 | import org.onosproject.core.CoreServiceAdapter; | 30 | import org.onosproject.core.CoreServiceAdapter; |
... | @@ -89,7 +90,7 @@ public class ControlPlaneRedirectManagerTest { | ... | @@ -89,7 +90,7 @@ public class ControlPlaneRedirectManagerTest { |
89 | private static final int OSPF_IP_PROTO = 0x59; | 90 | private static final int OSPF_IP_PROTO = 0x59; |
90 | private CoreService coreService = new TestCoreService(); | 91 | private CoreService coreService = new TestCoreService(); |
91 | private InterfaceService interfaceService; | 92 | private InterfaceService interfaceService; |
92 | - private static final ApplicationId APPID = TestApplicationId.create("org.onosproject.cpredirect"); | 93 | + private static final ApplicationId APPID = TestApplicationId.create("org.onosproject.vrouter"); |
93 | 94 | ||
94 | private static final DeviceId DEVICE_ID = DeviceId.deviceId("of:0000000000000001"); | 95 | private static final DeviceId DEVICE_ID = DeviceId.deviceId("of:0000000000000001"); |
95 | 96 | ||
... | @@ -111,6 +112,7 @@ public class ControlPlaneRedirectManagerTest { | ... | @@ -111,6 +112,7 @@ public class ControlPlaneRedirectManagerTest { |
111 | private DeviceListener deviceListener; | 112 | private DeviceListener deviceListener; |
112 | private MastershipService mastershipService = new InternalMastershipServiceTest(); | 113 | private MastershipService mastershipService = new InternalMastershipServiceTest(); |
113 | private InterfaceListener interfaceListener; | 114 | private InterfaceListener interfaceListener; |
115 | + private ApplicationService applicationService; | ||
114 | 116 | ||
115 | @Before | 117 | @Before |
116 | public void setUp() { | 118 | public void setUp() { |
... | @@ -126,6 +128,8 @@ public class ControlPlaneRedirectManagerTest { | ... | @@ -126,6 +128,8 @@ public class ControlPlaneRedirectManagerTest { |
126 | networkConfigService = new TestNetworkConfigService(); | 128 | networkConfigService = new TestNetworkConfigService(); |
127 | networkConfigService.addListener(networkConfigListener); | 129 | networkConfigService.addListener(networkConfigListener); |
128 | flowObjectiveService = createMock(FlowObjectiveService.class); | 130 | flowObjectiveService = createMock(FlowObjectiveService.class); |
131 | + applicationService = createNiceMock(ApplicationService.class); | ||
132 | + replay(applicationService); | ||
129 | setUpFlowObjectiveService(); | 133 | setUpFlowObjectiveService(); |
130 | controlPlaneRedirectManager.coreService = coreService; | 134 | controlPlaneRedirectManager.coreService = coreService; |
131 | controlPlaneRedirectManager.flowObjectiveService = flowObjectiveService; | 135 | controlPlaneRedirectManager.flowObjectiveService = flowObjectiveService; |
... | @@ -134,6 +138,7 @@ public class ControlPlaneRedirectManagerTest { | ... | @@ -134,6 +138,7 @@ public class ControlPlaneRedirectManagerTest { |
134 | controlPlaneRedirectManager.deviceService = deviceService; | 138 | controlPlaneRedirectManager.deviceService = deviceService; |
135 | controlPlaneRedirectManager.hostService = createNiceMock(HostService.class); | 139 | controlPlaneRedirectManager.hostService = createNiceMock(HostService.class); |
136 | controlPlaneRedirectManager.mastershipService = mastershipService; | 140 | controlPlaneRedirectManager.mastershipService = mastershipService; |
141 | + controlPlaneRedirectManager.applicationService = applicationService; | ||
137 | controlPlaneRedirectManager.activate(); | 142 | controlPlaneRedirectManager.activate(); |
138 | verify(flowObjectiveService); | 143 | verify(flowObjectiveService); |
139 | } | 144 | } | ... | ... |
-
Please register or login to post a comment