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