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 | |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 17 | import com.thinkaurelius.titan.core.TitanException; |
Naoki Shiota | c57efb8 | 2013-06-18 13:40:28 -0700 | [diff] [blame] | 18 | import com.tinkerpop.blueprints.Vertex; |
Naoki Shiota | c57efb8 | 2013-06-18 13:40:28 -0700 | [diff] [blame] | 19 | import com.tinkerpop.pipes.PipeFunction; |
| 20 | import com.tinkerpop.pipes.transform.PathPipe; |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 21 | |
Naoki Shiota | 1c393ce | 2013-06-28 22:55:14 -0700 | [diff] [blame] | 22 | /** |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame^] | 23 | * This is the class for storing the information of links into GraphDB |
Naoki Shiota | 1c393ce | 2013-06-28 22:55:14 -0700 | [diff] [blame] | 24 | */ |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 25 | public class LinkStorageImpl implements ILinkStorage { |
Pankaj Berde | 6201614 | 2013-04-09 15:35:50 -0700 | [diff] [blame] | 26 | |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 27 | protected static Logger log = LoggerFactory.getLogger(LinkStorageImpl.class); |
Toshio Koide | 7bdea5b | 2013-06-13 13:57:18 -0700 | [diff] [blame] | 28 | protected GraphDBOperation dbop; |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 29 | |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame^] | 30 | |
| 31 | /** |
| 32 | * Initialize the object. Open LinkStorage using given configuration file. |
| 33 | * @param conf Path (absolute path for now) to configuration file. |
| 34 | */ |
| 35 | @Override |
| 36 | public void init(String conf) { |
| 37 | this.dbop = new GraphDBOperation(conf); |
| 38 | } |
| 39 | |
Naoki Shiota | 1151671 | 2013-06-05 22:36:01 -0700 | [diff] [blame] | 40 | /** |
| 41 | * Update a record in the LinkStorage in a way provided by op. |
| 42 | * @param link Record of a link to be updated. |
| 43 | * @param op Operation to be done. |
| 44 | */ |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 45 | @Override |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame^] | 46 | public void update(Link link, LinkInfo linkinfo, DM_OPERATION op) { |
| 47 | switch (op) { |
| 48 | case CREATE: |
| 49 | case INSERT: |
| 50 | addLinkImpl(link,op); |
| 51 | break; |
| 52 | case UPDATE: |
| 53 | if (linkinfo != null) { |
| 54 | setLinkInfo(link, linkinfo); |
| 55 | } else { |
| 56 | deleteLinkInfo(link); |
| 57 | } |
| 58 | break; |
| 59 | case DELETE: |
| 60 | deleteLink(link); |
| 61 | break; |
| 62 | } |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 63 | } |
| 64 | |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame^] | 65 | @Override |
| 66 | public void addLink(Link link) { |
| 67 | addLinkImpl(link, DM_OPERATION.INSERT); |
| 68 | } |
| 69 | |
Naoki Shiota | 1151671 | 2013-06-05 22:36:01 -0700 | [diff] [blame] | 70 | /** |
| 71 | * Update multiple records in the LinkStorage in a way provided by op. |
| 72 | * @param links List of records to be updated. |
| 73 | * @param op Operation to be done. |
| 74 | */ |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 75 | @Override |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame^] | 76 | public void addLinks(List<Link> links) { |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 77 | for (Link lt: links) { |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame^] | 78 | addLinkImpl(lt, DM_OPERATION.INSERT); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Delete a record in the LinkStorage. |
| 84 | * @param lt Record to be deleted. |
| 85 | */ |
| 86 | @Override |
| 87 | public void deleteLink(Link lt) { |
| 88 | IPortObject vportSrc = null, vportDst = null; |
| 89 | |
| 90 | log.debug("deleteLink(): {}", lt); |
| 91 | |
| 92 | try { |
| 93 | // get source port vertex |
| 94 | String dpid = HexString.toHexString(lt.getSrc()); |
| 95 | short port = lt.getSrcPort(); |
| 96 | vportSrc = dbop.searchPort(dpid, port); |
| 97 | |
| 98 | // get dst port vertex |
| 99 | dpid = HexString.toHexString(lt.getDst()); |
| 100 | port = lt.getDstPort(); |
| 101 | vportDst = dbop.searchPort(dpid, port); |
| 102 | // FIXME: This needs to remove all edges |
| 103 | |
| 104 | if (vportSrc != null && vportDst != null) { |
| 105 | vportSrc.removeLink(vportDst); |
| 106 | dbop.commit(); |
| 107 | log.debug("deleteLink(): deleted edges src {} dst {}", new Object[]{ |
| 108 | lt, vportSrc, vportDst}); |
| 109 | |
| 110 | // TODO publish DELETE_LINK event here |
| 111 | } else { |
| 112 | log.error("deleteLink(): failed invalid vertices {} src {} dst {}", new Object[]{lt, vportSrc, vportDst}); |
| 113 | dbop.rollback(); |
| 114 | } |
| 115 | |
| 116 | } catch (TitanException e) { |
| 117 | /* |
| 118 | * retry till we succeed? |
| 119 | */ |
| 120 | log.error("deleteLink(): titan exception {} {}", new Object[]{lt, e.toString()}); |
| 121 | dbop.rollback(); |
| 122 | e.printStackTrace(); |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Delete multiple records in LinkStorage. |
| 128 | * @param links List of records to be deleted. |
| 129 | */ |
| 130 | @Override |
| 131 | public void deleteLinks(List<Link> links) { |
| 132 | for (Link lt : links) { |
| 133 | deleteLink(lt); |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 134 | } |
| 135 | } |
| 136 | |
Naoki Shiota | 1151671 | 2013-06-05 22:36:01 -0700 | [diff] [blame] | 137 | /** |
| 138 | * Update a record of link with meta-information in the LinkStorage in a way provided by op. |
| 139 | * @param link Record of a link to update. |
| 140 | * @param linkinfo Meta-information of a link to be updated. |
| 141 | * @param op Operation to be done. |
| 142 | */ |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame^] | 143 | private void setLinkInfo(Link link, LinkInfo linkinfo) { |
| 144 | // TODO implement this |
| 145 | |
| 146 | // TODO publish UPDATE_LINK event here |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 147 | } |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 148 | |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame^] | 149 | private void deleteLinkInfo(Link link) { |
| 150 | // TODO implement this |
| 151 | |
| 152 | // TODO publish UPDATE_LINK event here |
| 153 | } |
| 154 | |
Naoki Shiota | 1151671 | 2013-06-05 22:36:01 -0700 | [diff] [blame] | 155 | /** |
| 156 | * Perform INSERT/CREATE/UPDATE operation to update the LinkStorage. |
| 157 | * @param lt Record of a link to be updated. |
| 158 | * @param linkinfo Meta-information of a link to be updated. |
| 159 | * @param op Operation to be done. (only INSERT/CREATE/UPDATE is acceptable) |
| 160 | */ |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame^] | 161 | private void addLinkImpl(Link lt, DM_OPERATION op) { |
Pankaj Berde | 5fb2763 | 2013-04-05 08:56:12 -0700 | [diff] [blame] | 162 | IPortObject vportSrc = null, vportDst = null; |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 163 | |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame^] | 164 | log.trace("updateLink(): op {} {}", new Object[]{op, lt}); |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 165 | |
| 166 | try { |
| 167 | // get source port vertex |
| 168 | String dpid = HexString.toHexString(lt.getSrc()); |
| 169 | short port = lt.getSrcPort(); |
Toshio Koide | 7bdea5b | 2013-06-13 13:57:18 -0700 | [diff] [blame] | 170 | vportSrc = dbop.searchPort(dpid, port); |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 171 | |
| 172 | // get dest port vertex |
| 173 | dpid = HexString.toHexString(lt.getDst()); |
| 174 | port = lt.getDstPort(); |
Toshio Koide | 7bdea5b | 2013-06-13 13:57:18 -0700 | [diff] [blame] | 175 | vportDst = dbop.searchPort(dpid, port); |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 176 | |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 177 | if (vportSrc != null && vportDst != null) { |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 178 | // check if the link exists |
Pankaj Berde | 77b5851 | 2013-04-05 12:06:37 -0700 | [diff] [blame] | 179 | |
Pankaj Berde | 6201614 | 2013-04-09 15:35:50 -0700 | [diff] [blame] | 180 | Iterable<IPortObject> currPorts = vportSrc.getLinkedPorts(); |
| 181 | List<IPortObject> currLinks = new ArrayList<IPortObject>(); |
Pankaj Berde | 77b5851 | 2013-04-05 12:06:37 -0700 | [diff] [blame] | 182 | for (IPortObject V : currPorts) { |
Pankaj Berde | 6debb04 | 2013-01-16 18:04:32 -0800 | [diff] [blame] | 183 | currLinks.add(V); |
| 184 | } |
Naoki Shiota | cae568a | 2013-06-05 17:53:41 -0700 | [diff] [blame] | 185 | |
Pankaj Berde | 6debb04 | 2013-01-16 18:04:32 -0800 | [diff] [blame] | 186 | if (currLinks.contains(vportDst)) { |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 187 | if (op.equals(DM_OPERATION.INSERT) || op.equals(DM_OPERATION.CREATE)) { |
Umesh Krishnaswamy | 9306f95 | 2013-01-24 20:42:59 -0800 | [diff] [blame] | 188 | log.debug("addOrUpdateLink(): failed link exists {} {} src {} dst {}", |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 189 | new Object[]{op, lt, vportSrc, vportDst}); |
| 190 | } |
Pankaj Berde | 0fc4e43 | 2013-01-12 09:47:22 -0800 | [diff] [blame] | 191 | } else { |
Naoki Shiota | b0d0c00 | 2013-06-05 20:21:20 -0700 | [diff] [blame] | 192 | vportSrc.setLinkPort(vportDst); |
Pankaj Berde | 6201614 | 2013-04-09 15:35:50 -0700 | [diff] [blame] | 193 | |
Toshio Koide | 7bdea5b | 2013-06-13 13:57:18 -0700 | [diff] [blame] | 194 | dbop.commit(); |
Pankaj Berde | 254abb4 | 2013-06-10 21:21:49 -0700 | [diff] [blame] | 195 | log.debug("updateLink(): link added {} {} src {} dst {}", new Object[]{op, lt, vportSrc, vportDst}); |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame^] | 196 | |
| 197 | // TODO publish ADD_LINK event here |
Pankaj Berde | 0fc4e43 | 2013-01-12 09:47:22 -0800 | [diff] [blame] | 198 | } |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 199 | } else { |
Pankaj Berde | 254abb4 | 2013-06-10 21:21:49 -0700 | [diff] [blame] | 200 | log.error("updateLink(): failed invalid vertices {} {} src {} dst {}", new Object[]{op, lt, vportSrc, vportDst}); |
Toshio Koide | 7bdea5b | 2013-06-13 13:57:18 -0700 | [diff] [blame] | 201 | dbop.rollback(); |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 202 | } |
| 203 | } catch (TitanException e) { |
| 204 | /* |
| 205 | * retry till we succeed? |
| 206 | */ |
Umesh Krishnaswamy | c56a8cc | 2013-01-24 21:47:51 -0800 | [diff] [blame] | 207 | e.printStackTrace(); |
Pankaj Berde | 254abb4 | 2013-06-10 21:21:49 -0700 | [diff] [blame] | 208 | log.error("updateLink(): titan exception {} {} {}", new Object[]{op, lt, e.toString()}); |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 209 | } |
| 210 | } |
| 211 | |
Naoki Shiota | 1151671 | 2013-06-05 22:36:01 -0700 | [diff] [blame] | 212 | /** |
Naoki Shiota | 1151671 | 2013-06-05 22:36:01 -0700 | [diff] [blame] | 213 | * Get list of all links connected to the port specified by given DPID and port number. |
| 214 | * @param dpid DPID of desired port. |
| 215 | * @param port Port number of desired port. |
| 216 | * @return List of links. Empty list if no port was found. |
| 217 | */ |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 218 | @Override |
| 219 | public List<Link> getLinks(Long dpid, short port) { |
Naoki Shiota | 93ec171 | 2013-06-13 15:49:36 -0700 | [diff] [blame] | 220 | List<Link> links = new ArrayList<Link>(); |
| 221 | |
| 222 | IPortObject srcPort = dbop.searchPort(HexString.toHexString(dpid), port); |
| 223 | ISwitchObject srcSw = srcPort.getSwitch(); |
| 224 | |
Pankaj Berde | e7c2152 | 2013-08-01 16:52:29 -0700 | [diff] [blame] | 225 | if(srcSw != null && srcPort != null) { |
Naoki Shiota | 93ec171 | 2013-06-13 15:49:36 -0700 | [diff] [blame] | 226 | for(IPortObject dstPort : srcPort.getLinkedPorts()) { |
| 227 | ISwitchObject dstSw = dstPort.getSwitch(); |
| 228 | Link link = new Link(HexString.toLong(srcSw.getDPID()), |
| 229 | srcPort.getNumber(), |
| 230 | HexString.toLong(dstSw.getDPID()), |
| 231 | dstPort.getNumber()); |
| 232 | |
| 233 | links.add(link); |
| 234 | } |
| 235 | } |
| 236 | |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 237 | return links; |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 238 | } |
| 239 | |
Naoki Shiota | 1151671 | 2013-06-05 22:36:01 -0700 | [diff] [blame] | 240 | /** |
Naoki Shiota | 1151671 | 2013-06-05 22:36:01 -0700 | [diff] [blame] | 241 | * Delete records of the links connected to the port specified by given DPID and port number. |
| 242 | * @param dpid DPID of desired port. |
| 243 | * @param port Port number of desired port. |
| 244 | */ |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 245 | @Override |
| 246 | public void deleteLinksOnPort(Long dpid, short port) { |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame^] | 247 | List<Link> linksToDelete = getLinks(dpid, port); |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 248 | |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 249 | for(Link l : linksToDelete) { |
| 250 | deleteLink(l); |
| 251 | } |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 252 | } |
| 253 | |
Naoki Shiota | 1151671 | 2013-06-05 22:36:01 -0700 | [diff] [blame] | 254 | /** |
| 255 | * Get list of all links connected to the switch specified by given DPID. |
| 256 | * @param dpid DPID of desired switch. |
| 257 | * @return List of links. Empty list if no port was found. |
| 258 | */ |
Pankaj Berde | ff42180 | 2013-01-29 20:28:52 -0800 | [diff] [blame] | 259 | @Override |
| 260 | public List<Link> getLinks(String dpid) { |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 261 | List<Link> links = new ArrayList<Link>(); |
| 262 | |
Naoki Shiota | 93ec171 | 2013-06-13 15:49:36 -0700 | [diff] [blame] | 263 | ISwitchObject srcSw = dbop.searchSwitch(dpid); |
| 264 | |
| 265 | if(srcSw != null) { |
| 266 | for(IPortObject srcPort : srcSw.getPorts()) { |
| 267 | for(IPortObject dstPort : srcPort.getLinkedPorts()) { |
| 268 | ISwitchObject dstSw = dstPort.getSwitch(); |
| 269 | if(dstSw != null) { |
| 270 | Link link = new Link(HexString.toLong(srcSw.getDPID()), |
| 271 | srcPort.getNumber(), |
| 272 | HexString.toLong(dstSw.getDPID()), |
| 273 | dstPort.getNumber()); |
| 274 | links.add(link); |
| 275 | } |
| 276 | } |
| 277 | } |
| 278 | } |
| 279 | |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 280 | return links; |
Pankaj Berde | ff42180 | 2013-01-29 20:28:52 -0800 | [diff] [blame] | 281 | } |
| 282 | |
Naoki Shiota | 1151671 | 2013-06-05 22:36:01 -0700 | [diff] [blame] | 283 | /** |
| 284 | * Get list of all links whose state is ACTIVE. |
| 285 | * @return List of active links. Empty list if no port was found. |
| 286 | */ |
Pankaj Berde | ff42180 | 2013-01-29 20:28:52 -0800 | [diff] [blame] | 287 | public List<Link> getActiveLinks() { |
Toshio Koide | 7bdea5b | 2013-06-13 13:57:18 -0700 | [diff] [blame] | 288 | Iterable<ISwitchObject> switches = dbop.getActiveSwitches(); |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 289 | |
| 290 | List<Link> links = new ArrayList<Link>(); |
Naoki Shiota | 826e84a | 2013-06-18 13:13:25 -0700 | [diff] [blame] | 291 | |
| 292 | for (ISwitchObject srcSw : switches) { |
| 293 | for(IPortObject srcPort : srcSw.getPorts()) { |
| 294 | for(IPortObject dstPort : srcPort.getLinkedPorts()) { |
| 295 | ISwitchObject dstSw = dstPort.getSwitch(); |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 296 | |
Naoki Shiota | 826e84a | 2013-06-18 13:13:25 -0700 | [diff] [blame] | 297 | if(dstSw != null && dstSw.getState().equals("ACTIVE")) { |
| 298 | links.add(new Link(HexString.toLong(srcSw.getDPID()), |
| 299 | srcPort.getNumber(), |
| 300 | HexString.toLong(dstSw.getDPID()), |
| 301 | dstPort.getNumber())); |
| 302 | } |
| 303 | } |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 304 | } |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 305 | } |
Naoki Shiota | 826e84a | 2013-06-18 13:13:25 -0700 | [diff] [blame] | 306 | |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 307 | return links; |
Pankaj Berde | ff42180 | 2013-01-29 20:28:52 -0800 | [diff] [blame] | 308 | } |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 309 | |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame^] | 310 | @Override |
| 311 | public LinkInfo getLinkInfo(Link link) { |
| 312 | // TODO implement this |
| 313 | return null; |
| 314 | } |
| 315 | |
| 316 | /** |
| 317 | * Finalize the object. |
| 318 | */ |
| 319 | public void finalize() { |
| 320 | close(); |
| 321 | } |
| 322 | |
| 323 | /** |
| 324 | * Close LinkStorage. |
| 325 | */ |
| 326 | @Override |
| 327 | public void close() { |
| 328 | // TODO Auto-generated method stub |
| 329 | // graph.shutdown(); |
| 330 | } |
| 331 | |
| 332 | // TODO should be moved to TopoLinkServiceImpl (never used in this class) |
HIGUCHI Yuta | f05c480 | 2013-06-17 11:15:50 -0700 | [diff] [blame] | 333 | static class ExtractLink implements PipeFunction<PathPipe<Vertex>, Link> { |
Naoki Shiota | c57efb8 | 2013-06-18 13:40:28 -0700 | [diff] [blame] | 334 | |
Yuta HIGUCHI | 57e67f2 | 2013-10-14 10:21:05 -0700 | [diff] [blame] | 335 | @SuppressWarnings("unchecked") |
Naoki Shiota | c57efb8 | 2013-06-18 13:40:28 -0700 | [diff] [blame] | 336 | @Override |
| 337 | public Link compute(PathPipe<Vertex> pipe ) { |
Naoki Shiota | c57efb8 | 2013-06-18 13:40:28 -0700 | [diff] [blame] | 338 | long s_dpid = 0; |
| 339 | long d_dpid = 0; |
| 340 | short s_port = 0; |
| 341 | short d_port = 0; |
| 342 | List<Vertex> V = new ArrayList<Vertex>(); |
Yuta HIGUCHI | 57e67f2 | 2013-10-14 10:21:05 -0700 | [diff] [blame] | 343 | V = (List<Vertex>)pipe.next(); |
Naoki Shiota | c57efb8 | 2013-06-18 13:40:28 -0700 | [diff] [blame] | 344 | Vertex src_sw = V.get(0); |
| 345 | Vertex dest_sw = V.get(3); |
| 346 | Vertex src_port = V.get(1); |
| 347 | Vertex dest_port = V.get(2); |
| 348 | s_dpid = HexString.toLong((String) src_sw.getProperty("dpid")); |
| 349 | d_dpid = HexString.toLong((String) dest_sw.getProperty("dpid")); |
| 350 | s_port = (Short) src_port.getProperty("number"); |
| 351 | d_port = (Short) dest_port.getProperty("number"); |
| 352 | |
| 353 | Link l = new Link(s_dpid,s_port,d_dpid,d_port); |
| 354 | |
| 355 | return l; |
| 356 | } |
| 357 | } |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 358 | |
Pankaj Berde | ff42180 | 2013-01-29 20:28:52 -0800 | [diff] [blame] | 359 | |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 360 | } |