HIGUCHI Yuta | 2d01158 | 2013-06-15 01:47:11 -0700 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.core.internal; |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 2 | |
Pankaj Berde | 6debb04 | 2013-01-16 18:04:32 -0800 | [diff] [blame] | 3 | import java.util.ArrayList; |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 4 | import java.util.List; |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 5 | |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 6 | import net.floodlightcontroller.routing.Link; |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 7 | import net.onrc.onos.graph.GraphDBOperation; |
HIGUCHI Yuta | 2d01158 | 2013-06-15 01:47:11 -0700 | [diff] [blame] | 8 | import net.onrc.onos.ofcontroller.core.ILinkStorage; |
HIGUCHI Yuta | 2051490 | 2013-06-12 11:24:16 -0700 | [diff] [blame] | 9 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IPortObject; |
| 10 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject; |
HIGUCHI Yuta | a56fbde | 2013-06-17 14:26:05 -0700 | [diff] [blame] | 11 | import net.onrc.onos.ofcontroller.linkdiscovery.LinkInfo; |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 12 | |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 13 | import org.openflow.util.HexString; |
| 14 | import org.slf4j.Logger; |
| 15 | import org.slf4j.LoggerFactory; |
| 16 | |
Naoki Shiota | c57efb8 | 2013-06-18 13:40:28 -0700 | [diff] [blame] | 17 | import com.tinkerpop.blueprints.Vertex; |
Naoki Shiota | c57efb8 | 2013-06-18 13:40:28 -0700 | [diff] [blame] | 18 | import com.tinkerpop.pipes.PipeFunction; |
| 19 | import com.tinkerpop.pipes.transform.PathPipe; |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 20 | |
Naoki Shiota | 1c393ce | 2013-06-28 22:55:14 -0700 | [diff] [blame] | 21 | /** |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 22 | * This is the class for storing the information of links into GraphDB |
Naoki Shiota | 1c393ce | 2013-06-28 22:55:14 -0700 | [diff] [blame] | 23 | */ |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 24 | public class LinkStorageImpl implements ILinkStorage { |
Pankaj Berde | 6201614 | 2013-04-09 15:35:50 -0700 | [diff] [blame] | 25 | |
Yuta HIGUCHI | 6ac8d18 | 2013-10-22 15:24:56 -0700 | [diff] [blame] | 26 | protected final static Logger log = LoggerFactory.getLogger(LinkStorageImpl.class); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 27 | protected GraphDBOperation op; |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 28 | |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 29 | |
| 30 | /** |
| 31 | * Initialize the object. Open LinkStorage using given configuration file. |
| 32 | * @param conf Path (absolute path for now) to configuration file. |
| 33 | */ |
| 34 | @Override |
| 35 | public void init(String conf) { |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 36 | this.op = new GraphDBOperation(conf); |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 37 | } |
| 38 | |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 39 | // Method designing policy: |
| 40 | // op.commit() and op.rollback() MUST called in public (first-class) methods. |
| 41 | // A first-class method MUST NOT call other first-class method. |
| 42 | // Routine process should be implemented in private method. |
| 43 | // A private method MUST NOT call commit or rollback. |
| 44 | |
| 45 | |
Naoki Shiota | 1151671 | 2013-06-05 22:36:01 -0700 | [diff] [blame] | 46 | /** |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 47 | * Update a record in the LinkStorage in a way provided by dmop. |
Naoki Shiota | 1151671 | 2013-06-05 22:36:01 -0700 | [diff] [blame] | 48 | * @param link Record of a link to be updated. |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 49 | * @param linkinfo Meta-information of a link to be updated. |
| 50 | * @param dmop Operation to be done. |
Naoki Shiota | 1151671 | 2013-06-05 22:36:01 -0700 | [diff] [blame] | 51 | */ |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 52 | @Override |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 53 | public boolean update(Link link, LinkInfo linkinfo, DM_OPERATION dmop) { |
| 54 | boolean success = false; |
| 55 | |
| 56 | switch (dmop) { |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 57 | case CREATE: |
| 58 | case INSERT: |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 59 | if (link != null) { |
| 60 | try { |
| 61 | if (addLinkImpl(link)) { |
| 62 | op.commit(); |
| 63 | success = true; |
| 64 | } |
| 65 | } catch (Exception e) { |
| 66 | op.rollback(); |
| 67 | e.printStackTrace(); |
| 68 | log.error("LinkStorageImpl:update {} link:{} failed", dmop, link); |
| 69 | } |
| 70 | } |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 71 | break; |
| 72 | case UPDATE: |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 73 | if (link != null && linkinfo != null) { |
| 74 | try { |
| 75 | if (setLinkInfoImpl(link, linkinfo)) { |
| 76 | op.commit(); |
| 77 | success = true; |
| 78 | } |
| 79 | } catch (Exception e) { |
| 80 | op.rollback(); |
| 81 | e.printStackTrace(); |
| 82 | log.error("LinkStorageImpl:update {} link:{} failed", dmop, link); |
| 83 | } |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 84 | } |
| 85 | break; |
| 86 | case DELETE: |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 87 | if (link != null) { |
| 88 | try { |
| 89 | if (deleteLinkImpl(link)) { |
| 90 | op.commit(); |
| 91 | success = true; |
| 92 | log.debug("LinkStorageImpl:update {} link:{} succeeded", dmop, link); |
| 93 | } else { |
| 94 | op.rollback(); |
| 95 | log.debug("LinkStorageImpl:update {} link:{} failed", dmop, link); |
| 96 | } |
| 97 | } catch (Exception e) { |
| 98 | op.rollback(); |
| 99 | e.printStackTrace(); |
| 100 | log.error("LinkStorageImpl:update {} link:{} failed", dmop, link); |
| 101 | } |
| 102 | } |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 103 | break; |
| 104 | } |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 105 | |
| 106 | return success; |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 107 | } |
| 108 | |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 109 | @Override |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 110 | public boolean addLink(Link link) { |
| 111 | return addLink(link, null); |
| 112 | } |
| 113 | |
| 114 | @Override |
| 115 | public boolean addLink(Link link, LinkInfo linfo) { |
| 116 | boolean success = false; |
| 117 | |
| 118 | try { |
| 119 | if (addLinkImpl(link)) { |
| 120 | // Set LinkInfo only if linfo is non-null. |
| 121 | if (linfo != null && (! setLinkInfoImpl(link, linfo))) { |
| 122 | op.rollback(); |
| 123 | } |
| 124 | op.commit(); |
| 125 | success = true; |
| 126 | } else { |
| 127 | op.rollback(); |
| 128 | } |
| 129 | } catch (Exception e) { |
| 130 | e.printStackTrace(); |
| 131 | log.error("LinkStorageImpl:addLink link:{} linfo:{} failed", link, linfo); |
| 132 | } |
| 133 | |
| 134 | return success; |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 135 | } |
| 136 | |
Naoki Shiota | 1151671 | 2013-06-05 22:36:01 -0700 | [diff] [blame] | 137 | /** |
| 138 | * Update multiple records in the LinkStorage in a way provided by op. |
| 139 | * @param links List of records to be updated. |
| 140 | * @param op Operation to be done. |
| 141 | */ |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 142 | @Override |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 143 | public boolean addLinks(List<Link> links) { |
| 144 | boolean success = false; |
| 145 | |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 146 | for (Link lt: links) { |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 147 | if (! addLinkImpl(lt)) { |
| 148 | return false; |
| 149 | } |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 150 | } |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 151 | |
| 152 | try { |
| 153 | op.commit(); |
| 154 | success = true; |
| 155 | } catch (Exception e) { |
| 156 | e.printStackTrace(); |
| 157 | log.error("LinkStorageImpl:addLinks link:s{} failed", links); |
| 158 | } |
| 159 | |
| 160 | return success; |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | /** |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 164 | * Delete a record in the LinkStorage. |
| 165 | * @param lt Record to be deleted. |
| 166 | */ |
| 167 | @Override |
| 168 | public boolean deleteLink(Link lt) { |
| 169 | boolean success = false; |
| 170 | |
| 171 | log.debug("LinkStorageImpl:deleteLink(): {}", lt); |
| 172 | |
| 173 | try { |
| 174 | if (deleteLinkImpl(lt)) { |
| 175 | op.commit(); |
| 176 | success = true; |
| 177 | log.debug("LinkStorageImpl:deleteLink(): deleted edges {}", lt); |
| 178 | } else { |
| 179 | op.rollback(); |
| 180 | log.error("LinkStorageImpl:deleteLink(): failed invalid vertices {}", lt); |
| 181 | } |
| 182 | } catch (Exception e) { |
| 183 | op.rollback(); |
| 184 | log.error("LinkStorageImpl:deleteLink(): failed {} {}", |
| 185 | new Object[]{lt, e.toString()}); |
| 186 | e.printStackTrace(); |
| 187 | } |
| 188 | |
| 189 | return success; |
| 190 | } |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 191 | |
| 192 | /** |
| 193 | * Delete multiple records in LinkStorage. |
| 194 | * @param links List of records to be deleted. |
| 195 | */ |
| 196 | @Override |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 197 | public boolean deleteLinks(List<Link> links) { |
| 198 | boolean success = false; |
| 199 | |
| 200 | try { |
| 201 | for (Link lt : links) { |
| 202 | if (! deleteLinkImpl(lt)) { |
| 203 | op.rollback(); |
| 204 | return false; |
| 205 | } |
| 206 | } |
| 207 | op.commit(); |
| 208 | success = true; |
| 209 | } catch (Exception e) { |
| 210 | op.rollback(); |
| 211 | e.printStackTrace(); |
| 212 | log.error("LinkStorageImpl:deleteLinks failed invalid vertices {}", links); |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 213 | } |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 214 | |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 215 | return success; |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 216 | } |
| 217 | |
Naoki Shiota | 1151671 | 2013-06-05 22:36:01 -0700 | [diff] [blame] | 218 | /** |
Naoki Shiota | 1151671 | 2013-06-05 22:36:01 -0700 | [diff] [blame] | 219 | * Get list of all links connected to the port specified by given DPID and port number. |
| 220 | * @param dpid DPID of desired port. |
| 221 | * @param port Port number of desired port. |
| 222 | * @return List of links. Empty list if no port was found. |
| 223 | */ |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 224 | @Override |
| 225 | public List<Link> getLinks(Long dpid, short port) { |
Naoki Shiota | 93ec171 | 2013-06-13 15:49:36 -0700 | [diff] [blame] | 226 | List<Link> links = new ArrayList<Link>(); |
| 227 | |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 228 | IPortObject srcPort = op.searchPort(HexString.toHexString(dpid), port); |
Naoki Shiota | 93ec171 | 2013-06-13 15:49:36 -0700 | [diff] [blame] | 229 | ISwitchObject srcSw = srcPort.getSwitch(); |
| 230 | |
Pankaj Berde | e7c2152 | 2013-08-01 16:52:29 -0700 | [diff] [blame] | 231 | if(srcSw != null && srcPort != null) { |
Naoki Shiota | 93ec171 | 2013-06-13 15:49:36 -0700 | [diff] [blame] | 232 | for(IPortObject dstPort : srcPort.getLinkedPorts()) { |
| 233 | ISwitchObject dstSw = dstPort.getSwitch(); |
| 234 | Link link = new Link(HexString.toLong(srcSw.getDPID()), |
| 235 | srcPort.getNumber(), |
| 236 | HexString.toLong(dstSw.getDPID()), |
| 237 | dstPort.getNumber()); |
| 238 | |
| 239 | links.add(link); |
| 240 | } |
| 241 | } |
| 242 | |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 243 | return links; |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 244 | } |
| 245 | |
Naoki Shiota | 1151671 | 2013-06-05 22:36:01 -0700 | [diff] [blame] | 246 | /** |
Naoki Shiota | 1151671 | 2013-06-05 22:36:01 -0700 | [diff] [blame] | 247 | * Delete records of the links connected to the port specified by given DPID and port number. |
| 248 | * @param dpid DPID of desired port. |
| 249 | * @param port Port number of desired port. |
| 250 | */ |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 251 | @Override |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 252 | public boolean deleteLinksOnPort(Long dpid, short port) { |
| 253 | boolean success = false; |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 254 | |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 255 | List<Link> linksToDelete = getLinks(dpid, port); |
| 256 | try { |
| 257 | for(Link l : linksToDelete) { |
| 258 | if (! deleteLinkImpl(l)) { |
| 259 | op.rollback(); |
| 260 | log.error("LinkStorageImpl:deleteLinksOnPort dpid:{} port:{} failed", dpid, port); |
| 261 | return false; |
| 262 | } |
| 263 | } |
| 264 | op.commit(); |
| 265 | success = true; |
| 266 | } catch (Exception e) { |
| 267 | op.rollback(); |
| 268 | e.printStackTrace(); |
| 269 | log.error("LinkStorageImpl:deleteLinksOnPort dpid:{} port:{} failed", dpid, port); |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 270 | } |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 271 | |
| 272 | return success; |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 273 | } |
| 274 | |
Naoki Shiota | 1151671 | 2013-06-05 22:36:01 -0700 | [diff] [blame] | 275 | /** |
| 276 | * Get list of all links connected to the switch specified by given DPID. |
| 277 | * @param dpid DPID of desired switch. |
| 278 | * @return List of links. Empty list if no port was found. |
| 279 | */ |
Pankaj Berde | ff42180 | 2013-01-29 20:28:52 -0800 | [diff] [blame] | 280 | @Override |
| 281 | public List<Link> getLinks(String dpid) { |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 282 | List<Link> links = new ArrayList<Link>(); |
| 283 | |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 284 | ISwitchObject srcSw = op.searchSwitch(dpid); |
Naoki Shiota | 93ec171 | 2013-06-13 15:49:36 -0700 | [diff] [blame] | 285 | |
| 286 | if(srcSw != null) { |
| 287 | for(IPortObject srcPort : srcSw.getPorts()) { |
| 288 | for(IPortObject dstPort : srcPort.getLinkedPorts()) { |
| 289 | ISwitchObject dstSw = dstPort.getSwitch(); |
| 290 | if(dstSw != null) { |
| 291 | Link link = new Link(HexString.toLong(srcSw.getDPID()), |
| 292 | srcPort.getNumber(), |
| 293 | HexString.toLong(dstSw.getDPID()), |
| 294 | dstPort.getNumber()); |
| 295 | links.add(link); |
| 296 | } |
| 297 | } |
| 298 | } |
| 299 | } |
| 300 | |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 301 | return links; |
Pankaj Berde | ff42180 | 2013-01-29 20:28:52 -0800 | [diff] [blame] | 302 | } |
| 303 | |
Naoki Shiota | 1151671 | 2013-06-05 22:36:01 -0700 | [diff] [blame] | 304 | /** |
Pavlin Radoslavov | c934b4a | 2013-11-02 14:53:52 -0700 | [diff] [blame] | 305 | * Get list of all reverse links connected to the switch specified by |
| 306 | * given DPID. |
| 307 | * @param dpid DPID of desired switch. |
| 308 | * @return List of reverse links. Empty list if no port was found. |
| 309 | */ |
| 310 | @Override |
| 311 | public List<Link> getReverseLinks(String dpid) { |
| 312 | List<Link> links = new ArrayList<Link>(); |
| 313 | |
| 314 | ISwitchObject srcSw = op.searchSwitch(dpid); |
| 315 | |
| 316 | if(srcSw != null) { |
| 317 | for(IPortObject srcPort : srcSw.getPorts()) { |
| 318 | for(IPortObject dstPort : srcPort.getReverseLinkedPorts()) { |
| 319 | ISwitchObject dstSw = dstPort.getSwitch(); |
| 320 | if(dstSw != null) { |
| 321 | Link link = new Link( |
| 322 | HexString.toLong(dstSw.getDPID()), |
| 323 | dstPort.getNumber(), |
| 324 | |
| 325 | HexString.toLong(srcSw.getDPID()), |
| 326 | srcPort.getNumber()); |
| 327 | links.add(link); |
| 328 | } |
| 329 | } |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | return links; |
| 334 | } |
| 335 | |
| 336 | /** |
Naoki Shiota | 1151671 | 2013-06-05 22:36:01 -0700 | [diff] [blame] | 337 | * Get list of all links whose state is ACTIVE. |
| 338 | * @return List of active links. Empty list if no port was found. |
| 339 | */ |
Pankaj Berde | ff42180 | 2013-01-29 20:28:52 -0800 | [diff] [blame] | 340 | public List<Link> getActiveLinks() { |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 341 | Iterable<ISwitchObject> switches = op.getActiveSwitches(); |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 342 | |
| 343 | List<Link> links = new ArrayList<Link>(); |
Naoki Shiota | 826e84a | 2013-06-18 13:13:25 -0700 | [diff] [blame] | 344 | |
| 345 | for (ISwitchObject srcSw : switches) { |
| 346 | for(IPortObject srcPort : srcSw.getPorts()) { |
| 347 | for(IPortObject dstPort : srcPort.getLinkedPorts()) { |
| 348 | ISwitchObject dstSw = dstPort.getSwitch(); |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 349 | |
Naoki Shiota | 826e84a | 2013-06-18 13:13:25 -0700 | [diff] [blame] | 350 | if(dstSw != null && dstSw.getState().equals("ACTIVE")) { |
| 351 | links.add(new Link(HexString.toLong(srcSw.getDPID()), |
| 352 | srcPort.getNumber(), |
| 353 | HexString.toLong(dstSw.getDPID()), |
| 354 | dstPort.getNumber())); |
| 355 | } |
| 356 | } |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 357 | } |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 358 | } |
Naoki Shiota | 826e84a | 2013-06-18 13:13:25 -0700 | [diff] [blame] | 359 | |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 360 | return links; |
Pankaj Berde | ff42180 | 2013-01-29 20:28:52 -0800 | [diff] [blame] | 361 | } |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 362 | |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 363 | @Override |
| 364 | public LinkInfo getLinkInfo(Link link) { |
| 365 | // TODO implement this |
| 366 | return null; |
| 367 | } |
| 368 | |
| 369 | /** |
| 370 | * Finalize the object. |
| 371 | */ |
| 372 | public void finalize() { |
| 373 | close(); |
| 374 | } |
| 375 | |
| 376 | /** |
| 377 | * Close LinkStorage. |
| 378 | */ |
| 379 | @Override |
| 380 | public void close() { |
| 381 | // TODO Auto-generated method stub |
| 382 | // graph.shutdown(); |
| 383 | } |
| 384 | |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 385 | /** |
| 386 | * Update a record of link with meta-information in the LinkStorage. |
| 387 | * @param link Record of a link to update. |
| 388 | * @param linkinfo Meta-information of a link to be updated. |
| 389 | */ |
| 390 | private boolean setLinkInfoImpl(Link link, LinkInfo linkinfo) { |
| 391 | // TODO implement this |
| 392 | |
| 393 | return false; |
| 394 | } |
| 395 | |
| 396 | private boolean addLinkImpl(Link lt) { |
| 397 | boolean success = false; |
| 398 | |
| 399 | IPortObject vportSrc = null, vportDst = null; |
| 400 | |
| 401 | // get source port vertex |
| 402 | String dpid = HexString.toHexString(lt.getSrc()); |
| 403 | short port = lt.getSrcPort(); |
| 404 | vportSrc = op.searchPort(dpid, port); |
| 405 | |
| 406 | // get dest port vertex |
| 407 | dpid = HexString.toHexString(lt.getDst()); |
| 408 | port = lt.getDstPort(); |
| 409 | vportDst = op.searchPort(dpid, port); |
| 410 | |
| 411 | if (vportSrc != null && vportDst != null) { |
| 412 | IPortObject portExist = null; |
| 413 | // check if the link exists |
| 414 | for (IPortObject V : vportSrc.getLinkedPorts()) { |
| 415 | if (V.equals(vportDst)) { |
| 416 | portExist = V; |
| 417 | break; |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | if (portExist == null) { |
| 422 | vportSrc.setLinkPort(vportDst); |
| 423 | success = true; |
| 424 | } else { |
| 425 | log.debug("LinkStorageImpl:addLinkImpl failed link exists {} {} src {} dst {}", |
| 426 | new Object[]{op, lt, vportSrc, vportDst}); |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | return success; |
| 431 | } |
| 432 | |
| 433 | private boolean deleteLinkImpl(Link lt) { |
| 434 | boolean success = false; |
| 435 | IPortObject vportSrc = null, vportDst = null; |
| 436 | |
| 437 | // get source port vertex |
| 438 | String dpid = HexString.toHexString(lt.getSrc()); |
| 439 | short port = lt.getSrcPort(); |
| 440 | vportSrc = op.searchPort(dpid, port); |
| 441 | |
| 442 | // get dst port vertex |
| 443 | dpid = HexString.toHexString(lt.getDst()); |
| 444 | port = lt.getDstPort(); |
| 445 | vportDst = op.searchPort(dpid, port); |
| 446 | |
| 447 | // FIXME: This needs to remove all edges |
| 448 | if (vportSrc != null && vportDst != null) { |
| 449 | vportSrc.removeLink(vportDst); |
| 450 | log.debug("deleteLinkImpl(): deleted edges src {} dst {}", new Object[]{ |
| 451 | lt, vportSrc, vportDst}); |
| 452 | success = true; |
| 453 | } |
| 454 | |
| 455 | return success; |
| 456 | } |
| 457 | |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 458 | // TODO should be moved to TopoLinkServiceImpl (never used in this class) |
HIGUCHI Yuta | f05c480 | 2013-06-17 11:15:50 -0700 | [diff] [blame] | 459 | static class ExtractLink implements PipeFunction<PathPipe<Vertex>, Link> { |
Naoki Shiota | c57efb8 | 2013-06-18 13:40:28 -0700 | [diff] [blame] | 460 | |
Yuta HIGUCHI | 57e67f2 | 2013-10-14 10:21:05 -0700 | [diff] [blame] | 461 | @SuppressWarnings("unchecked") |
Naoki Shiota | c57efb8 | 2013-06-18 13:40:28 -0700 | [diff] [blame] | 462 | @Override |
| 463 | public Link compute(PathPipe<Vertex> pipe ) { |
Naoki Shiota | c57efb8 | 2013-06-18 13:40:28 -0700 | [diff] [blame] | 464 | long s_dpid = 0; |
| 465 | long d_dpid = 0; |
| 466 | short s_port = 0; |
| 467 | short d_port = 0; |
| 468 | List<Vertex> V = new ArrayList<Vertex>(); |
Yuta HIGUCHI | 57e67f2 | 2013-10-14 10:21:05 -0700 | [diff] [blame] | 469 | V = (List<Vertex>)pipe.next(); |
Naoki Shiota | c57efb8 | 2013-06-18 13:40:28 -0700 | [diff] [blame] | 470 | Vertex src_sw = V.get(0); |
| 471 | Vertex dest_sw = V.get(3); |
| 472 | Vertex src_port = V.get(1); |
| 473 | Vertex dest_port = V.get(2); |
| 474 | s_dpid = HexString.toLong((String) src_sw.getProperty("dpid")); |
| 475 | d_dpid = HexString.toLong((String) dest_sw.getProperty("dpid")); |
| 476 | s_port = (Short) src_port.getProperty("number"); |
| 477 | d_port = (Short) dest_port.getProperty("number"); |
| 478 | |
| 479 | Link l = new Link(s_dpid,s_port,d_dpid,d_port); |
| 480 | |
| 481 | return l; |
| 482 | } |
| 483 | } |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 484 | |
Pankaj Berde | ff42180 | 2013-01-29 20:28:52 -0800 | [diff] [blame] | 485 | |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 486 | } |