Showing
16 changed files
with
94 additions
and
27 deletions
... | @@ -219,6 +219,7 @@ public abstract class AbstractOpenFlowSwitch implements OpenFlowSwitchDriver { | ... | @@ -219,6 +219,7 @@ public abstract class AbstractOpenFlowSwitch implements OpenFlowSwitchDriver { |
219 | @Override | 219 | @Override |
220 | public void setRole(RoleState role) { | 220 | public void setRole(RoleState role) { |
221 | try { | 221 | try { |
222 | + log.info("Sending role {} to switch {}", role, getStringId()); | ||
222 | if (this.roleMan.sendRoleRequest(role, RoleRecvStatus.MATCHED_SET_ROLE)) { | 223 | if (this.roleMan.sendRoleRequest(role, RoleRecvStatus.MATCHED_SET_ROLE)) { |
223 | this.role = role; | 224 | this.role = role; |
224 | } | 225 | } | ... | ... |
... | @@ -15,7 +15,7 @@ | ... | @@ -15,7 +15,7 @@ |
15 | * under the License. | 15 | * under the License. |
16 | **/ | 16 | **/ |
17 | 17 | ||
18 | -package org.onlab.onos.of.controller.impl.internal; | 18 | +package org.onlab.onos.of.controller.impl; |
19 | 19 | ||
20 | import java.lang.management.ManagementFactory; | 20 | import java.lang.management.ManagementFactory; |
21 | import java.lang.management.RuntimeMXBean; | 21 | import java.lang.management.RuntimeMXBean; |
... | @@ -34,7 +34,7 @@ import org.onlab.onos.of.controller.driver.OpenFlowAgent; | ... | @@ -34,7 +34,7 @@ import org.onlab.onos.of.controller.driver.OpenFlowAgent; |
34 | import org.onlab.onos.of.controller.driver.OpenFlowSwitchDriver; | 34 | import org.onlab.onos.of.controller.driver.OpenFlowSwitchDriver; |
35 | import org.onlab.onos.of.controller.impl.annotations.LogMessageDoc; | 35 | import org.onlab.onos.of.controller.impl.annotations.LogMessageDoc; |
36 | import org.onlab.onos.of.controller.impl.annotations.LogMessageDocs; | 36 | import org.onlab.onos.of.controller.impl.annotations.LogMessageDocs; |
37 | -import org.onlab.onos.of.drivers.DriverManager; | 37 | +import org.onlab.onos.of.drivers.impl.DriverManager; |
38 | import org.projectfloodlight.openflow.protocol.OFDescStatsReply; | 38 | import org.projectfloodlight.openflow.protocol.OFDescStatsReply; |
39 | import org.projectfloodlight.openflow.protocol.OFFactories; | 39 | import org.projectfloodlight.openflow.protocol.OFFactories; |
40 | import org.projectfloodlight.openflow.protocol.OFFactory; | 40 | import org.projectfloodlight.openflow.protocol.OFFactory; | ... | ... |
... | @@ -15,7 +15,7 @@ | ... | @@ -15,7 +15,7 @@ |
15 | * under the License. | 15 | * under the License. |
16 | **/ | 16 | **/ |
17 | 17 | ||
18 | -package org.onlab.onos.of.controller.impl.internal; | 18 | +package org.onlab.onos.of.controller.impl; |
19 | 19 | ||
20 | /** | 20 | /** |
21 | * Exception is thrown when the handshake fails to complete. | 21 | * Exception is thrown when the handshake fails to complete. | ... | ... |
... | @@ -15,7 +15,7 @@ | ... | @@ -15,7 +15,7 @@ |
15 | * under the License. | 15 | * under the License. |
16 | **/ | 16 | **/ |
17 | 17 | ||
18 | -package org.onlab.onos.of.controller.impl.internal; | 18 | +package org.onlab.onos.of.controller.impl; |
19 | 19 | ||
20 | import java.util.concurrent.TimeUnit; | 20 | import java.util.concurrent.TimeUnit; |
21 | 21 | ... | ... |
1 | -package org.onlab.onos.of.controller.impl.internal; | 1 | +package org.onlab.onos.of.controller.impl; |
2 | 2 | ||
3 | import org.onlab.onos.of.controller.driver.AbstractOpenFlowSwitch; | 3 | import org.onlab.onos.of.controller.driver.AbstractOpenFlowSwitch; |
4 | import org.projectfloodlight.openflow.protocol.OFVersion; | 4 | import org.projectfloodlight.openflow.protocol.OFVersion; | ... | ... |
1 | //CHECKSTYLE:OFF | 1 | //CHECKSTYLE:OFF |
2 | -package org.onlab.onos.of.controller.impl.internal; | 2 | +package org.onlab.onos.of.controller.impl; |
3 | 3 | ||
4 | import java.io.IOException; | 4 | import java.io.IOException; |
5 | import java.nio.channels.ClosedChannelException; | 5 | import java.nio.channels.ClosedChannelException; |
... | @@ -415,17 +415,18 @@ class OFChannelHandler extends IdleStateAwareChannelHandler { | ... | @@ -415,17 +415,18 @@ class OFChannelHandler extends IdleStateAwareChannelHandler { |
415 | OFDescStatsReply drep = (OFDescStatsReply) m; | 415 | OFDescStatsReply drep = (OFDescStatsReply) m; |
416 | // Here is where we differentiate between different kinds of switches | 416 | // Here is where we differentiate between different kinds of switches |
417 | h.sw = h.controller.getOFSwitchInstance(h.thisdpid, drep, h.ofVersion); | 417 | h.sw = h.controller.getOFSwitchInstance(h.thisdpid, drep, h.ofVersion); |
418 | + h.sw.setOFVersion(h.ofVersion); | ||
419 | + h.sw.setFeaturesReply(h.featuresReply); | ||
420 | + h.sw.setPortDescReply(h.portDescReply); | ||
421 | + h.sw.setConnected(true); | ||
422 | + h.sw.setChannel(h.channel); | ||
418 | boolean success = h.sw.connectSwitch(); | 423 | boolean success = h.sw.connectSwitch(); |
419 | if (!success) { | 424 | if (!success) { |
420 | disconnectDuplicate(h); | 425 | disconnectDuplicate(h); |
421 | return; | 426 | return; |
422 | } | 427 | } |
423 | // set switch information | 428 | // set switch information |
424 | - h.sw.setOFVersion(h.ofVersion); | 429 | + |
425 | - h.sw.setFeaturesReply(h.featuresReply); | ||
426 | - h.sw.setPortDescReply(h.portDescReply); | ||
427 | - h.sw.setConnected(true); | ||
428 | - h.sw.setChannel(h.channel); | ||
429 | 430 | ||
430 | 431 | ||
431 | log.info("Switch {} bound to class {}, description {}", | 432 | log.info("Switch {} bound to class {}, description {}", | ... | ... |
... | @@ -15,7 +15,7 @@ | ... | @@ -15,7 +15,7 @@ |
15 | * under the License. | 15 | * under the License. |
16 | **/ | 16 | **/ |
17 | 17 | ||
18 | -package org.onlab.onos.of.controller.impl.internal; | 18 | +package org.onlab.onos.of.controller.impl; |
19 | 19 | ||
20 | 20 | ||
21 | import org.jboss.netty.buffer.ChannelBuffer; | 21 | import org.jboss.netty.buffer.ChannelBuffer; | ... | ... |
1 | -package org.onlab.onos.of.controller.impl.internal; | 1 | +package org.onlab.onos.of.controller.impl; |
2 | 2 | ||
3 | import java.util.ArrayList; | 3 | import java.util.ArrayList; |
4 | import java.util.concurrent.ConcurrentHashMap; | 4 | import java.util.concurrent.ConcurrentHashMap; |
... | @@ -15,7 +15,6 @@ import org.onlab.onos.of.controller.OpenFlowSwitch; | ... | @@ -15,7 +15,6 @@ import org.onlab.onos.of.controller.OpenFlowSwitch; |
15 | import org.onlab.onos.of.controller.OpenFlowSwitchListener; | 15 | import org.onlab.onos.of.controller.OpenFlowSwitchListener; |
16 | import org.onlab.onos.of.controller.PacketListener; | 16 | import org.onlab.onos.of.controller.PacketListener; |
17 | import org.onlab.onos.of.controller.RoleState; | 17 | import org.onlab.onos.of.controller.RoleState; |
18 | -import org.onlab.onos.of.controller.driver.AbstractOpenFlowSwitch; | ||
19 | import org.onlab.onos.of.controller.driver.OpenFlowAgent; | 18 | import org.onlab.onos.of.controller.driver.OpenFlowAgent; |
20 | import org.projectfloodlight.openflow.protocol.OFMessage; | 19 | import org.projectfloodlight.openflow.protocol.OFMessage; |
21 | import org.slf4j.Logger; | 20 | import org.slf4j.Logger; |
... | @@ -68,17 +67,18 @@ public class OpenFlowControllerImpl implements OpenFlowController { | ... | @@ -68,17 +67,18 @@ public class OpenFlowControllerImpl implements OpenFlowController { |
68 | 67 | ||
69 | @Override | 68 | @Override |
70 | public OpenFlowSwitch getSwitch(Dpid dpid) { | 69 | public OpenFlowSwitch getSwitch(Dpid dpid) { |
71 | - return connectedSwitches.get(dpid.value()); | 70 | + return connectedSwitches.get(dpid); |
72 | } | 71 | } |
73 | 72 | ||
74 | @Override | 73 | @Override |
75 | public OpenFlowSwitch getMasterSwitch(Dpid dpid) { | 74 | public OpenFlowSwitch getMasterSwitch(Dpid dpid) { |
76 | - return activeMasterSwitches.get(dpid.value()); | 75 | + return activeMasterSwitches.get(dpid); |
77 | } | 76 | } |
78 | 77 | ||
79 | @Override | 78 | @Override |
80 | public OpenFlowSwitch getEqualSwitch(Dpid dpid) { | 79 | public OpenFlowSwitch getEqualSwitch(Dpid dpid) { |
81 | - return activeEqualSwitches.get(dpid.value()); } | 80 | + return activeEqualSwitches.get(dpid); |
81 | + } | ||
82 | 82 | ||
83 | @Override | 83 | @Override |
84 | public void addListener(OpenFlowSwitchListener listener) { | 84 | public void addListener(OpenFlowSwitchListener listener) { |
... | @@ -116,9 +116,15 @@ public class OpenFlowControllerImpl implements OpenFlowController { | ... | @@ -116,9 +116,15 @@ public class OpenFlowControllerImpl implements OpenFlowController { |
116 | 116 | ||
117 | @Override | 117 | @Override |
118 | public void setRole(Dpid dpid, RoleState role) { | 118 | public void setRole(Dpid dpid, RoleState role) { |
119 | - ((AbstractOpenFlowSwitch) getSwitch(dpid)).setRole(role); | 119 | + getSwitch(dpid).setRole(role); |
120 | } | 120 | } |
121 | 121 | ||
122 | + /** | ||
123 | + * Implementation of an OpenFlow Agent which is responsible for | ||
124 | + * keeping track of connected switches and the state in which | ||
125 | + * they are. | ||
126 | + * | ||
127 | + */ | ||
122 | public class OpenFlowSwitchAgent implements OpenFlowAgent { | 128 | public class OpenFlowSwitchAgent implements OpenFlowAgent { |
123 | 129 | ||
124 | private final Logger log = LoggerFactory.getLogger(OpenFlowSwitchAgent.class); | 130 | private final Logger log = LoggerFactory.getLogger(OpenFlowSwitchAgent.class); |
... | @@ -204,6 +210,7 @@ public class OpenFlowControllerImpl implements OpenFlowController { | ... | @@ -204,6 +210,7 @@ public class OpenFlowControllerImpl implements OpenFlowController { |
204 | + "was not found in controller-cache", dpid); | 210 | + "was not found in controller-cache", dpid); |
205 | return; | 211 | return; |
206 | } | 212 | } |
213 | + log.info("Transitioned switch {} to MASTER", dpid); | ||
207 | activeMasterSwitches.put(dpid, sw); | 214 | activeMasterSwitches.put(dpid, sw); |
208 | } finally { | 215 | } finally { |
209 | switchLock.unlock(); | 216 | switchLock.unlock(); |
... | @@ -224,6 +231,7 @@ public class OpenFlowControllerImpl implements OpenFlowController { | ... | @@ -224,6 +231,7 @@ public class OpenFlowControllerImpl implements OpenFlowController { |
224 | + "was not found in controller-cache", dpid); | 231 | + "was not found in controller-cache", dpid); |
225 | return; | 232 | return; |
226 | } | 233 | } |
234 | + log.info("Transitioned switch {} to EQUAL", dpid); | ||
227 | activeEqualSwitches.put(dpid, sw); | 235 | activeEqualSwitches.put(dpid, sw); |
228 | } finally { | 236 | } finally { |
229 | switchLock.unlock(); | 237 | switchLock.unlock(); | ... | ... |
... | @@ -15,7 +15,7 @@ | ... | @@ -15,7 +15,7 @@ |
15 | * under the License. | 15 | * under the License. |
16 | **/ | 16 | **/ |
17 | 17 | ||
18 | -package org.onlab.onos.of.controller.impl.internal; | 18 | +package org.onlab.onos.of.controller.impl; |
19 | 19 | ||
20 | import java.util.concurrent.ThreadPoolExecutor; | 20 | import java.util.concurrent.ThreadPoolExecutor; |
21 | 21 | ... | ... |
providers/of/device/src/main/java/org/onlab/onos/provider/of/device/impl/OpenFlowDeviceProvider.java
1 | package org.onlab.onos.provider.of.device.impl; | 1 | package org.onlab.onos.provider.of.device.impl; |
2 | 2 | ||
3 | +import static org.slf4j.LoggerFactory.getLogger; | ||
4 | + | ||
5 | +import java.net.URI; | ||
6 | +import java.net.URISyntaxException; | ||
7 | + | ||
3 | import org.apache.felix.scr.annotations.Activate; | 8 | import org.apache.felix.scr.annotations.Activate; |
4 | import org.apache.felix.scr.annotations.Component; | 9 | import org.apache.felix.scr.annotations.Component; |
5 | import org.apache.felix.scr.annotations.Deactivate; | 10 | import org.apache.felix.scr.annotations.Deactivate; |
6 | import org.apache.felix.scr.annotations.Reference; | 11 | import org.apache.felix.scr.annotations.Reference; |
7 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 12 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
8 | import org.onlab.onos.net.Device; | 13 | import org.onlab.onos.net.Device; |
14 | +import org.onlab.onos.net.DeviceId; | ||
9 | import org.onlab.onos.net.MastershipRole; | 15 | import org.onlab.onos.net.MastershipRole; |
16 | +import org.onlab.onos.net.device.DeviceDescription; | ||
10 | import org.onlab.onos.net.device.DeviceProvider; | 17 | import org.onlab.onos.net.device.DeviceProvider; |
11 | import org.onlab.onos.net.device.DeviceProviderRegistry; | 18 | import org.onlab.onos.net.device.DeviceProviderRegistry; |
12 | import org.onlab.onos.net.device.DeviceProviderService; | 19 | import org.onlab.onos.net.device.DeviceProviderService; |
13 | import org.onlab.onos.net.provider.AbstractProvider; | 20 | import org.onlab.onos.net.provider.AbstractProvider; |
14 | import org.onlab.onos.net.provider.ProviderId; | 21 | import org.onlab.onos.net.provider.ProviderId; |
22 | +import org.onlab.onos.of.controller.Dpid; | ||
15 | import org.onlab.onos.of.controller.OpenFlowController; | 23 | import org.onlab.onos.of.controller.OpenFlowController; |
24 | +import org.onlab.onos.of.controller.OpenFlowSwitchListener; | ||
25 | +import org.onlab.onos.of.controller.RoleState; | ||
16 | import org.slf4j.Logger; | 26 | import org.slf4j.Logger; |
17 | 27 | ||
18 | -import static org.slf4j.LoggerFactory.getLogger; | ||
19 | - | ||
20 | /** | 28 | /** |
21 | * Provider which uses an OpenFlow controller to detect network | 29 | * Provider which uses an OpenFlow controller to detect network |
22 | * infrastructure devices. | 30 | * infrastructure devices. |
... | @@ -44,6 +52,7 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr | ... | @@ -44,6 +52,7 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr |
44 | @Activate | 52 | @Activate |
45 | public void activate() { | 53 | public void activate() { |
46 | providerService = providerRegistry.register(this); | 54 | providerService = providerRegistry.register(this); |
55 | + controller.addListener(new InternalDeviceProvider()); | ||
47 | log.info("Started"); | 56 | log.info("Started"); |
48 | } | 57 | } |
49 | 58 | ||
... | @@ -61,7 +70,55 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr | ... | @@ -61,7 +70,55 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr |
61 | 70 | ||
62 | @Override | 71 | @Override |
63 | public void roleChanged(Device device, MastershipRole newRole) { | 72 | public void roleChanged(Device device, MastershipRole newRole) { |
73 | + switch (newRole) { | ||
74 | + case MASTER: | ||
75 | + controller.setRole(new Dpid(device.id().uri().getSchemeSpecificPart()), | ||
76 | + RoleState.MASTER); | ||
77 | + break; | ||
78 | + case STANDBY: | ||
79 | + controller.setRole(new Dpid(device.id().uri().getSchemeSpecificPart()), | ||
80 | + RoleState.EQUAL); | ||
81 | + case NONE: | ||
82 | + controller.setRole(new Dpid(device.id().uri().getSchemeSpecificPart()), | ||
83 | + RoleState.SLAVE); | ||
84 | + break; | ||
85 | + default: | ||
86 | + log.error("Unknown Mastership state : {}", newRole); | ||
87 | + | ||
88 | + } | ||
64 | log.info("Accepting mastership role change for device {}", device.id()); | 89 | log.info("Accepting mastership role change for device {}", device.id()); |
65 | } | 90 | } |
66 | 91 | ||
92 | + private class InternalDeviceProvider implements OpenFlowSwitchListener { | ||
93 | + | ||
94 | + @Override | ||
95 | + public void switchAdded(final Dpid dpid) { | ||
96 | + URI uri = buildURI(dpid); | ||
97 | + providerService.deviceConnected(new DeviceId(uri), new DeviceDescription() { | ||
98 | + | ||
99 | + @Override | ||
100 | + public URI deviceURI() { | ||
101 | + return buildURI(dpid); | ||
102 | + } | ||
103 | + }); | ||
104 | + } | ||
105 | + | ||
106 | + @Override | ||
107 | + public void switchRemoved(Dpid dpid) { | ||
108 | + URI uri = buildURI(dpid); | ||
109 | + providerService.deviceDisconnected(new DeviceId(uri)); | ||
110 | + } | ||
111 | + | ||
112 | + private URI buildURI(Dpid dpid) { | ||
113 | + URI uri = null; | ||
114 | + try { | ||
115 | + uri = new URI("of", Long.toHexString(dpid.value()), null); | ||
116 | + } catch (URISyntaxException e) { | ||
117 | + log.warn("URI construction for device {} failed.", dpid); | ||
118 | + } | ||
119 | + return uri; | ||
120 | + } | ||
121 | + | ||
122 | + } | ||
123 | + | ||
67 | } | 124 | } | ... | ... |
-
Please register or login to post a comment