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