alshabib

portStatusChanged implemented

1 package org.onlab.onos.of.controller; 1 package org.onlab.onos.of.controller;
2 2
3 +import org.projectfloodlight.openflow.protocol.OFPortStatus;
4 +
3 /** 5 /**
4 * Allows for providers interested in Switch events to be notified. 6 * Allows for providers interested in Switch events to be notified.
5 */ 7 */
...@@ -17,4 +19,10 @@ public interface OpenFlowSwitchListener { ...@@ -17,4 +19,10 @@ public interface OpenFlowSwitchListener {
17 */ 19 */
18 public void switchRemoved(Dpid dpid); 20 public void switchRemoved(Dpid dpid);
19 21
22 + /**
23 + * Notify that a port has changed.
24 + * @param dpid the switch on which the change happened.
25 + * @param status the new state of the port.
26 + */
27 + public void portChanged(Dpid dpid, OFPortStatus status);
20 } 28 }
......
...@@ -33,6 +33,7 @@ import org.onlab.onos.of.controller.RoleState; ...@@ -33,6 +33,7 @@ import org.onlab.onos.of.controller.RoleState;
33 import org.projectfloodlight.openflow.protocol.OFPortConfig; 33 import org.projectfloodlight.openflow.protocol.OFPortConfig;
34 import org.projectfloodlight.openflow.protocol.OFPortDesc; 34 import org.projectfloodlight.openflow.protocol.OFPortDesc;
35 import org.projectfloodlight.openflow.protocol.OFPortState; 35 import org.projectfloodlight.openflow.protocol.OFPortState;
36 +import org.projectfloodlight.openflow.protocol.OFPortStatus;
36 import org.slf4j.Logger; 37 import org.slf4j.Logger;
37 38
38 /** 39 /**
...@@ -130,6 +131,18 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr ...@@ -130,6 +131,18 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
130 providerService.deviceDisconnected(deviceId(uri)); 131 providerService.deviceDisconnected(deviceId(uri));
131 } 132 }
132 133
134 + @Override
135 + public void portChanged(Dpid dpid, OFPortStatus status) {
136 + final PortDescription portDescription = buildPortDescription(status.getDesc());
137 + final URI uri = buildURI(dpid);
138 + providerService.portStatusChanged(deviceId(uri), portDescription);
139 + }
140 +
141 + /**
142 + * Given a dpid builds a URI for the device.
143 + * @param dpid the dpid to build the uri from
144 + * @return returns a uri of the form of:<dpidHexForm>
145 + */
133 private URI buildURI(Dpid dpid) { 146 private URI buildURI(Dpid dpid) {
134 URI uri = null; 147 URI uri = null;
135 try { 148 try {
...@@ -140,21 +153,31 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr ...@@ -140,21 +153,31 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
140 return uri; 153 return uri;
141 } 154 }
142 155
156 + /**
157 + * Builds a list of port descriptions for a given list of ports.
158 + * @param ports the list of ports
159 + * @return list of portdescriptions
160 + */
143 private List<PortDescription> buildPortDescriptions( 161 private List<PortDescription> buildPortDescriptions(
144 List<OFPortDesc> ports) { 162 List<OFPortDesc> ports) {
145 final List<PortDescription> portDescs = new ArrayList<PortDescription>(); 163 final List<PortDescription> portDescs = new ArrayList<PortDescription>();
146 - PortNumber portNo;
147 - boolean enabled;
148 for (OFPortDesc port : ports) { 164 for (OFPortDesc port : ports) {
149 - portNo = PortNumber.portNumber(port.getPortNo().getPortNumber()); 165 + portDescs.add(buildPortDescription(port));
150 - enabled = !port.getState().contains(OFPortState.LINK_DOWN) &&
151 - !port.getConfig().contains(OFPortConfig.PORT_DOWN);
152 - portDescs.add(new DefaultPortDescription(portNo,
153 - enabled));
154 } 166 }
155 return portDescs; 167 return portDescs;
156 } 168 }
157 169
170 + /**
171 + * Build a portDescription from a given port.
172 + * @param port the port to build from.
173 + * @return portDescription for the port.
174 + */
175 + private PortDescription buildPortDescription(OFPortDesc port) {
176 + final PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber());
177 + final boolean enabled = !port.getState().contains(OFPortState.LINK_DOWN) &&
178 + !port.getConfig().contains(OFPortConfig.PORT_DOWN);
179 + return new DefaultPortDescription(portNo, enabled);
180 + }
158 } 181 }
159 182
160 } 183 }
......