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))) { |
Jonathan Hart | 13ccdca | 2013-10-30 15:23:28 -0700 | [diff] [blame] | 122 | log.debug("Adding linkinfo failed: {}", link); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 123 | op.rollback(); |
| 124 | } |
| 125 | op.commit(); |
| 126 | success = true; |
| 127 | } else { |
Jonathan Hart | 13ccdca | 2013-10-30 15:23:28 -0700 | [diff] [blame] | 128 | // If we fail here that's because the ports aren't added |
| 129 | // before we try to add the link |
| 130 | log.debug("Adding link failed: {}", link); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 131 | op.rollback(); |
| 132 | } |
| 133 | } catch (Exception e) { |
| 134 | e.printStackTrace(); |
| 135 | log.error("LinkStorageImpl:addLink link:{} linfo:{} failed", link, linfo); |
| 136 | } |
| 137 | |
| 138 | return success; |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Naoki Shiota | 1151671 | 2013-06-05 22:36:01 -0700 | [diff] [blame] | 141 | /** |
| 142 | * Update multiple records in the LinkStorage in a way provided by op. |
| 143 | * @param links List of records to be updated. |
| 144 | * @param op Operation to be done. |
| 145 | */ |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 146 | @Override |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 147 | public boolean addLinks(List<Link> links) { |
| 148 | boolean success = false; |
| 149 | |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 150 | for (Link lt: links) { |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 151 | if (! addLinkImpl(lt)) { |
| 152 | return false; |
| 153 | } |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 154 | } |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 155 | |
| 156 | try { |
| 157 | op.commit(); |
| 158 | success = true; |
| 159 | } catch (Exception e) { |
| 160 | e.printStackTrace(); |
| 161 | log.error("LinkStorageImpl:addLinks link:s{} failed", links); |
| 162 | } |
| 163 | |
| 164 | return success; |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | /** |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 168 | * Delete a record in the LinkStorage. |
| 169 | * @param lt Record to be deleted. |
| 170 | */ |
| 171 | @Override |
| 172 | public boolean deleteLink(Link lt) { |
| 173 | boolean success = false; |
| 174 | |
| 175 | log.debug("LinkStorageImpl:deleteLink(): {}", lt); |
| 176 | |
| 177 | try { |
| 178 | if (deleteLinkImpl(lt)) { |
| 179 | op.commit(); |
| 180 | success = true; |
| 181 | log.debug("LinkStorageImpl:deleteLink(): deleted edges {}", lt); |
| 182 | } else { |
| 183 | op.rollback(); |
| 184 | log.error("LinkStorageImpl:deleteLink(): failed invalid vertices {}", lt); |
| 185 | } |
| 186 | } catch (Exception e) { |
| 187 | op.rollback(); |
| 188 | log.error("LinkStorageImpl:deleteLink(): failed {} {}", |
| 189 | new Object[]{lt, e.toString()}); |
| 190 | e.printStackTrace(); |
| 191 | } |
| 192 | |
| 193 | return success; |
| 194 | } |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 195 | |
| 196 | /** |
| 197 | * Delete multiple records in LinkStorage. |
| 198 | * @param links List of records to be deleted. |
| 199 | */ |
| 200 | @Override |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 201 | public boolean deleteLinks(List<Link> links) { |
| 202 | boolean success = false; |
| 203 | |
| 204 | try { |
| 205 | for (Link lt : links) { |
| 206 | if (! deleteLinkImpl(lt)) { |
| 207 | op.rollback(); |
| 208 | return false; |
| 209 | } |
| 210 | } |
| 211 | op.commit(); |
| 212 | success = true; |
| 213 | } catch (Exception e) { |
| 214 | op.rollback(); |
| 215 | e.printStackTrace(); |
| 216 | log.error("LinkStorageImpl:deleteLinks failed invalid vertices {}", links); |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 217 | } |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 218 | |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 219 | return success; |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 220 | } |
| 221 | |
Naoki Shiota | 1151671 | 2013-06-05 22:36:01 -0700 | [diff] [blame] | 222 | /** |
Naoki Shiota | 1151671 | 2013-06-05 22:36:01 -0700 | [diff] [blame] | 223 | * Get list of all links connected to the port specified by given DPID and port number. |
| 224 | * @param dpid DPID of desired port. |
| 225 | * @param port Port number of desired port. |
| 226 | * @return List of links. Empty list if no port was found. |
| 227 | */ |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 228 | @Override |
| 229 | public List<Link> getLinks(Long dpid, short port) { |
Naoki Shiota | 93ec171 | 2013-06-13 15:49:36 -0700 | [diff] [blame] | 230 | List<Link> links = new ArrayList<Link>(); |
| 231 | |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 232 | IPortObject srcPort = op.searchPort(HexString.toHexString(dpid), port); |
Naoki Shiota | 93ec171 | 2013-06-13 15:49:36 -0700 | [diff] [blame] | 233 | ISwitchObject srcSw = srcPort.getSwitch(); |
| 234 | |
Pankaj Berde | e7c2152 | 2013-08-01 16:52:29 -0700 | [diff] [blame] | 235 | if(srcSw != null && srcPort != null) { |
Naoki Shiota | 93ec171 | 2013-06-13 15:49:36 -0700 | [diff] [blame] | 236 | for(IPortObject dstPort : srcPort.getLinkedPorts()) { |
| 237 | ISwitchObject dstSw = dstPort.getSwitch(); |
| 238 | Link link = new Link(HexString.toLong(srcSw.getDPID()), |
| 239 | srcPort.getNumber(), |
| 240 | HexString.toLong(dstSw.getDPID()), |
| 241 | dstPort.getNumber()); |
| 242 | |
| 243 | links.add(link); |
| 244 | } |
| 245 | } |
| 246 | |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 247 | return links; |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 248 | } |
| 249 | |
Naoki Shiota | 1151671 | 2013-06-05 22:36:01 -0700 | [diff] [blame] | 250 | /** |
Naoki Shiota | 1151671 | 2013-06-05 22:36:01 -0700 | [diff] [blame] | 251 | * Delete records of the links connected to the port specified by given DPID and port number. |
| 252 | * @param dpid DPID of desired port. |
| 253 | * @param port Port number of desired port. |
| 254 | */ |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 255 | @Override |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 256 | public boolean deleteLinksOnPort(Long dpid, short port) { |
| 257 | boolean success = false; |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 258 | |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 259 | List<Link> linksToDelete = getLinks(dpid, port); |
| 260 | try { |
| 261 | for(Link l : linksToDelete) { |
| 262 | if (! deleteLinkImpl(l)) { |
| 263 | op.rollback(); |
| 264 | log.error("LinkStorageImpl:deleteLinksOnPort dpid:{} port:{} failed", dpid, port); |
| 265 | return false; |
| 266 | } |
| 267 | } |
| 268 | op.commit(); |
| 269 | success = true; |
| 270 | } catch (Exception e) { |
| 271 | op.rollback(); |
| 272 | e.printStackTrace(); |
| 273 | log.error("LinkStorageImpl:deleteLinksOnPort dpid:{} port:{} failed", dpid, port); |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 274 | } |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 275 | |
| 276 | return success; |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 277 | } |
| 278 | |
Naoki Shiota | 1151671 | 2013-06-05 22:36:01 -0700 | [diff] [blame] | 279 | /** |
| 280 | * Get list of all links connected to the switch specified by given DPID. |
| 281 | * @param dpid DPID of desired switch. |
| 282 | * @return List of links. Empty list if no port was found. |
| 283 | */ |
Pankaj Berde | ff42180 | 2013-01-29 20:28:52 -0800 | [diff] [blame] | 284 | @Override |
| 285 | public List<Link> getLinks(String dpid) { |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 286 | List<Link> links = new ArrayList<Link>(); |
| 287 | |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 288 | ISwitchObject srcSw = op.searchSwitch(dpid); |
Naoki Shiota | 93ec171 | 2013-06-13 15:49:36 -0700 | [diff] [blame] | 289 | |
| 290 | if(srcSw != null) { |
| 291 | for(IPortObject srcPort : srcSw.getPorts()) { |
| 292 | for(IPortObject dstPort : srcPort.getLinkedPorts()) { |
| 293 | ISwitchObject dstSw = dstPort.getSwitch(); |
| 294 | if(dstSw != null) { |
| 295 | Link link = new Link(HexString.toLong(srcSw.getDPID()), |
| 296 | srcPort.getNumber(), |
| 297 | HexString.toLong(dstSw.getDPID()), |
| 298 | dstPort.getNumber()); |
| 299 | links.add(link); |
| 300 | } |
| 301 | } |
| 302 | } |
| 303 | } |
| 304 | |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 305 | return links; |
Pankaj Berde | ff42180 | 2013-01-29 20:28:52 -0800 | [diff] [blame] | 306 | } |
| 307 | |
Naoki Shiota | 1151671 | 2013-06-05 22:36:01 -0700 | [diff] [blame] | 308 | /** |
| 309 | * Get list of all links whose state is ACTIVE. |
| 310 | * @return List of active links. Empty list if no port was found. |
| 311 | */ |
Pankaj Berde | ff42180 | 2013-01-29 20:28:52 -0800 | [diff] [blame] | 312 | public List<Link> getActiveLinks() { |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 313 | Iterable<ISwitchObject> switches = op.getActiveSwitches(); |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 314 | |
| 315 | List<Link> links = new ArrayList<Link>(); |
Naoki Shiota | 826e84a | 2013-06-18 13:13:25 -0700 | [diff] [blame] | 316 | |
| 317 | for (ISwitchObject srcSw : switches) { |
| 318 | for(IPortObject srcPort : srcSw.getPorts()) { |
| 319 | for(IPortObject dstPort : srcPort.getLinkedPorts()) { |
| 320 | ISwitchObject dstSw = dstPort.getSwitch(); |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 321 | |
Naoki Shiota | 826e84a | 2013-06-18 13:13:25 -0700 | [diff] [blame] | 322 | if(dstSw != null && dstSw.getState().equals("ACTIVE")) { |
| 323 | links.add(new Link(HexString.toLong(srcSw.getDPID()), |
| 324 | srcPort.getNumber(), |
| 325 | HexString.toLong(dstSw.getDPID()), |
| 326 | dstPort.getNumber())); |
| 327 | } |
| 328 | } |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 329 | } |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 330 | } |
Naoki Shiota | 826e84a | 2013-06-18 13:13:25 -0700 | [diff] [blame] | 331 | |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 332 | return links; |
Pankaj Berde | ff42180 | 2013-01-29 20:28:52 -0800 | [diff] [blame] | 333 | } |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 334 | |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 335 | @Override |
| 336 | public LinkInfo getLinkInfo(Link link) { |
| 337 | // TODO implement this |
| 338 | return null; |
| 339 | } |
| 340 | |
| 341 | /** |
| 342 | * Finalize the object. |
| 343 | */ |
| 344 | public void finalize() { |
| 345 | close(); |
| 346 | } |
| 347 | |
| 348 | /** |
| 349 | * Close LinkStorage. |
| 350 | */ |
| 351 | @Override |
| 352 | public void close() { |
| 353 | // TODO Auto-generated method stub |
| 354 | // graph.shutdown(); |
| 355 | } |
| 356 | |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 357 | /** |
| 358 | * Update a record of link with meta-information in the LinkStorage. |
| 359 | * @param link Record of a link to update. |
| 360 | * @param linkinfo Meta-information of a link to be updated. |
| 361 | */ |
| 362 | private boolean setLinkInfoImpl(Link link, LinkInfo linkinfo) { |
| 363 | // TODO implement this |
| 364 | |
| 365 | return false; |
| 366 | } |
| 367 | |
| 368 | private boolean addLinkImpl(Link lt) { |
| 369 | boolean success = false; |
| 370 | |
| 371 | IPortObject vportSrc = null, vportDst = null; |
| 372 | |
| 373 | // get source port vertex |
| 374 | String dpid = HexString.toHexString(lt.getSrc()); |
| 375 | short port = lt.getSrcPort(); |
| 376 | vportSrc = op.searchPort(dpid, port); |
| 377 | |
| 378 | // get dest port vertex |
| 379 | dpid = HexString.toHexString(lt.getDst()); |
| 380 | port = lt.getDstPort(); |
| 381 | vportDst = op.searchPort(dpid, port); |
| 382 | |
| 383 | if (vportSrc != null && vportDst != null) { |
| 384 | IPortObject portExist = null; |
| 385 | // check if the link exists |
| 386 | for (IPortObject V : vportSrc.getLinkedPorts()) { |
| 387 | if (V.equals(vportDst)) { |
| 388 | portExist = V; |
| 389 | break; |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | if (portExist == null) { |
| 394 | vportSrc.setLinkPort(vportDst); |
| 395 | success = true; |
| 396 | } else { |
| 397 | log.debug("LinkStorageImpl:addLinkImpl failed link exists {} {} src {} dst {}", |
| 398 | new Object[]{op, lt, vportSrc, vportDst}); |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | return success; |
| 403 | } |
| 404 | |
| 405 | private boolean deleteLinkImpl(Link lt) { |
| 406 | boolean success = false; |
| 407 | IPortObject vportSrc = null, vportDst = null; |
| 408 | |
| 409 | // get source port vertex |
| 410 | String dpid = HexString.toHexString(lt.getSrc()); |
| 411 | short port = lt.getSrcPort(); |
| 412 | vportSrc = op.searchPort(dpid, port); |
| 413 | |
| 414 | // get dst port vertex |
| 415 | dpid = HexString.toHexString(lt.getDst()); |
| 416 | port = lt.getDstPort(); |
| 417 | vportDst = op.searchPort(dpid, port); |
| 418 | |
| 419 | // FIXME: This needs to remove all edges |
| 420 | if (vportSrc != null && vportDst != null) { |
| 421 | vportSrc.removeLink(vportDst); |
| 422 | log.debug("deleteLinkImpl(): deleted edges src {} dst {}", new Object[]{ |
| 423 | lt, vportSrc, vportDst}); |
| 424 | success = true; |
| 425 | } |
| 426 | |
| 427 | return success; |
| 428 | } |
| 429 | |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 430 | // TODO should be moved to TopoLinkServiceImpl (never used in this class) |
HIGUCHI Yuta | f05c480 | 2013-06-17 11:15:50 -0700 | [diff] [blame] | 431 | static class ExtractLink implements PipeFunction<PathPipe<Vertex>, Link> { |
Naoki Shiota | c57efb8 | 2013-06-18 13:40:28 -0700 | [diff] [blame] | 432 | |
Yuta HIGUCHI | 57e67f2 | 2013-10-14 10:21:05 -0700 | [diff] [blame] | 433 | @SuppressWarnings("unchecked") |
Naoki Shiota | c57efb8 | 2013-06-18 13:40:28 -0700 | [diff] [blame] | 434 | @Override |
| 435 | public Link compute(PathPipe<Vertex> pipe ) { |
Naoki Shiota | c57efb8 | 2013-06-18 13:40:28 -0700 | [diff] [blame] | 436 | long s_dpid = 0; |
| 437 | long d_dpid = 0; |
| 438 | short s_port = 0; |
| 439 | short d_port = 0; |
| 440 | List<Vertex> V = new ArrayList<Vertex>(); |
Yuta HIGUCHI | 57e67f2 | 2013-10-14 10:21:05 -0700 | [diff] [blame] | 441 | V = (List<Vertex>)pipe.next(); |
Naoki Shiota | c57efb8 | 2013-06-18 13:40:28 -0700 | [diff] [blame] | 442 | Vertex src_sw = V.get(0); |
| 443 | Vertex dest_sw = V.get(3); |
| 444 | Vertex src_port = V.get(1); |
| 445 | Vertex dest_port = V.get(2); |
| 446 | s_dpid = HexString.toLong((String) src_sw.getProperty("dpid")); |
| 447 | d_dpid = HexString.toLong((String) dest_sw.getProperty("dpid")); |
| 448 | s_port = (Short) src_port.getProperty("number"); |
| 449 | d_port = (Short) dest_port.getProperty("number"); |
| 450 | |
| 451 | Link l = new Link(s_dpid,s_port,d_dpid,d_port); |
| 452 | |
| 453 | return l; |
| 454 | } |
| 455 | } |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 456 | |
Pankaj Berde | ff42180 | 2013-01-29 20:28:52 -0800 | [diff] [blame] | 457 | |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 458 | } |