HIGUCHI Yuta | ed49ef7 | 2013-06-12 11:34:10 -0700 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.core.internal; |
Pankaj Berde | 3200ea0 | 2013-01-04 15:48:36 -0800 | [diff] [blame] | 2 | |
Pavlin Radoslavov | 64647d2 | 2013-11-04 19:07:03 -0800 | [diff] [blame^] | 3 | import java.util.ArrayList; |
| 4 | import java.util.List; |
| 5 | |
Pankaj Berde | bbd3861 | 2013-06-22 05:59:12 -0700 | [diff] [blame] | 6 | import net.floodlightcontroller.core.IOFSwitch; |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 7 | import net.onrc.onos.graph.GraphDBConnection; |
| 8 | import net.onrc.onos.graph.GraphDBOperation; |
HIGUCHI Yuta | 2051490 | 2013-06-12 11:24:16 -0700 | [diff] [blame] | 9 | import net.onrc.onos.ofcontroller.core.ISwitchStorage; |
| 10 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IPortObject; |
| 11 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject; |
Pankaj Berde | afb2053 | 2013-01-08 15:05:24 -0800 | [diff] [blame] | 12 | |
Pankaj Berde | 3200ea0 | 2013-01-04 15:48:36 -0800 | [diff] [blame] | 13 | import org.openflow.protocol.OFPhysicalPort; |
Pankaj Berde | 6a4075d | 2013-01-22 16:42:54 -0800 | [diff] [blame] | 14 | import org.openflow.protocol.OFPhysicalPort.OFPortConfig; |
| 15 | import org.openflow.protocol.OFPhysicalPort.OFPortState; |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 16 | import org.slf4j.Logger; |
| 17 | import org.slf4j.LoggerFactory; |
Pankaj Berde | 3200ea0 | 2013-01-04 15:48:36 -0800 | [diff] [blame] | 18 | |
Teru | ef33dc3 | 2013-06-20 09:54:37 -0700 | [diff] [blame] | 19 | /** |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 20 | * This is the class for storing the information of switches into GraphDB |
Teru | ef33dc3 | 2013-06-20 09:54:37 -0700 | [diff] [blame] | 21 | */ |
Pankaj Berde | 3200ea0 | 2013-01-04 15:48:36 -0800 | [diff] [blame] | 22 | public class SwitchStorageImpl implements ISwitchStorage { |
Toshio Koide | 4f3d9eb | 2013-06-13 13:20:55 -0700 | [diff] [blame] | 23 | protected GraphDBOperation op; |
Yuta HIGUCHI | 6ac8d18 | 2013-10-22 15:24:56 -0700 | [diff] [blame] | 24 | protected final static Logger log = LoggerFactory.getLogger(SwitchStorageImpl.class); |
Teru | ef33dc3 | 2013-06-20 09:54:37 -0700 | [diff] [blame] | 25 | |
| 26 | /*** |
| 27 | * Initialize function. Before you use this class, please call this method |
| 28 | * @param conf configuration file for Cassandra DB |
| 29 | */ |
Pankaj Berde | 3200ea0 | 2013-01-04 15:48:36 -0800 | [diff] [blame] | 30 | @Override |
Teru | ef33dc3 | 2013-06-20 09:54:37 -0700 | [diff] [blame] | 31 | public void init(String conf) { |
| 32 | GraphDBConnection conn = GraphDBConnection.getInstance(conf); |
| 33 | op = new GraphDBOperation(conn); |
| 34 | } |
Pankaj Berde | 3200ea0 | 2013-01-04 15:48:36 -0800 | [diff] [blame] | 35 | |
Teru | ef33dc3 | 2013-06-20 09:54:37 -0700 | [diff] [blame] | 36 | /*** |
| 37 | * Finalize/close function. After you use this class, please call this method. |
| 38 | * It will close the DB connection. |
| 39 | */ |
| 40 | public void finalize() { |
| 41 | close(); |
| 42 | } |
| 43 | |
| 44 | /*** |
| 45 | * Finalize/close function. After you use this class, please call this method. |
Pavlin Radoslavov | ef0cb00 | 2013-06-21 14:55:23 -0700 | [diff] [blame] | 46 | * It will close the DB connection. This is for Java garbage collection. |
Teru | ef33dc3 | 2013-06-20 09:54:37 -0700 | [diff] [blame] | 47 | */ |
| 48 | @Override |
| 49 | public void close() { |
| 50 | op.close(); |
| 51 | } |
| 52 | |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 53 | // Method designing policy: |
| 54 | // op.commit() and op.rollback() MUST called in public (first-class) methods. |
| 55 | // A first-class method MUST NOT call other first-class method. |
| 56 | // Routine process should be implemented in private method. |
| 57 | // A private method MUST NOT call commit or rollback. |
| 58 | |
Teru | ef33dc3 | 2013-06-20 09:54:37 -0700 | [diff] [blame] | 59 | /*** |
Teru | ef33dc3 | 2013-06-20 09:54:37 -0700 | [diff] [blame] | 60 | * This function is for updating the switch into the DB. |
| 61 | * @param dpid The switch dpid you want to update from the DB |
| 62 | * @param state The state of the switch like ACTIVE, INACTIVE |
| 63 | * @param dmope The DM_OPERATION of the switch |
| 64 | */ |
| 65 | @Override |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 66 | public boolean updateSwitch(String dpid, SwitchState state, DM_OPERATION dmope) { |
| 67 | boolean success = false; |
| 68 | ISwitchObject sw = null; |
| 69 | |
| 70 | log.info("SwitchStorage:update {} dpid:{}", dmope, dpid); |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 71 | switch(dmope) { |
| 72 | case UPDATE: |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 73 | try { |
| 74 | sw = op.searchSwitch(dpid); |
| 75 | if (sw != null) { |
| 76 | setSwitchStateImpl(sw, state); |
| 77 | op.commit(); |
| 78 | success = true; |
| 79 | } |
| 80 | } catch (Exception e) { |
| 81 | op.rollback(); |
| 82 | e.printStackTrace(); |
| 83 | log.info("SwitchStorage:update {} dpid:{} failed", dmope, dpid); |
| 84 | } |
| 85 | break; |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 86 | case INSERT: |
| 87 | case CREATE: |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 88 | try { |
| 89 | sw = addSwitchImpl(dpid); |
| 90 | if (sw != null) { |
| 91 | if (state != SwitchState.ACTIVE) { |
| 92 | setSwitchStateImpl(sw, state); |
| 93 | } |
| 94 | op.commit(); |
| 95 | success = true; |
| 96 | } |
| 97 | } catch (Exception e) { |
| 98 | op.rollback(); |
| 99 | e.printStackTrace(); |
| 100 | log.info("SwitchStorage:update {} dpid:{} failed", dmope, dpid); |
| 101 | } |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 102 | break; |
| 103 | case DELETE: |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 104 | try { |
| 105 | sw = op.searchSwitch(dpid); |
| 106 | if (sw != null) { |
| 107 | deleteSwitchImpl(sw); |
| 108 | op.commit(); |
| 109 | success = true; |
| 110 | } |
| 111 | } catch (Exception e) { |
| 112 | op.rollback(); |
| 113 | e.printStackTrace(); |
| 114 | log.info("SwitchStorage:update {} dpid:{} failed", dmope, dpid); |
| 115 | } |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 116 | break; |
| 117 | default: |
| 118 | } |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 119 | |
| 120 | return success; |
| 121 | } |
| 122 | |
| 123 | @Override |
| 124 | public boolean addSwitch(IOFSwitch sw) { |
| 125 | boolean success = false; |
| 126 | |
| 127 | String dpid = sw.getStringId(); |
| 128 | log.info("SwitchStorage:addSwitch(): dpid {} ", dpid); |
| 129 | |
| 130 | try { |
| 131 | ISwitchObject curr = op.searchSwitch(dpid); |
| 132 | if (curr != null) { |
| 133 | //If existing the switch. set The SW state ACTIVE. |
| 134 | log.info("SwitchStorage:addSwitch dpid:{} already exists", dpid); |
| 135 | setSwitchStateImpl(curr, SwitchState.ACTIVE); |
| 136 | } else { |
| 137 | curr = addSwitchImpl(dpid); |
| 138 | } |
| 139 | |
| 140 | for (OFPhysicalPort port: sw.getPorts()) { |
| 141 | IPortObject p = op.searchPort(dpid, port.getPortNumber()); |
| 142 | if (p != null) { |
Jonathan Hart | 13ccdca | 2013-10-30 15:23:28 -0700 | [diff] [blame] | 143 | log.debug("SwitchStorage:addPort dpid:{} port:{} exists", dpid, port.getPortNumber()); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 144 | setPortStateImpl(p, port.getState(), port.getName()); |
| 145 | p.setState("ACTIVE"); |
Jonathan Hart | 13ccdca | 2013-10-30 15:23:28 -0700 | [diff] [blame] | 146 | if (curr.getPort(port.getPortNumber()) == null) { |
| 147 | // The port exists but the switch has no "on" link to it |
| 148 | curr.addPort(p); |
| 149 | } |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 150 | } else { |
| 151 | p = addPortImpl(curr, port.getPortNumber()); |
| 152 | setPortStateImpl(p, port.getState(), port.getName()); |
| 153 | } |
| 154 | } |
| 155 | op.commit(); |
| 156 | success = true; |
| 157 | } catch (Exception e) { |
| 158 | op.rollback(); |
Jonathan Hart | 13ccdca | 2013-10-30 15:23:28 -0700 | [diff] [blame] | 159 | //e.printStackTrace(); |
| 160 | log.error("SwitchStorage:addSwitch dpid:{} failed: {}", dpid); |
| 161 | log.error("switch write error", e); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | return success; |
| 165 | } |
| 166 | |
| 167 | /*** |
| 168 | * This function is for adding the switch into the DB. |
| 169 | * @param dpid The switch dpid you want to add into the DB. |
| 170 | */ |
Jonathan Hart | 13ccdca | 2013-10-30 15:23:28 -0700 | [diff] [blame] | 171 | // This method is only called by tests, so we probably don't need it. |
| 172 | // If we need both addSwitch interfaces, one should call the other |
| 173 | // rather than implementing the same logic twice. |
| 174 | @Deprecated |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 175 | @Override |
| 176 | public boolean addSwitch(String dpid) { |
| 177 | boolean success = false; |
| 178 | |
| 179 | log.info("SwitchStorage:addSwitch(): dpid {} ", dpid); |
| 180 | try { |
| 181 | ISwitchObject sw = op.searchSwitch(dpid); |
| 182 | if (sw != null) { |
| 183 | //If existing the switch. set The SW state ACTIVE. |
| 184 | log.info("SwitchStorage:addSwitch dpid:{} already exists", dpid); |
| 185 | setSwitchStateImpl(sw, SwitchState.ACTIVE); |
| 186 | } else { |
| 187 | addSwitchImpl(dpid); |
| 188 | } |
| 189 | op.commit(); |
| 190 | success = true; |
| 191 | } catch (Exception e) { |
| 192 | op.rollback(); |
| 193 | e.printStackTrace(); |
| 194 | log.info("SwitchStorage:addSwitch dpid:{} failed", dpid); |
| 195 | } |
| 196 | |
| 197 | return success; |
| 198 | } |
| 199 | |
| 200 | /*** |
| 201 | * This function is for deleting the switch into the DB. |
| 202 | * @param dpid The switch dpid you want to delete from the DB. |
| 203 | */ |
| 204 | @Override |
| 205 | public boolean deleteSwitch(String dpid) { |
| 206 | boolean success = false; |
| 207 | |
| 208 | try { |
| 209 | ISwitchObject sw = op.searchSwitch(dpid); |
| 210 | if (sw != null) { |
| 211 | deleteSwitchImpl(sw); |
| 212 | op.commit(); |
| 213 | } |
| 214 | success = true; |
| 215 | } catch (Exception e) { |
| 216 | op.rollback(); |
| 217 | e.printStackTrace(); |
| 218 | log.error("SwitchStorage:deleteSwitch {} failed", dpid); |
| 219 | } |
| 220 | |
| 221 | return success; |
| 222 | } |
| 223 | |
| 224 | public boolean updatePort(String dpid, short portNum, int state, String desc) { |
| 225 | boolean success = false; |
| 226 | |
| 227 | try { |
| 228 | ISwitchObject sw = op.searchSwitch(dpid); |
| 229 | |
| 230 | if (sw != null) { |
| 231 | IPortObject p = sw.getPort(portNum); |
| 232 | log.info("SwitchStorage:updatePort dpid:{} port:{}", dpid, portNum); |
| 233 | if (p != null) { |
| 234 | setPortStateImpl(p, state, desc); |
| 235 | } |
| 236 | op.commit(); |
| 237 | success = true; |
| 238 | } else { |
| 239 | log.error("SwitchStorage:updatePort dpid:{} port:{} : failed switch does not exist", dpid, portNum); |
| 240 | } |
| 241 | } catch (Exception e) { |
| 242 | op.rollback(); |
| 243 | e.printStackTrace(); |
| 244 | log.error("SwitchStorage:addPort dpid:{} port:{} failed", dpid, portNum); |
| 245 | } |
| 246 | |
| 247 | return success; |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | /*** |
| 251 | * This function is for adding the switch port into the DB. |
| 252 | * @param dpid The switch dpid that has the port. |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 253 | * @param phport The port you want to add the switch. |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 254 | */ |
| 255 | @Override |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 256 | public boolean addPort(String dpid, OFPhysicalPort phport) { |
| 257 | boolean success = false; |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 258 | |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 259 | if(((OFPortConfig.OFPPC_PORT_DOWN.getValue() & phport.getConfig()) > 0) || |
| 260 | ((OFPortState.OFPPS_LINK_DOWN.getValue() & phport.getState()) > 0)) { |
| 261 | // just dispatch to deletePort() |
| 262 | return deletePort(dpid, phport.getPortNumber()); |
| 263 | } |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 264 | |
| 265 | try { |
| 266 | ISwitchObject sw = op.searchSwitch(dpid); |
| 267 | |
| 268 | if (sw != null) { |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 269 | IPortObject p = sw.getPort(phport.getPortNumber()); |
| 270 | log.info("SwitchStorage:addPort dpid:{} port:{}", dpid, phport.getPortNumber()); |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 271 | if (p != null) { |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 272 | setPortStateImpl(p, phport.getState(), phport.getName()); |
| 273 | log.error("SwitchStorage:addPort dpid:{} port:{} exists setting as ACTIVE", dpid, phport.getPortNumber()); |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 274 | } else { |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 275 | addPortImpl(sw, phport.getPortNumber()); |
| 276 | setPortStateImpl(p, phport.getState(), phport.getName()); |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 277 | } |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 278 | op.commit(); |
| 279 | success = true; |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 280 | } else { |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 281 | log.error("SwitchStorage:addPort dpid:{} port:{} : failed switch does not exist", dpid, phport.getPortNumber()); |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 282 | } |
| 283 | } catch (Exception e) { |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 284 | op.rollback(); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 285 | e.printStackTrace(); |
| 286 | log.error("SwitchStorage:addPort dpid:{} port:{} failed", dpid, phport.getPortNumber()); |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 287 | } |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 288 | |
| 289 | return success; |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | /*** |
| 293 | * This function is for deleting the switch port from the DB. |
| 294 | * @param dpid The switch dpid that has the port. |
| 295 | * @param port The port you want to delete the switch. |
| 296 | */ |
| 297 | @Override |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 298 | public boolean deletePort(String dpid, short port) { |
| 299 | boolean success = false; |
| 300 | |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 301 | try { |
| 302 | ISwitchObject sw = op.searchSwitch(dpid); |
| 303 | |
| 304 | if (sw != null) { |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 305 | IPortObject p = sw.getPort(port); |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 306 | if (p != null) { |
| 307 | log.info("SwitchStorage:deletePort dpid:{} port:{} found and set INACTIVE", dpid, port); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 308 | deletePortImpl(p); |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 309 | op.commit(); |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 310 | } |
| 311 | } |
Pavlin Radoslavov | 3d99e70 | 2013-11-04 15:39:34 -0800 | [diff] [blame] | 312 | success = true; |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 313 | } catch (Exception e) { |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 314 | op.rollback(); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 315 | e.printStackTrace(); |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 316 | log.info("SwitchStorage:deletePort dpid:{} port:{} failed", dpid, port); |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 317 | } |
| 318 | |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 319 | return success; |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 320 | } |
| 321 | |
Pavlin Radoslavov | 64647d2 | 2013-11-04 19:07:03 -0800 | [diff] [blame^] | 322 | /** |
| 323 | * Get list of all ports on the switch specified by given DPID. |
| 324 | * |
| 325 | * @param dpid DPID of desired switch. |
| 326 | * @return List of port IDs. Empty list if no port was found. |
| 327 | */ |
| 328 | @Override |
| 329 | public List<Short> getPorts(String dpid) { |
| 330 | List<Short> ports = new ArrayList<Short>(); |
| 331 | |
| 332 | ISwitchObject srcSw = op.searchSwitch(dpid); |
| 333 | if (srcSw != null) { |
| 334 | for (IPortObject srcPort : srcSw.getPorts()) { |
| 335 | ports.add(srcPort.getNumber()); |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | return ports; |
| 340 | } |
| 341 | |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 342 | private ISwitchObject addSwitchImpl(String dpid) { |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 343 | if (dpid != null) { |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 344 | ISwitchObject sw = op.newSwitch(dpid); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 345 | sw.setState(SwitchState.ACTIVE.toString()); |
| 346 | log.info("SwitchStorage:addSwitchImpl dpid:{} added", dpid); |
| 347 | return sw; |
| 348 | } else { |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 349 | return null; |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | private void setSwitchStateImpl(ISwitchObject sw, SwitchState state) { |
| 354 | if (sw != null && state != null) { |
| 355 | sw.setState(state.toString()); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 356 | log.info("SwitchStorage:setSwitchStateImpl dpid:{} updated {}", |
| 357 | sw.getDPID(), state.toString()); |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 358 | } |
Pankaj Berde | 3200ea0 | 2013-01-04 15:48:36 -0800 | [diff] [blame] | 359 | } |
Teru | ef33dc3 | 2013-06-20 09:54:37 -0700 | [diff] [blame] | 360 | |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 361 | private void deleteSwitchImpl(ISwitchObject sw) { |
| 362 | if (sw != null) { |
| 363 | op.removeSwitch(sw); |
| 364 | log.info("SwitchStorage:DeleteSwitchImpl dpid:{} done", |
| 365 | sw.getDPID()); |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | private IPortObject addPortImpl(ISwitchObject sw, short portNum) { |
| 370 | IPortObject p = op.newPort(sw.getDPID(), portNum); |
| 371 | p.setState("ACTIVE"); |
| 372 | sw.addPort(p); |
| 373 | log.info("SwitchStorage:addPortImpl dpid:{} port:{} done", |
| 374 | sw.getDPID(), portNum); |
| 375 | |
| 376 | return p; |
| 377 | } |
| 378 | |
| 379 | private void setPortStateImpl(IPortObject port, Integer state, String desc) { |
| 380 | if (port != null) { |
| 381 | if (state != null) { |
| 382 | port.setPortState(state); |
| 383 | } |
| 384 | if (desc != null) { |
| 385 | port.setDesc(desc); |
| 386 | } |
| 387 | |
| 388 | log.info("SwitchStorage:setPortStateImpl port:{} state:{} desc:{} done", |
| 389 | new Object[] {port.getPortId(), state, desc}); |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | private void deletePortImpl(IPortObject port) { |
| 394 | if (port != null) { |
| 395 | op.removePort(port); |
| 396 | log.info("SwitchStorage:deletePortImpl port:{} done", |
| 397 | port.getPortId()); |
| 398 | } |
| 399 | } |
Teru | 4fd5864 | 2013-06-21 07:54:49 -0700 | [diff] [blame] | 400 | } |