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 | |
Masayoshi Kobayashi | 536d72e | 2014-01-06 13:15:52 -0800 | [diff] [blame] | 6 | import com.tinkerpop.blueprints.impls.ramcloud.PerfMon; |
| 7 | |
Pankaj Berde | bbd3861 | 2013-06-22 05:59:12 -0700 | [diff] [blame] | 8 | import net.floodlightcontroller.core.IOFSwitch; |
yoshi | 2fd4c7e | 2013-11-22 15:47:55 -0800 | [diff] [blame] | 9 | import net.onrc.onos.graph.DBOperation; |
| 10 | import net.onrc.onos.graph.GraphDBManager; |
HIGUCHI Yuta | 2051490 | 2013-06-12 11:24:16 -0700 | [diff] [blame] | 11 | import net.onrc.onos.ofcontroller.core.ISwitchStorage; |
Jonathan Hart | 1a6f1d6 | 2013-11-14 11:33:46 -0800 | [diff] [blame] | 12 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IDeviceObject; |
HIGUCHI Yuta | 2051490 | 2013-06-12 11:24:16 -0700 | [diff] [blame] | 13 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IPortObject; |
| 14 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject; |
Jonathan Hart | 1a6f1d6 | 2013-11-14 11:33:46 -0800 | [diff] [blame] | 15 | import net.onrc.onos.ofcontroller.core.ISwitchStorage; |
Pankaj Berde | afb2053 | 2013-01-08 15:05:24 -0800 | [diff] [blame] | 16 | |
Pankaj Berde | 3200ea0 | 2013-01-04 15:48:36 -0800 | [diff] [blame] | 17 | import org.openflow.protocol.OFPhysicalPort; |
Pankaj Berde | 6a4075d | 2013-01-22 16:42:54 -0800 | [diff] [blame] | 18 | import org.openflow.protocol.OFPhysicalPort.OFPortConfig; |
| 19 | import org.openflow.protocol.OFPhysicalPort.OFPortState; |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 20 | import org.slf4j.Logger; |
| 21 | import org.slf4j.LoggerFactory; |
Pankaj Berde | 3200ea0 | 2013-01-04 15:48:36 -0800 | [diff] [blame] | 22 | |
Teru | ef33dc3 | 2013-06-20 09:54:37 -0700 | [diff] [blame] | 23 | /** |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 24 | * This is the class for storing the information of switches into GraphDB |
Teru | ef33dc3 | 2013-06-20 09:54:37 -0700 | [diff] [blame] | 25 | */ |
Pankaj Berde | 3200ea0 | 2013-01-04 15:48:36 -0800 | [diff] [blame] | 26 | public class SwitchStorageImpl implements ISwitchStorage { |
Pankaj Berde | 3200ea0 | 2013-01-04 15:48:36 -0800 | [diff] [blame] | 27 | |
yoshi | 0fee3de | 2013-11-23 09:13:37 -0800 | [diff] [blame] | 28 | protected DBOperation op; |
Yuta HIGUCHI | 6ac8d18 | 2013-10-22 15:24:56 -0700 | [diff] [blame] | 29 | protected final static Logger log = LoggerFactory.getLogger(SwitchStorageImpl.class); |
yoshi | d76fa1f | 2013-12-19 14:20:34 -0800 | [diff] [blame] | 30 | public final long measureONOSTimeProp = Long.valueOf(System.getProperty("benchmark.measureONOS", "0")); |
Masayoshi Kobayashi | 536d72e | 2014-01-06 13:15:52 -0800 | [diff] [blame] | 31 | public final long measureAllTimeProp = Long.valueOf(System.getProperty("benchmark.measureAll", "0")); |
| 32 | |
| 33 | private static PerfMon pm = PerfMon.getInstance(); |
Teru | ef33dc3 | 2013-06-20 09:54:37 -0700 | [diff] [blame] | 34 | |
Pankaj Berde | 3200ea0 | 2013-01-04 15:48:36 -0800 | [diff] [blame] | 35 | /*** |
| 36 | * Initialize function. Before you use this class, please call this method |
| 37 | * @param conf configuration file for Cassandra DB |
| 38 | */ |
| 39 | @Override |
yoshi | 0fee3de | 2013-11-23 09:13:37 -0800 | [diff] [blame] | 40 | public void init(final String dbStore, final String conf) { |
yoshi | d38cd31 | 2013-12-02 19:54:44 -0800 | [diff] [blame] | 41 | op = GraphDBManager.getDBOperation("ramcloud", "/tmp/ramcloudconf"); |
| 42 | //op = GraphDBManager.getDBOperation(dbStore, conf); |
Pankaj Berde | 3200ea0 | 2013-01-04 15:48:36 -0800 | [diff] [blame] | 43 | } |
yoshi | 2fd4c7e | 2013-11-22 15:47:55 -0800 | [diff] [blame] | 44 | |
yoshi | 2fd4c7e | 2013-11-22 15:47:55 -0800 | [diff] [blame] | 45 | |
Teru | ef33dc3 | 2013-06-20 09:54:37 -0700 | [diff] [blame] | 46 | /*** |
| 47 | * Finalize/close function. After you use this class, please call this method. |
| 48 | * It will close the DB connection. |
| 49 | */ |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 50 | @Override |
Yuta HIGUCHI | 67a7a3e | 2014-01-03 14:51:34 -0800 | [diff] [blame] | 51 | protected void finalize() { |
Teru | ef33dc3 | 2013-06-20 09:54:37 -0700 | [diff] [blame] | 52 | close(); |
| 53 | } |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 54 | |
Teru | ef33dc3 | 2013-06-20 09:54:37 -0700 | [diff] [blame] | 55 | /*** |
| 56 | * Finalize/close function. After you use this class, please call this method. |
| 57 | * It will close the DB connection. This is for Java garbage collection. |
| 58 | */ |
| 59 | @Override |
| 60 | public void close() { |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 61 | op.close(); |
Teru | ef33dc3 | 2013-06-20 09:54:37 -0700 | [diff] [blame] | 62 | } |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 63 | |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 64 | // Method designing policy: |
| 65 | // op.commit() and op.rollback() MUST called in public (first-class) methods. |
| 66 | // A first-class method MUST NOT call other first-class method. |
| 67 | // Routine process should be implemented in private method. |
| 68 | // A private method MUST NOT call commit or rollback. |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 69 | |
Teru | ef33dc3 | 2013-06-20 09:54:37 -0700 | [diff] [blame] | 70 | /*** |
Teru | ef33dc3 | 2013-06-20 09:54:37 -0700 | [diff] [blame] | 71 | * This function is for updating the switch into the DB. |
| 72 | * @param dpid The switch dpid you want to update from the DB |
| 73 | * @param state The state of the switch like ACTIVE, INACTIVE |
| 74 | * @param dmope The DM_OPERATION of the switch |
| 75 | */ |
Jonathan Hart | adc6389 | 2013-11-08 14:03:55 -0800 | [diff] [blame] | 76 | /* |
| 77 | * Jono, 11/8/2013 |
| 78 | * We don't need this update method that demultiplexes DM_OPERATIONS, |
| 79 | * we can have clients just call the required methods directly. |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 80 | * We especially don't need this update method to re-implement |
Jonathan Hart | adc6389 | 2013-11-08 14:03:55 -0800 | [diff] [blame] | 81 | * the functions of other methods. |
| 82 | */ |
| 83 | @Deprecated |
Teru | ef33dc3 | 2013-06-20 09:54:37 -0700 | [diff] [blame] | 84 | @Override |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 85 | public boolean updateSwitch(String dpid, SwitchState state, DM_OPERATION dmope) { |
| 86 | boolean success = false; |
| 87 | ISwitchObject sw = null; |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 88 | |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 89 | log.info("SwitchStorage:update {} dpid:{}", dmope, dpid); |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 90 | switch(dmope) { |
| 91 | case UPDATE: |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 92 | try { |
| 93 | sw = op.searchSwitch(dpid); |
| 94 | if (sw != null) { |
| 95 | setSwitchStateImpl(sw, state); |
| 96 | op.commit(); |
| 97 | success = true; |
| 98 | } |
| 99 | } catch (Exception e) { |
| 100 | op.rollback(); |
| 101 | e.printStackTrace(); |
| 102 | log.info("SwitchStorage:update {} dpid:{} failed", dmope, dpid); |
| 103 | } |
| 104 | break; |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 105 | case INSERT: |
| 106 | case CREATE: |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 107 | try { |
| 108 | sw = addSwitchImpl(dpid); |
| 109 | if (sw != null) { |
| 110 | if (state != SwitchState.ACTIVE) { |
| 111 | setSwitchStateImpl(sw, state); |
| 112 | } |
| 113 | op.commit(); |
| 114 | success = true; |
| 115 | } |
| 116 | } catch (Exception e) { |
| 117 | op.rollback(); |
| 118 | e.printStackTrace(); |
| 119 | log.info("SwitchStorage:update {} dpid:{} failed", dmope, dpid); |
| 120 | } |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 121 | break; |
| 122 | case DELETE: |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 123 | try { |
| 124 | sw = op.searchSwitch(dpid); |
| 125 | if (sw != null) { |
| 126 | deleteSwitchImpl(sw); |
| 127 | op.commit(); |
| 128 | success = true; |
| 129 | } |
| 130 | } catch (Exception e) { |
| 131 | op.rollback(); |
| 132 | e.printStackTrace(); |
| 133 | log.info("SwitchStorage:update {} dpid:{} failed", dmope, dpid); |
| 134 | } |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 135 | break; |
| 136 | default: |
| 137 | } |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 138 | |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 139 | return success; |
| 140 | } |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 141 | |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 142 | @Override |
| 143 | public boolean addSwitch(IOFSwitch sw) { |
| 144 | boolean success = false; |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 145 | |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 146 | String dpid = sw.getStringId(); |
| 147 | log.info("SwitchStorage:addSwitch(): dpid {} ", dpid); |
yoshi | d76fa1f | 2013-12-19 14:20:34 -0800 | [diff] [blame] | 148 | long startSwitchTime = 0, endSwitchTime = 0; |
| 149 | long startUpdSwitchTime = 0, endUpdSwitchTime=0; |
| 150 | long startPortTime = 0, endPortTime=0; |
| 151 | long totalStartTime =0, totalEndTime=0; |
Masayoshi Kobayashi | 536d72e | 2014-01-06 13:15:52 -0800 | [diff] [blame] | 152 | long Tstamp1=0; |
yoshi | d76fa1f | 2013-12-19 14:20:34 -0800 | [diff] [blame] | 153 | |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 154 | try { |
yoshi | d76fa1f | 2013-12-19 14:20:34 -0800 | [diff] [blame] | 155 | if (measureONOSTimeProp == 1) { |
Masayoshi Kobayashi | 536d72e | 2014-01-06 13:15:52 -0800 | [diff] [blame] | 156 | log.error("Performance: addSwitch dpid= {} Start", dpid); |
yoshi | d76fa1f | 2013-12-19 14:20:34 -0800 | [diff] [blame] | 157 | totalStartTime = System.nanoTime(); |
| 158 | } |
Masayoshi Kobayashi | 536d72e | 2014-01-06 13:15:52 -0800 | [diff] [blame] | 159 | pm.addswitch_start(); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 160 | ISwitchObject curr = op.searchSwitch(dpid); |
Masayoshi Kobayashi | 536d72e | 2014-01-06 13:15:52 -0800 | [diff] [blame] | 161 | if (measureONOSTimeProp == 1) { |
| 162 | Tstamp1 = System.nanoTime(); |
| 163 | log.error("Performance: addSwitch dpid= {} searchSwitch done at {} took {}", dpid, Tstamp1, Tstamp1-totalStartTime); |
| 164 | } |
| 165 | |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 166 | if (curr != null) { |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 167 | //If existing the switch. set The SW state ACTIVE. |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 168 | log.info("SwitchStorage:addSwitch dpid:{} already exists", dpid); |
yoshi | d76fa1f | 2013-12-19 14:20:34 -0800 | [diff] [blame] | 169 | if (measureONOSTimeProp == 1) { |
| 170 | startUpdSwitchTime = System.nanoTime(); |
| 171 | } |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 172 | setSwitchStateImpl(curr, SwitchState.ACTIVE); |
yoshi | d76fa1f | 2013-12-19 14:20:34 -0800 | [diff] [blame] | 173 | if (measureONOSTimeProp == 1) { |
| 174 | endUpdSwitchTime = System.nanoTime(); |
| 175 | } |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 176 | } else { |
yoshi | d76fa1f | 2013-12-19 14:20:34 -0800 | [diff] [blame] | 177 | if (measureONOSTimeProp == 1) { |
| 178 | startSwitchTime = System.nanoTime(); |
| 179 | } |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 180 | curr = addSwitchImpl(dpid); |
Masayoshi Kobayashi | 536d72e | 2014-01-06 13:15:52 -0800 | [diff] [blame] | 181 | pm.addswitch_end(); |
yoshi | d76fa1f | 2013-12-19 14:20:34 -0800 | [diff] [blame] | 182 | if (measureONOSTimeProp == 1) { |
| 183 | endSwitchTime = System.nanoTime(); |
Masayoshi Kobayashi | 536d72e | 2014-01-06 13:15:52 -0800 | [diff] [blame] | 184 | //log.error("Performance: addSwitch dpid= {} addSwitchImpl done at {} took {}", dpid, endSwitchTime, endSwitchTime-startSwitchTime); |
| 185 | log.error("Performance: addSwitch dpid= {} End searchSwitch {} addSwitchImpl {} total {} diff {}", dpid, Tstamp1-totalStartTime, endSwitchTime-startSwitchTime, endSwitchTime-totalStartTime,endSwitchTime-totalStartTime-(Tstamp1-totalStartTime)-(endSwitchTime-startSwitchTime)); |
yoshi | d76fa1f | 2013-12-19 14:20:34 -0800 | [diff] [blame] | 186 | } |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 187 | } |
yoshi | d76fa1f | 2013-12-19 14:20:34 -0800 | [diff] [blame] | 188 | if (measureONOSTimeProp == 1) { |
| 189 | startPortTime = System.nanoTime(); |
| 190 | } |
| 191 | long noOfPorts = 0; |
Masayoshi Kobayashi | 536d72e | 2014-01-06 13:15:52 -0800 | [diff] [blame] | 192 | pm.addport_start(); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 193 | for (OFPhysicalPort port: sw.getPorts()) { |
Jonathan Hart | 4cfd193 | 2013-11-19 16:42:25 -0800 | [diff] [blame] | 194 | //addPort(dpid, port); |
| 195 | addPortImpl(curr, port); |
yoshi | d76fa1f | 2013-12-19 14:20:34 -0800 | [diff] [blame] | 196 | noOfPorts++; |
Masayoshi Kobayashi | 536d72e | 2014-01-06 13:15:52 -0800 | [diff] [blame] | 197 | pm.addport_incr(); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 198 | } |
Masayoshi Kobayashi | 536d72e | 2014-01-06 13:15:52 -0800 | [diff] [blame] | 199 | pm.addport_end(); |
yoshi | d76fa1f | 2013-12-19 14:20:34 -0800 | [diff] [blame] | 200 | if (measureONOSTimeProp == 1) { |
| 201 | endPortTime = System.nanoTime(); |
| 202 | } |
Jonathan Hart | 4cfd193 | 2013-11-19 16:42:25 -0800 | [diff] [blame] | 203 | // XXX for now delete devices when we change a port to prevent |
| 204 | // having stale devices. |
| 205 | DeviceStorageImpl deviceStorage = new DeviceStorageImpl(); |
yoshi | 0fee3de | 2013-11-23 09:13:37 -0800 | [diff] [blame] | 206 | deviceStorage.init("",""); |
Jonathan Hart | 4cfd193 | 2013-11-19 16:42:25 -0800 | [diff] [blame] | 207 | for (IPortObject portObject : curr.getPorts()) { |
| 208 | for (IDeviceObject deviceObject : portObject.getDevices()) { |
| 209 | // The deviceStorage has to remove on the object gained by its own |
| 210 | // FramedGraph, it can't use our objects from here |
| 211 | deviceStorage.removeDeviceImpl(deviceStorage.getDeviceByMac(deviceObject.getMACAddress())); |
| 212 | } |
| 213 | } |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 214 | |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 215 | op.commit(); |
yoshi | d76fa1f | 2013-12-19 14:20:34 -0800 | [diff] [blame] | 216 | if (measureONOSTimeProp == 1) { |
| 217 | totalEndTime = System.nanoTime(); |
| 218 | } |
| 219 | if (startSwitchTime != 0) { |
Masayoshi Kobayashi | 536d72e | 2014-01-06 13:15:52 -0800 | [diff] [blame] | 220 | //log.error("Performance -- switch add total time {}", endSwitchTime - startSwitchTime); |
| 221 | log.error("Performance -- switch add total time {} including_search {}", endSwitchTime - startSwitchTime, endSwitchTime - totalStartTime); |
yoshi | d76fa1f | 2013-12-19 14:20:34 -0800 | [diff] [blame] | 222 | } |
| 223 | if (startUpdSwitchTime != 0) { |
Masayoshi Kobayashi | 536d72e | 2014-01-06 13:15:52 -0800 | [diff] [blame] | 224 | log.error("Performance -- switch update total time {} including_search {}", endUpdSwitchTime - startUpdSwitchTime, endUpdSwitchTime - totalStartTime); |
yoshi | d76fa1f | 2013-12-19 14:20:34 -0800 | [diff] [blame] | 225 | } |
| 226 | if (startPortTime != 0) { |
| 227 | log.error("Performance @@ port add total time {} no of ports written {}", endPortTime - startPortTime, noOfPorts); |
| 228 | } |
yoshi | 9715955 | 2014-01-10 13:18:20 -0800 | [diff] [blame] | 229 | if (totalStartTime != 0) { |
| 230 | log.error("Performance && total time for add switch {}", totalEndTime - totalStartTime); |
| 231 | } |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 232 | success = true; |
| 233 | } catch (Exception e) { |
| 234 | op.rollback(); |
Yuta HIGUCHI | 5302ddf | 2014-01-06 12:53:35 -0800 | [diff] [blame] | 235 | log.error("SwitchStorage:addSwitch dpid:"+dpid+" failed", e); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 236 | } |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 237 | |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 238 | return success; |
| 239 | } |
yoshi | 2fd4c7e | 2013-11-22 15:47:55 -0800 | [diff] [blame] | 240 | |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 241 | /*** |
| 242 | * This function is for adding the switch into the DB. |
| 243 | * @param dpid The switch dpid you want to add into the DB. |
| 244 | */ |
Jonathan Hart | 13ccdca | 2013-10-30 15:23:28 -0700 | [diff] [blame] | 245 | // This method is only called by tests, so we probably don't need it. |
| 246 | // If we need both addSwitch interfaces, one should call the other |
| 247 | // rather than implementing the same logic twice. |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 248 | @Deprecated |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 249 | @Override |
| 250 | public boolean addSwitch(String dpid) { |
| 251 | boolean success = false; |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 252 | |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 253 | log.info("SwitchStorage:addSwitch(): dpid {} ", dpid); |
| 254 | try { |
| 255 | ISwitchObject sw = op.searchSwitch(dpid); |
| 256 | if (sw != null) { |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 257 | //If existing the switch. set The SW state ACTIVE. |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 258 | log.info("SwitchStorage:addSwitch dpid:{} already exists", dpid); |
| 259 | setSwitchStateImpl(sw, SwitchState.ACTIVE); |
| 260 | } else { |
| 261 | addSwitchImpl(dpid); |
| 262 | } |
| 263 | op.commit(); |
| 264 | success = true; |
| 265 | } catch (Exception e) { |
| 266 | op.rollback(); |
| 267 | e.printStackTrace(); |
Yuta HIGUCHI | 5302ddf | 2014-01-06 12:53:35 -0800 | [diff] [blame] | 268 | log.error("SwitchStorage:addSwitch dpid:"+dpid+" failed", e); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 269 | } |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 270 | |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 271 | return success; |
| 272 | } |
| 273 | |
| 274 | /*** |
| 275 | * This function is for deleting the switch into the DB. |
| 276 | * @param dpid The switch dpid you want to delete from the DB. |
| 277 | */ |
| 278 | @Override |
| 279 | public boolean deleteSwitch(String dpid) { |
| 280 | boolean success = false; |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 281 | |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 282 | try { |
| 283 | ISwitchObject sw = op.searchSwitch(dpid); |
| 284 | if (sw != null) { |
| 285 | deleteSwitchImpl(sw); |
| 286 | op.commit(); |
| 287 | } |
| 288 | success = true; |
| 289 | } catch (Exception e) { |
| 290 | op.rollback(); |
| 291 | e.printStackTrace(); |
| 292 | log.error("SwitchStorage:deleteSwitch {} failed", dpid); |
| 293 | } |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 294 | |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 295 | return success; |
| 296 | } |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 297 | |
| 298 | @Override |
Jonathan Hart | adc6389 | 2013-11-08 14:03:55 -0800 | [diff] [blame] | 299 | public boolean deactivateSwitch(String dpid) { |
| 300 | boolean success = false; |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 301 | |
Jonathan Hart | adc6389 | 2013-11-08 14:03:55 -0800 | [diff] [blame] | 302 | try { |
| 303 | ISwitchObject switchObject = op.searchSwitch(dpid); |
| 304 | if (switchObject != null) { |
| 305 | setSwitchStateImpl(switchObject, SwitchState.INACTIVE); |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 306 | |
Jonathan Hart | adc6389 | 2013-11-08 14:03:55 -0800 | [diff] [blame] | 307 | for (IPortObject portObject : switchObject.getPorts()) { |
| 308 | portObject.setState("INACTIVE"); |
| 309 | } |
| 310 | op.commit(); |
| 311 | success = true; |
| 312 | } |
| 313 | else { |
| 314 | log.warn("Switch {} not found when trying to deactivate", dpid); |
| 315 | } |
| 316 | } catch (Exception e) { |
| 317 | // TODO what type of exception is thrown when we can't commit? |
| 318 | op.rollback(); |
Yuta HIGUCHI | 5302ddf | 2014-01-06 12:53:35 -0800 | [diff] [blame] | 319 | log.error("SwitchStorage:deactivateSwitch "+dpid+" failed", e); |
Jonathan Hart | adc6389 | 2013-11-08 14:03:55 -0800 | [diff] [blame] | 320 | } |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 321 | |
Jonathan Hart | adc6389 | 2013-11-08 14:03:55 -0800 | [diff] [blame] | 322 | return success; |
| 323 | } |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 324 | |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 325 | @Override |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 326 | public boolean updatePort(String dpid, short portNum, int state, String desc) { |
| 327 | boolean success = false; |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 328 | |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 329 | try { |
| 330 | ISwitchObject sw = op.searchSwitch(dpid); |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 331 | |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 332 | if (sw != null) { |
| 333 | IPortObject p = sw.getPort(portNum); |
| 334 | log.info("SwitchStorage:updatePort dpid:{} port:{}", dpid, portNum); |
| 335 | if (p != null) { |
| 336 | setPortStateImpl(p, state, desc); |
Pavlin Radoslavov | e86bbfc | 2013-11-05 08:32:14 -0800 | [diff] [blame] | 337 | op.commit(); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 338 | } |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 339 | success = true; |
| 340 | } else { |
| 341 | log.error("SwitchStorage:updatePort dpid:{} port:{} : failed switch does not exist", dpid, portNum); |
| 342 | } |
| 343 | } catch (Exception e) { |
| 344 | op.rollback(); |
| 345 | e.printStackTrace(); |
| 346 | log.error("SwitchStorage:addPort dpid:{} port:{} failed", dpid, portNum); |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 347 | } |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 348 | |
| 349 | return success; |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | /*** |
| 353 | * This function is for adding the switch port into the DB. |
| 354 | * @param dpid The switch dpid that has the port. |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 355 | * @param phport The port you want to add the switch. |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 356 | */ |
| 357 | @Override |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 358 | public boolean addPort(String dpid, OFPhysicalPort phport) { |
| 359 | boolean success = false; |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 360 | |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 361 | if(((OFPortConfig.OFPPC_PORT_DOWN.getValue() & phport.getConfig()) > 0) || |
| 362 | ((OFPortState.OFPPS_LINK_DOWN.getValue() & phport.getState()) > 0)) { |
| 363 | // just dispatch to deletePort() |
Jonathan Hart | adc6389 | 2013-11-08 14:03:55 -0800 | [diff] [blame] | 364 | // TODO This is wrong. We need to make sure the port is in the |
| 365 | // DB with the correct info and port state. |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 366 | return deletePort(dpid, phport.getPortNumber()); |
| 367 | } |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 368 | |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 369 | try { |
| 370 | ISwitchObject sw = op.searchSwitch(dpid); |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 371 | |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 372 | if (sw != null) { |
Jonathan Hart | 4cfd193 | 2013-11-19 16:42:25 -0800 | [diff] [blame] | 373 | IPortObject portObject = addPortImpl(sw, phport); |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 374 | |
Jonathan Hart | 4cfd193 | 2013-11-19 16:42:25 -0800 | [diff] [blame] | 375 | // XXX for now delete devices when we change a port to prevent |
| 376 | // having stale devices. |
| 377 | DeviceStorageImpl deviceStorage = new DeviceStorageImpl(); |
yoshi | 0fee3de | 2013-11-23 09:13:37 -0800 | [diff] [blame] | 378 | deviceStorage.init("",""); |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 379 | |
Jonathan Hart | 4cfd193 | 2013-11-19 16:42:25 -0800 | [diff] [blame] | 380 | for (IDeviceObject deviceObject : portObject.getDevices()) { |
| 381 | deviceStorage.removeDevice(deviceObject); |
| 382 | } |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 383 | |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 384 | op.commit(); |
| 385 | success = true; |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 386 | } else { |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 387 | 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] | 388 | } |
| 389 | } catch (Exception e) { |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 390 | op.rollback(); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 391 | e.printStackTrace(); |
| 392 | log.error("SwitchStorage:addPort dpid:{} port:{} failed", dpid, phport.getPortNumber()); |
Jonathan Hart | 4cfd193 | 2013-11-19 16:42:25 -0800 | [diff] [blame] | 393 | } |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 394 | |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 395 | return success; |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | /*** |
| 399 | * This function is for deleting the switch port from the DB. |
| 400 | * @param dpid The switch dpid that has the port. |
| 401 | * @param port The port you want to delete the switch. |
| 402 | */ |
| 403 | @Override |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 404 | public boolean deletePort(String dpid, short port) { |
| 405 | boolean success = false; |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 406 | |
Jonathan Hart | 1a6f1d6 | 2013-11-14 11:33:46 -0800 | [diff] [blame] | 407 | DeviceStorageImpl deviceStorage = new DeviceStorageImpl(); |
yoshi | 0fee3de | 2013-11-23 09:13:37 -0800 | [diff] [blame] | 408 | deviceStorage.init("",""); |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 409 | |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 410 | try { |
| 411 | ISwitchObject sw = op.searchSwitch(dpid); |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 412 | |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 413 | if (sw != null) { |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 414 | IPortObject p = sw.getPort(port); |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 415 | if (p != null) { |
| 416 | log.info("SwitchStorage:deletePort dpid:{} port:{} found and set INACTIVE", dpid, port); |
Jonathan Hart | adc6389 | 2013-11-08 14:03:55 -0800 | [diff] [blame] | 417 | p.setState("INACTIVE"); |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 418 | |
Jonathan Hart | 1a6f1d6 | 2013-11-14 11:33:46 -0800 | [diff] [blame] | 419 | // XXX for now delete devices when we change a port to prevent |
| 420 | // having stale devices. |
| 421 | for (IDeviceObject d : p.getDevices()) { |
| 422 | deviceStorage.removeDevice(d); |
| 423 | } |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 424 | op.commit(); |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 425 | } |
| 426 | } |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 427 | |
Jonathan Hart | 1a6f1d6 | 2013-11-14 11:33:46 -0800 | [diff] [blame] | 428 | success = true; |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 429 | } catch (Exception e) { |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 430 | op.rollback(); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 431 | e.printStackTrace(); |
Jonathan Hart | adc6389 | 2013-11-08 14:03:55 -0800 | [diff] [blame] | 432 | log.error("SwitchStorage:deletePort dpid:{} port:{} failed", dpid, port); |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 433 | } |
| 434 | |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 435 | return success; |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 436 | } |
| 437 | |
Pavlin Radoslavov | 64647d2 | 2013-11-04 19:07:03 -0800 | [diff] [blame] | 438 | /** |
| 439 | * Get list of all ports on the switch specified by given DPID. |
| 440 | * |
| 441 | * @param dpid DPID of desired switch. |
| 442 | * @return List of port IDs. Empty list if no port was found. |
| 443 | */ |
| 444 | @Override |
| 445 | public List<Short> getPorts(String dpid) { |
| 446 | List<Short> ports = new ArrayList<Short>(); |
| 447 | |
| 448 | ISwitchObject srcSw = op.searchSwitch(dpid); |
| 449 | if (srcSw != null) { |
| 450 | for (IPortObject srcPort : srcSw.getPorts()) { |
| 451 | ports.add(srcPort.getNumber()); |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | return ports; |
| 456 | } |
| 457 | |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 458 | private ISwitchObject addSwitchImpl(String dpid) { |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 459 | if (dpid != null) { |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 460 | ISwitchObject sw = op.newSwitch(dpid); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 461 | sw.setState(SwitchState.ACTIVE.toString()); |
| 462 | log.info("SwitchStorage:addSwitchImpl dpid:{} added", dpid); |
| 463 | return sw; |
| 464 | } else { |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 465 | return null; |
| 466 | } |
| 467 | } |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 468 | |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 469 | private void setSwitchStateImpl(ISwitchObject sw, SwitchState state) { |
| 470 | if (sw != null && state != null) { |
| 471 | sw.setState(state.toString()); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 472 | log.info("SwitchStorage:setSwitchStateImpl dpid:{} updated {}", |
Yuta HIGUCHI | 5302ddf | 2014-01-06 12:53:35 -0800 | [diff] [blame] | 473 | sw.getDPID(), state); |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 474 | } |
Pankaj Berde | 3200ea0 | 2013-01-04 15:48:36 -0800 | [diff] [blame] | 475 | } |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 476 | |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 477 | private void deleteSwitchImpl(ISwitchObject sw) { |
| 478 | if (sw != null) { |
| 479 | op.removeSwitch(sw); |
| 480 | log.info("SwitchStorage:DeleteSwitchImpl dpid:{} done", |
| 481 | sw.getDPID()); |
yoshi | 2fd4c7e | 2013-11-22 15:47:55 -0800 | [diff] [blame] | 482 | } |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 483 | } |
yoshi | 2fd4c7e | 2013-11-22 15:47:55 -0800 | [diff] [blame] | 484 | |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 485 | |
Jonathan Hart | 4cfd193 | 2013-11-19 16:42:25 -0800 | [diff] [blame] | 486 | private IPortObject addPortImpl(ISwitchObject sw, OFPhysicalPort phport) { |
| 487 | IPortObject portObject = op.searchPort(sw.getDPID(), phport.getPortNumber()); |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 488 | |
| 489 | log.info("SwitchStorage:addPort dpid:{} port:{}", |
Jonathan Hart | 4cfd193 | 2013-11-19 16:42:25 -0800 | [diff] [blame] | 490 | sw.getDPID(), phport.getPortNumber()); |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 491 | |
Jonathan Hart | 4cfd193 | 2013-11-19 16:42:25 -0800 | [diff] [blame] | 492 | if (portObject != null) { |
| 493 | setPortStateImpl(portObject, phport.getState(), phport.getName()); |
| 494 | portObject.setState("ACTIVE"); |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 495 | |
Jonathan Hart | 4cfd193 | 2013-11-19 16:42:25 -0800 | [diff] [blame] | 496 | // This a convoluted way of checking if the port is attached |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 497 | // or not, but doing it this way avoids using the |
Jonathan Hart | 4cfd193 | 2013-11-19 16:42:25 -0800 | [diff] [blame] | 498 | // ISwitchObject.getPort method which uses GremlinGroovy query |
| 499 | // and takes forever. |
| 500 | boolean attached = false; |
| 501 | for (IPortObject portsOnSwitch : sw.getPorts()) { |
Yuta HIGUCHI | aa1fac7 | 2013-12-15 14:47:56 -0800 | [diff] [blame] | 502 | if (portsOnSwitch.getPortId().equals( portObject.getPortId() )) { |
Jonathan Hart | 4cfd193 | 2013-11-19 16:42:25 -0800 | [diff] [blame] | 503 | attached = true; |
| 504 | break; |
| 505 | } |
| 506 | } |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 507 | |
Jonathan Hart | 4cfd193 | 2013-11-19 16:42:25 -0800 | [diff] [blame] | 508 | if (!attached) { |
| 509 | sw.addPort(portObject); |
| 510 | } |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 511 | |
Jonathan Hart | 4cfd193 | 2013-11-19 16:42:25 -0800 | [diff] [blame] | 512 | /* |
| 513 | if (sw.getPort(phport.getPortNumber()) == null) { |
| 514 | // The port exists but the switch has no "on" link to it |
| 515 | sw.addPort(portObject); |
| 516 | }*/ |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 517 | |
| 518 | log.info("SwitchStorage:addPort dpid:{} port:{} exists setting as ACTIVE", |
Jonathan Hart | 4cfd193 | 2013-11-19 16:42:25 -0800 | [diff] [blame] | 519 | sw.getDPID(), phport.getPortNumber()); |
| 520 | } else { |
| 521 | //addPortImpl(sw, phport.getPortNumber()); |
| 522 | portObject = op.newPort(sw.getDPID(), phport.getPortNumber()); |
| 523 | portObject.setState("ACTIVE"); |
| 524 | setPortStateImpl(portObject, phport.getState(), phport.getName()); |
| 525 | sw.addPort(portObject); |
| 526 | log.info("SwitchStorage:addPort dpid:{} port:{} done", |
| 527 | sw.getDPID(), phport.getPortNumber()); |
| 528 | } |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 529 | |
Jonathan Hart | 4cfd193 | 2013-11-19 16:42:25 -0800 | [diff] [blame] | 530 | return portObject; |
| 531 | } |
Jonathan Hart | d6ed62b | 2013-11-01 13:18:25 -0700 | [diff] [blame] | 532 | // TODO There's an issue here where a port with that ID could already |
| 533 | // exist when we try to add this one (because it's left over from an |
| 534 | // old topology). We need to remove an old port with the same ID when |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 535 | // we add the new port. Also it seems that old ports like this are |
Jonathan Hart | d6ed62b | 2013-11-01 13:18:25 -0700 | [diff] [blame] | 536 | // never cleaned up and will remain in the DB in the ACTIVE state forever. |
Jonathan Hart | 4cfd193 | 2013-11-19 16:42:25 -0800 | [diff] [blame] | 537 | /*private IPortObject addPortImpl(ISwitchObject sw, short portNum) { |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 538 | IPortObject p = op.newPort(sw.getDPID(), portNum); |
| 539 | p.setState("ACTIVE"); |
| 540 | sw.addPort(p); |
| 541 | log.info("SwitchStorage:addPortImpl dpid:{} port:{} done", |
| 542 | sw.getDPID(), portNum); |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 543 | |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 544 | return p; |
Jonathan Hart | 4cfd193 | 2013-11-19 16:42:25 -0800 | [diff] [blame] | 545 | }*/ |
yoshi | 2fd4c7e | 2013-11-22 15:47:55 -0800 | [diff] [blame] | 546 | |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 547 | private void setPortStateImpl(IPortObject port, Integer state, String desc) { |
| 548 | if (port != null) { |
| 549 | if (state != null) { |
| 550 | port.setPortState(state); |
| 551 | } |
| 552 | if (desc != null) { |
| 553 | port.setDesc(desc); |
| 554 | } |
Yuta HIGUCHI | a0200a9 | 2013-12-15 14:50:41 -0800 | [diff] [blame] | 555 | |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 556 | log.info("SwitchStorage:setPortStateImpl port:{} state:{} desc:{} done", |
| 557 | new Object[] {port.getPortId(), state, desc}); |
| 558 | } |
| 559 | } |
Yuta HIGUCHI | ef3828d | 2013-12-17 22:17:07 -0800 | [diff] [blame] | 560 | } |