Jonathan Hart
Committed by Gerrit Code Review

Push default forwarding objectives when device becomes available.

Change-Id: Ic3e54e99783ca1e01a984f86fdb754dcc7852c06
...@@ -32,6 +32,9 @@ import org.onosproject.core.CoreService; ...@@ -32,6 +32,9 @@ import org.onosproject.core.CoreService;
32 import org.onosproject.net.ConnectPoint; 32 import org.onosproject.net.ConnectPoint;
33 import org.onosproject.net.DeviceId; 33 import org.onosproject.net.DeviceId;
34 import org.onosproject.net.PortNumber; 34 import org.onosproject.net.PortNumber;
35 +import org.onosproject.net.device.DeviceEvent;
36 +import org.onosproject.net.device.DeviceListener;
37 +import org.onosproject.net.device.DeviceService;
35 import org.onosproject.net.flow.DefaultTrafficSelector; 38 import org.onosproject.net.flow.DefaultTrafficSelector;
36 import org.onosproject.net.flow.DefaultTrafficTreatment; 39 import org.onosproject.net.flow.DefaultTrafficTreatment;
37 import org.onosproject.net.flow.TrafficSelector; 40 import org.onosproject.net.flow.TrafficSelector;
...@@ -70,34 +73,36 @@ public class CordFabricManager implements FabricService { ...@@ -70,34 +73,36 @@ public class CordFabricManager implements FabricService {
70 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 73 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
71 protected FlowObjectiveService flowObjectiveService; 74 protected FlowObjectiveService flowObjectiveService;
72 75
73 - private static final int PRIORITY = 50000; 76 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
77 + protected DeviceService deviceService;
74 78
75 - private short openflowPort = 6633; 79 + private InternalDeviceListener deviceListener = new InternalDeviceListener();
80 +
81 + private static final int PRIORITY = 50000;
76 82
77 private short radiusPort = 1812; 83 private short radiusPort = 1812;
78 84
79 private DeviceId fabricDeviceId = DeviceId.deviceId("of:5e3e486e73000187"); 85 private DeviceId fabricDeviceId = DeviceId.deviceId("of:5e3e486e73000187");
80 86
81 - private ConnectPoint oltConnectPoint =
82 - new ConnectPoint(fabricDeviceId, PortNumber.portNumber(2));
83 - private ConnectPoint oltControllerConnectPoint =
84 - new ConnectPoint(fabricDeviceId, PortNumber.portNumber(1));
85 - private ConnectPoint radiusConnectPoint =
86 - new ConnectPoint(fabricDeviceId, PortNumber.portNumber(5));
87 -
88 private final Multimap<VlanId, ConnectPoint> vlans = HashMultimap.create(); 87 private final Multimap<VlanId, ConnectPoint> vlans = HashMultimap.create();
89 88
90 @Activate 89 @Activate
91 public void activate() { 90 public void activate() {
92 appId = coreService.registerApplication("org.onosproject.cordfabric"); 91 appId = coreService.registerApplication("org.onosproject.cordfabric");
93 92
94 - setupDefaultFlows(); 93 + deviceService.addListener(deviceListener);
94 +
95 + if (deviceService.isAvailable(fabricDeviceId)) {
96 + setupDefaultFlows();
97 + }
95 98
96 log.info("Started"); 99 log.info("Started");
97 } 100 }
98 101
99 @Deactivate 102 @Deactivate
100 public void deactivate() { 103 public void deactivate() {
104 + deviceService.removeListener(deviceListener);
105 +
101 log.info("Stopped"); 106 log.info("Stopped");
102 } 107 }
103 108
...@@ -112,8 +117,6 @@ public class CordFabricManager implements FabricService { ...@@ -112,8 +117,6 @@ public class CordFabricManager implements FabricService {
112 .punt() 117 .punt()
113 .build(); 118 .build();
114 119
115 -
116 -
117 ForwardingObjective ofToController = DefaultForwardingObjective.builder() 120 ForwardingObjective ofToController = DefaultForwardingObjective.builder()
118 .fromApp(appId) 121 .fromApp(appId)
119 .makePermanent() 122 .makePermanent()
...@@ -123,7 +126,6 @@ public class CordFabricManager implements FabricService { ...@@ -123,7 +126,6 @@ public class CordFabricManager implements FabricService {
123 .withTreatment(forwardToController) 126 .withTreatment(forwardToController)
124 .add(); 127 .add();
125 128
126 -
127 flowObjectiveService.forward(fabricDeviceId, ofToController); 129 flowObjectiveService.forward(fabricDeviceId, ofToController);
128 } 130 }
129 131
...@@ -223,4 +225,23 @@ public class CordFabricManager implements FabricService { ...@@ -223,4 +225,23 @@ public class CordFabricManager implements FabricService {
223 log.info("Flow objective operation failed: {}", objective); 225 log.info("Flow objective operation failed: {}", objective);
224 } 226 }
225 } 227 }
228 +
229 + /**
230 + * Internal listener for device service events.
231 + */
232 + private class InternalDeviceListener implements DeviceListener {
233 + @Override
234 + public void event(DeviceEvent event) {
235 + switch (event.type()) {
236 + case DEVICE_ADDED:
237 + case DEVICE_AVAILABILITY_CHANGED:
238 + if (event.subject().id().equals(fabricDeviceId) &&
239 + deviceService.isAvailable(event.subject().id())) {
240 + setupDefaultFlows();
241 + }
242 + default:
243 + break;
244 + }
245 + }
246 + }
226 } 247 }
......