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 | |
Pankaj Berde | 2239f0d | 2013-04-04 09:42:43 -0700 | [diff] [blame] | 6 | import net.floodlightcontroller.core.INetMapTopologyObjects.IPortObject; |
Pankaj Berde | 1e2f731 | 2013-02-15 08:25:31 -0800 | [diff] [blame] | 7 | import net.floodlightcontroller.core.INetMapTopologyObjects.ISwitchObject; |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 8 | import net.floodlightcontroller.linkdiscovery.ILinkStorage; |
| 9 | import net.floodlightcontroller.linkdiscovery.LinkInfo; |
| 10 | import net.floodlightcontroller.routing.Link; |
Pankaj Berde | 2239f0d | 2013-04-04 09:42:43 -0700 | [diff] [blame] | 11 | import net.onrc.onos.util.GraphDBConnection; |
Pankaj Berde | 2239f0d | 2013-04-04 09:42:43 -0700 | [diff] [blame] | 12 | import net.onrc.onos.util.GraphDBConnection.Transaction; |
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); |
Pankaj Berde | 5fb2763 | 2013-04-05 08:56:12 -0700 | [diff] [blame] | 29 | protected String conf; |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 30 | |
Naoki Shiota | cae568a | 2013-06-05 17:53:41 -0700 | [diff] [blame] | 31 | /** |
| 32 | * Update |
| 33 | */ |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 34 | @Override |
| 35 | public void update(Link link, DM_OPERATION op) { |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 36 | update(link, (LinkInfo)null, op); |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | @Override |
| 40 | public void update(List<Link> links, DM_OPERATION op) { |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 41 | for (Link lt: links) { |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 42 | update(lt, (LinkInfo)null, op); |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 43 | } |
| 44 | } |
| 45 | |
| 46 | @Override |
| 47 | public void update(Link link, LinkInfo linkinfo, DM_OPERATION op) { |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 48 | switch (op) { |
| 49 | case UPDATE: |
| 50 | case CREATE: |
| 51 | case INSERT: |
Pankaj Berde | 254abb4 | 2013-06-10 21:21:49 -0700 | [diff] [blame] | 52 | updateLink(link, linkinfo, op); |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 53 | break; |
| 54 | case DELETE: |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 55 | deleteLink(link); |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 56 | break; |
| 57 | } |
| 58 | } |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 59 | |
Pankaj Berde | 254abb4 | 2013-06-10 21:21:49 -0700 | [diff] [blame] | 60 | public void updateLink(Link lt, LinkInfo linkinfo, DM_OPERATION op) { |
Pankaj Berde | 5fb2763 | 2013-04-05 08:56:12 -0700 | [diff] [blame] | 61 | GraphDBConnection conn = GraphDBConnection.getInstance(this.conf); |
| 62 | IPortObject vportSrc = null, vportDst = null; |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 63 | |
Pankaj Berde | 254abb4 | 2013-06-10 21:21:49 -0700 | [diff] [blame] | 64 | log.trace("updateLink(): op {} {} {}", new Object[]{op, lt, linkinfo}); |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 65 | |
| 66 | try { |
| 67 | // get source port vertex |
| 68 | String dpid = HexString.toHexString(lt.getSrc()); |
| 69 | short port = lt.getSrcPort(); |
Pankaj Berde | 5fb2763 | 2013-04-05 08:56:12 -0700 | [diff] [blame] | 70 | vportSrc = conn.utils().searchPort(conn, dpid, port); |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 71 | |
| 72 | // get dest port vertex |
| 73 | dpid = HexString.toHexString(lt.getDst()); |
| 74 | port = lt.getDstPort(); |
Pankaj Berde | 5fb2763 | 2013-04-05 08:56:12 -0700 | [diff] [blame] | 75 | vportDst = conn.utils().searchPort(conn, dpid, port); |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 76 | |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 77 | if (vportSrc != null && vportDst != null) { |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 78 | // check if the link exists |
Pankaj Berde | 77b5851 | 2013-04-05 12:06:37 -0700 | [diff] [blame] | 79 | |
Pankaj Berde | 6201614 | 2013-04-09 15:35:50 -0700 | [diff] [blame] | 80 | Iterable<IPortObject> currPorts = vportSrc.getLinkedPorts(); |
| 81 | List<IPortObject> currLinks = new ArrayList<IPortObject>(); |
Pankaj Berde | 77b5851 | 2013-04-05 12:06:37 -0700 | [diff] [blame] | 82 | for (IPortObject V : currPorts) { |
Pankaj Berde | 6debb04 | 2013-01-16 18:04:32 -0800 | [diff] [blame] | 83 | currLinks.add(V); |
| 84 | } |
Naoki Shiota | cae568a | 2013-06-05 17:53:41 -0700 | [diff] [blame] | 85 | |
Pankaj Berde | 6debb04 | 2013-01-16 18:04:32 -0800 | [diff] [blame] | 86 | if (currLinks.contains(vportDst)) { |
Naoki Shiota | 1b97286 | 2013-06-05 19:49:09 -0700 | [diff] [blame^] | 87 | // TODO: update linkinfo |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 88 | if (op.equals(DM_OPERATION.INSERT) || op.equals(DM_OPERATION.CREATE)) { |
Umesh Krishnaswamy | 9306f95 | 2013-01-24 20:42:59 -0800 | [diff] [blame] | 89 | log.debug("addOrUpdateLink(): failed link exists {} {} src {} dst {}", |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 90 | new Object[]{op, lt, vportSrc, vportDst}); |
| 91 | } |
Pankaj Berde | 0fc4e43 | 2013-01-12 09:47:22 -0800 | [diff] [blame] | 92 | } else { |
Naoki Shiota | 1b97286 | 2013-06-05 19:49:09 -0700 | [diff] [blame^] | 93 | vportSrc.setLinkPort(vportDst); |
Pankaj Berde | 6201614 | 2013-04-09 15:35:50 -0700 | [diff] [blame] | 94 | |
Pankaj Berde | 86a0d41 | 2013-04-05 15:06:26 -0700 | [diff] [blame] | 95 | conn.endTx(Transaction.COMMIT); |
Pankaj Berde | 254abb4 | 2013-06-10 21:21:49 -0700 | [diff] [blame] | 96 | 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] | 97 | } |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 98 | } else { |
Pankaj Berde | 254abb4 | 2013-06-10 21:21:49 -0700 | [diff] [blame] | 99 | log.error("updateLink(): failed invalid vertices {} {} src {} dst {}", new Object[]{op, lt, vportSrc, vportDst}); |
| 100 | conn.endTx(Transaction.ROLLBACK); |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 101 | } |
| 102 | } catch (TitanException e) { |
| 103 | /* |
| 104 | * retry till we succeed? |
| 105 | */ |
Umesh Krishnaswamy | c56a8cc | 2013-01-24 21:47:51 -0800 | [diff] [blame] | 106 | e.printStackTrace(); |
Pankaj Berde | 254abb4 | 2013-06-10 21:21:49 -0700 | [diff] [blame] | 107 | log.error("updateLink(): titan exception {} {} {}", new Object[]{op, lt, e.toString()}); |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 108 | } |
| 109 | } |
| 110 | |
| 111 | @Override |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 112 | public void deleteLinks(List<Link> links) { |
| 113 | |
| 114 | for (Link lt : links) { |
| 115 | deleteLink(lt); |
| 116 | } |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 117 | } |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 118 | |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 119 | |
| 120 | @Override |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 121 | public void deleteLink(Link lt) { |
Pankaj Berde | 5fb2763 | 2013-04-05 08:56:12 -0700 | [diff] [blame] | 122 | GraphDBConnection conn = GraphDBConnection.getInstance(this.conf); |
Pankaj Berde | 2239f0d | 2013-04-04 09:42:43 -0700 | [diff] [blame] | 123 | IPortObject vportSrc = null, vportDst = null; |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 124 | int count = 0; |
| 125 | |
| 126 | log.debug("deleteLink(): {}", lt); |
| 127 | |
| 128 | try { |
| 129 | // get source port vertex |
| 130 | String dpid = HexString.toHexString(lt.getSrc()); |
| 131 | short port = lt.getSrcPort(); |
Pankaj Berde | 2239f0d | 2013-04-04 09:42:43 -0700 | [diff] [blame] | 132 | vportSrc = conn.utils().searchPort(conn, dpid, port); |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 133 | |
| 134 | // get dst port vertex |
| 135 | dpid = HexString.toHexString(lt.getDst()); |
| 136 | port = lt.getDstPort(); |
Pankaj Berde | 2239f0d | 2013-04-04 09:42:43 -0700 | [diff] [blame] | 137 | vportDst = conn.utils().searchPort(conn, dpid, port); |
| 138 | // FIXME: This needs to remove all edges |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 139 | |
| 140 | if (vportSrc != null && vportDst != null) { |
Pankaj Berde | 2239f0d | 2013-04-04 09:42:43 -0700 | [diff] [blame] | 141 | |
| 142 | /* for (Edge e : vportSrc.asVertex().getEdges(Direction.OUT)) { |
Umesh Krishnaswamy | 11060ed | 2013-01-23 19:24:36 -0800 | [diff] [blame] | 143 | log.debug("deleteLink(): {} in {} out {}", |
| 144 | new Object[]{e.getLabel(), e.getVertex(Direction.IN), e.getVertex(Direction.OUT)}); |
| 145 | if (e.getLabel().equals("link") && e.getVertex(Direction.IN).equals(vportDst)) { |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 146 | graph.removeEdge(e); |
| 147 | count++; |
| 148 | } |
Pankaj Berde | 2239f0d | 2013-04-04 09:42:43 -0700 | [diff] [blame] | 149 | }*/ |
| 150 | vportSrc.removeLink(vportDst); |
Naoki Shiota | cae568a | 2013-06-05 17:53:41 -0700 | [diff] [blame] | 151 | |
Pankaj Berde | 5fb2763 | 2013-04-05 08:56:12 -0700 | [diff] [blame] | 152 | conn.endTx(Transaction.COMMIT); |
Pankaj Berde | 2239f0d | 2013-04-04 09:42:43 -0700 | [diff] [blame] | 153 | log.debug("deleteLink(): deleted edges src {} dst {}", new Object[]{ |
| 154 | lt, vportSrc, vportDst}); |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 155 | |
| 156 | } else { |
Umesh Krishnaswamy | 9306f95 | 2013-01-24 20:42:59 -0800 | [diff] [blame] | 157 | log.error("deleteLink(): failed invalid vertices {} src {} dst {}", new Object[]{lt, vportSrc, vportDst}); |
Pankaj Berde | 254abb4 | 2013-06-10 21:21:49 -0700 | [diff] [blame] | 158 | conn.endTx(Transaction.ROLLBACK); |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | } catch (TitanException e) { |
| 162 | /* |
| 163 | * retry till we succeed? |
| 164 | */ |
Umesh Krishnaswamy | c56a8cc | 2013-01-24 21:47:51 -0800 | [diff] [blame] | 165 | log.error("deleteLink(): titan exception {} {}", new Object[]{lt, e.toString()}); |
Pankaj Berde | 254abb4 | 2013-06-10 21:21:49 -0700 | [diff] [blame] | 166 | conn.endTx(Transaction.ROLLBACK); |
Umesh Krishnaswamy | c56a8cc | 2013-01-24 21:47:51 -0800 | [diff] [blame] | 167 | e.printStackTrace(); |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 168 | } |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 169 | } |
| 170 | |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 171 | @Override |
| 172 | public List<Link> getLinks(Long dpid, short port) { |
Pankaj Berde | 6201614 | 2013-04-09 15:35:50 -0700 | [diff] [blame] | 173 | GraphDBConnection conn = GraphDBConnection.getInstance(this.conf); |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 174 | IPortObject vportSrc; |
| 175 | |
| 176 | List<Link> links = new ArrayList<Link>(); |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 177 | |
Pankaj Berde | 6201614 | 2013-04-09 15:35:50 -0700 | [diff] [blame] | 178 | vportSrc = conn.utils().searchPort(conn, HexString.toHexString(dpid), port); |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 179 | if (vportSrc != null) { |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 180 | |
| 181 | for (Edge e : vportSrc.asVertex().getEdges(Direction.IN)) { |
| 182 | if(e.getLabel().equals("link")) { |
| 183 | Vertex v = e.getVertex(Direction.OUT); |
| 184 | short dst_port = v.getProperty("number"); |
| 185 | for(Edge e2 : v.getEdges(Direction.IN)) { |
| 186 | if(e2.getLabel().equals("on")) { |
| 187 | Vertex v2 = e2.getVertex(Direction.OUT); |
| 188 | long dst_dpid = HexString.toLong((String) v2.getProperty("dpid")); |
| 189 | |
| 190 | Link lt = new Link(dpid, port, dst_dpid, dst_port); |
| 191 | links.add(lt); |
| 192 | } |
| 193 | } |
| 194 | } |
| 195 | } |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 196 | } |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 197 | |
| 198 | return links; |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 199 | } |
| 200 | |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 201 | @Override |
| 202 | public void init(String conf) { |
Pankaj Berde | 1f10be0 | 2013-02-01 14:06:02 -0800 | [diff] [blame] | 203 | //TODO extract the DB location from properties |
Pankaj Berde | 67f88fb | 2013-01-15 17:16:01 -0800 | [diff] [blame] | 204 | |
Pankaj Berde | 5fb2763 | 2013-04-05 08:56:12 -0700 | [diff] [blame] | 205 | this.conf = conf; |
Pankaj Berde | 6201614 | 2013-04-09 15:35:50 -0700 | [diff] [blame] | 206 | |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 207 | } |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 208 | |
| 209 | @Override |
| 210 | public void deleteLinksOnPort(Long dpid, short port) { |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 211 | List<Link> linksToDelete = getLinks(dpid,port); |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 212 | |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 213 | for(Link l : linksToDelete) { |
| 214 | deleteLink(l); |
| 215 | } |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 216 | } |
| 217 | |
Naoki Shiota | 1b97286 | 2013-06-05 19:49:09 -0700 | [diff] [blame^] | 218 | // TODO: Fix me |
Pankaj Berde | ff42180 | 2013-01-29 20:28:52 -0800 | [diff] [blame] | 219 | @Override |
| 220 | public List<Link> getLinks(String dpid) { |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 221 | GraphDBConnection conn = GraphDBConnection.getInstance(this.conf); |
| 222 | ISwitchObject vswitch; |
| 223 | List<Link> links = new ArrayList<Link>(); |
| 224 | |
Naoki Shiota | 1b97286 | 2013-06-05 19:49:09 -0700 | [diff] [blame^] | 225 | // BEGIN: Trial code |
| 226 | // author: Naoki Shiota |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 227 | vswitch = conn.utils().searchSwitch(conn, dpid); |
| 228 | |
| 229 | for(IPortObject vportSrc : vswitch.getPorts()) { |
Naoki Shiota | 1b97286 | 2013-06-05 19:49:09 -0700 | [diff] [blame^] | 230 | // array concatenation may be heavy... |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 231 | List<Link> sublinks = getLinks(HexString.toLong(dpid), vportSrc.getNumber()); |
| 232 | links.addAll(sublinks); |
| 233 | } |
Naoki Shiota | 1b97286 | 2013-06-05 19:49:09 -0700 | [diff] [blame^] | 234 | // END: Trial code |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 235 | |
| 236 | return links; |
Pankaj Berde | ff42180 | 2013-01-29 20:28:52 -0800 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | public List<Link> getActiveLinks() { |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 240 | |
Pankaj Berde | 6201614 | 2013-04-09 15:35:50 -0700 | [diff] [blame] | 241 | GraphDBConnection conn = GraphDBConnection.getInstance(this.conf); |
Pankaj Berde | ff42180 | 2013-01-29 20:28:52 -0800 | [diff] [blame] | 242 | |
Pankaj Berde | 6201614 | 2013-04-09 15:35:50 -0700 | [diff] [blame] | 243 | Iterable<ISwitchObject> switches = conn.utils().getActiveSwitches(conn); |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 244 | |
| 245 | List<Link> links = new ArrayList<Link>(); |
| 246 | for (ISwitchObject sw : switches) { |
| 247 | GremlinPipeline<Vertex, Link> pipe = new GremlinPipeline<Vertex, Link>(); |
| 248 | ExtractLink extractor = new ExtractLink(); |
| 249 | |
| 250 | pipe.start(sw.asVertex()); |
| 251 | pipe.enablePath(true); |
Pankaj Berde | 1f10be0 | 2013-02-01 14:06:02 -0800 | [diff] [blame] | 252 | pipe.out("on").out("link").in("on").path().step(extractor); |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 253 | |
Pankaj Berde | 1f10be0 | 2013-02-01 14:06:02 -0800 | [diff] [blame] | 254 | while (pipe.hasNext() ) { |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 255 | Link l = pipe.next(); |
| 256 | links.add(l); |
| 257 | } |
| 258 | |
| 259 | } |
| 260 | return links; |
Pankaj Berde | ff42180 | 2013-01-29 20:28:52 -0800 | [diff] [blame] | 261 | } |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 262 | |
| 263 | static class ExtractLink implements PipeFunction<PathPipe<Vertex>, Link> { |
| 264 | |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 265 | @Override |
| 266 | public Link compute(PathPipe<Vertex> pipe ) { |
Pankaj Berde | d18c762 | 2013-02-04 10:28:35 -0800 | [diff] [blame] | 267 | // TODO Auto-generated method stub |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 268 | long s_dpid = 0; |
| 269 | long d_dpid = 0; |
| 270 | short s_port = 0; |
| 271 | short d_port = 0; |
| 272 | List<Vertex> V = new ArrayList<Vertex>(); |
| 273 | V = pipe.next(); |
| 274 | Vertex src_sw = V.get(0); |
| 275 | Vertex dest_sw = V.get(3); |
| 276 | Vertex src_port = V.get(1); |
| 277 | Vertex dest_port = V.get(2); |
| 278 | s_dpid = HexString.toLong((String) src_sw.getProperty("dpid")); |
| 279 | d_dpid = HexString.toLong((String) dest_sw.getProperty("dpid")); |
| 280 | s_port = (Short) src_port.getProperty("number"); |
| 281 | d_port = (Short) dest_port.getProperty("number"); |
| 282 | |
| 283 | Link l = new Link(s_dpid,s_port,d_dpid,d_port); |
| 284 | |
| 285 | return l; |
| 286 | } |
| 287 | } |
Pankaj Berde | d18c762 | 2013-02-04 10:28:35 -0800 | [diff] [blame] | 288 | |
| 289 | public void finalize() { |
| 290 | close(); |
| 291 | } |
| 292 | |
| 293 | @Override |
| 294 | public void close() { |
| 295 | // TODO Auto-generated method stub |
Pankaj Berde | 6201614 | 2013-04-09 15:35:50 -0700 | [diff] [blame] | 296 | // graph.shutdown(); |
Pankaj Berde | d18c762 | 2013-02-04 10:28:35 -0800 | [diff] [blame] | 297 | } |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 298 | |
Pankaj Berde | ff42180 | 2013-01-29 20:28:52 -0800 | [diff] [blame] | 299 | |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 300 | } |