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 | cb05c66 | 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: |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 52 | addOrUpdateLink(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 | |
| 60 | public void addOrUpdateLink(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 | |
Umesh Krishnaswamy | 0ef75ee | 2013-03-25 17:50:27 -0700 | [diff] [blame] | 64 | log.trace("addOrUpdateLink(): 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 | cb05c66 | 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)) { |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 87 | if (op.equals(DM_OPERATION.INSERT) || op.equals(DM_OPERATION.CREATE)) { |
Umesh Krishnaswamy | 9306f95 | 2013-01-24 20:42:59 -0800 | [diff] [blame] | 88 | log.debug("addOrUpdateLink(): failed link exists {} {} src {} dst {}", |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 89 | new Object[]{op, lt, vportSrc, vportDst}); |
mininet | c7f49a8 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 90 | } else if (op.equals(DM_OPERATION.UPDATE)) { |
| 91 | // TODO: update linkinfo |
| 92 | // GraphDB seems to have no KeyIndex for LinkInfo data |
Naoki Shiota | cb05c66 | 2013-06-05 17:53:41 -0700 | [diff] [blame^] | 93 | |
| 94 | // BEGIN: trial code (update implementation) |
| 95 | if(linkinfo != null) { |
| 96 | vportSrc.setPortState(linkinfo.getSrcPortState()); |
| 97 | vportDst.setPortState(linkinfo.getDstPortState()); |
| 98 | |
| 99 | Vertex vsrc = vportSrc.asVertex(); |
| 100 | vsrc.setProperty("first_seen_time", linkinfo.getFirstSeenTime()); |
| 101 | vsrc.setProperty("last_lldp_received_time", linkinfo.getUnicastValidTime()); |
| 102 | vsrc.setProperty("last_bddp_received_time", linkinfo.getMulticastValidTime()); |
| 103 | |
| 104 | // for(Edge e: vportSrc.asVertex().getEdges(Direction.OUT)) { |
| 105 | // if(e.getVertex(Direction.OUT).equals(vportDst.asVertex())) { |
| 106 | // e.setProperty("first_seen_time", linkinfo.getFirstSeenTime()); |
| 107 | // e.setProperty("last_lldp_received_time", linkinfo.getUnicastValidTime()); |
| 108 | // e.setProperty("last_bddp_received_time", linkinfo.getMulticastValidTime()); |
| 109 | // } |
| 110 | // } |
| 111 | |
| 112 | conn.endTx(Transaction.COMMIT); |
| 113 | log.debug("addOrUpdateLink(): link updated {} {} src {} dst {}", new Object[]{op, lt, vportSrc, vportDst}); |
| 114 | } |
| 115 | // END: trial code |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 116 | } |
Pankaj Berde | 0fc4e43 | 2013-01-12 09:47:22 -0800 | [diff] [blame] | 117 | } else { |
Naoki Shiota | cb05c66 | 2013-06-05 17:53:41 -0700 | [diff] [blame^] | 118 | if (op.equals(DM_OPERATION.UPDATE)) { |
| 119 | log.debug("addOrUpdateLink(): failed link doesn't exist {} {} src {} dst {}", |
| 120 | new Object[]{op, lt, vportSrc, vportDst}); |
| 121 | } else { |
| 122 | vportSrc.setLinkPort(vportDst); |
| 123 | |
| 124 | // BEGIN: trial code (update implementation) |
| 125 | if(linkinfo != null) { |
| 126 | vportSrc.setPortState(linkinfo.getSrcPortState()); |
| 127 | vportDst.setPortState(linkinfo.getDstPortState()); |
| 128 | |
| 129 | Vertex vsrc = vportSrc.asVertex(); |
| 130 | vsrc.setProperty("first_seen_time", linkinfo.getFirstSeenTime()); |
| 131 | vsrc.setProperty("last_lldp_received_time", linkinfo.getUnicastValidTime()); |
| 132 | vsrc.setProperty("last_bddp_received_time", linkinfo.getMulticastValidTime()); |
| 133 | } |
| 134 | // END: trial code |
| 135 | } |
Pankaj Berde | 6201614 | 2013-04-09 15:35:50 -0700 | [diff] [blame] | 136 | |
Pankaj Berde | 86a0d41 | 2013-04-05 15:06:26 -0700 | [diff] [blame] | 137 | conn.endTx(Transaction.COMMIT); |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 138 | log.debug("addOrUpdateLink(): link added {} {} src {} dst {}", new Object[]{op, lt, vportSrc, vportDst}); |
Pankaj Berde | 0fc4e43 | 2013-01-12 09:47:22 -0800 | [diff] [blame] | 139 | } |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 140 | } else { |
Umesh Krishnaswamy | 9306f95 | 2013-01-24 20:42:59 -0800 | [diff] [blame] | 141 | log.error("addOrUpdateLink(): failed invalid vertices {} {} src {} dst {}", new Object[]{op, lt, vportSrc, vportDst}); |
Pankaj Berde | 6201614 | 2013-04-09 15:35:50 -0700 | [diff] [blame] | 142 | // conn.endTx(Transaction.ROLLBACK); |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 143 | } |
| 144 | } catch (TitanException e) { |
| 145 | /* |
| 146 | * retry till we succeed? |
| 147 | */ |
Umesh Krishnaswamy | c56a8cc | 2013-01-24 21:47:51 -0800 | [diff] [blame] | 148 | e.printStackTrace(); |
Pankaj Berde | 6201614 | 2013-04-09 15:35:50 -0700 | [diff] [blame] | 149 | log.error("addOrUpdateLink(): titan exception {} {} {}", new Object[]{op, lt, e.toString()}); |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 150 | } |
| 151 | } |
| 152 | |
| 153 | @Override |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 154 | public void deleteLinks(List<Link> links) { |
| 155 | |
| 156 | for (Link lt : links) { |
| 157 | deleteLink(lt); |
| 158 | } |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 159 | } |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 160 | |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 161 | |
| 162 | @Override |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 163 | public void deleteLink(Link lt) { |
Pankaj Berde | 5fb2763 | 2013-04-05 08:56:12 -0700 | [diff] [blame] | 164 | GraphDBConnection conn = GraphDBConnection.getInstance(this.conf); |
Pankaj Berde | 2239f0d | 2013-04-04 09:42:43 -0700 | [diff] [blame] | 165 | IPortObject vportSrc = null, vportDst = null; |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 166 | int count = 0; |
| 167 | |
| 168 | log.debug("deleteLink(): {}", lt); |
| 169 | |
| 170 | try { |
| 171 | // get source port vertex |
| 172 | String dpid = HexString.toHexString(lt.getSrc()); |
| 173 | short port = lt.getSrcPort(); |
Pankaj Berde | 2239f0d | 2013-04-04 09:42:43 -0700 | [diff] [blame] | 174 | vportSrc = conn.utils().searchPort(conn, dpid, port); |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 175 | |
| 176 | // get dst port vertex |
| 177 | dpid = HexString.toHexString(lt.getDst()); |
| 178 | port = lt.getDstPort(); |
Pankaj Berde | 2239f0d | 2013-04-04 09:42:43 -0700 | [diff] [blame] | 179 | vportDst = conn.utils().searchPort(conn, dpid, port); |
| 180 | // FIXME: This needs to remove all edges |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 181 | |
| 182 | if (vportSrc != null && vportDst != null) { |
Pankaj Berde | 2239f0d | 2013-04-04 09:42:43 -0700 | [diff] [blame] | 183 | |
| 184 | /* for (Edge e : vportSrc.asVertex().getEdges(Direction.OUT)) { |
Umesh Krishnaswamy | 11060ed | 2013-01-23 19:24:36 -0800 | [diff] [blame] | 185 | log.debug("deleteLink(): {} in {} out {}", |
| 186 | new Object[]{e.getLabel(), e.getVertex(Direction.IN), e.getVertex(Direction.OUT)}); |
| 187 | if (e.getLabel().equals("link") && e.getVertex(Direction.IN).equals(vportDst)) { |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 188 | graph.removeEdge(e); |
| 189 | count++; |
| 190 | } |
Pankaj Berde | 2239f0d | 2013-04-04 09:42:43 -0700 | [diff] [blame] | 191 | }*/ |
| 192 | vportSrc.removeLink(vportDst); |
Naoki Shiota | cb05c66 | 2013-06-05 17:53:41 -0700 | [diff] [blame^] | 193 | |
| 194 | // BEGIN: trial code (update implementation) |
| 195 | Vertex vsrc = vportSrc.asVertex(); |
| 196 | vsrc.removeProperty("first_seen_time"); |
| 197 | vsrc.removeProperty("last_lldp_received_time"); |
| 198 | vsrc.removeProperty("last_bddp_received_time"); |
| 199 | // END: trial code |
| 200 | |
Pankaj Berde | 5fb2763 | 2013-04-05 08:56:12 -0700 | [diff] [blame] | 201 | conn.endTx(Transaction.COMMIT); |
Pankaj Berde | 2239f0d | 2013-04-04 09:42:43 -0700 | [diff] [blame] | 202 | log.debug("deleteLink(): deleted edges src {} dst {}", new Object[]{ |
| 203 | lt, vportSrc, vportDst}); |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 204 | |
| 205 | } else { |
Umesh Krishnaswamy | 9306f95 | 2013-01-24 20:42:59 -0800 | [diff] [blame] | 206 | log.error("deleteLink(): failed invalid vertices {} src {} dst {}", new Object[]{lt, vportSrc, vportDst}); |
Pankaj Berde | 6201614 | 2013-04-09 15:35:50 -0700 | [diff] [blame] | 207 | // conn.endTx(Transaction.ROLLBACK); |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | } catch (TitanException e) { |
| 211 | /* |
| 212 | * retry till we succeed? |
| 213 | */ |
Umesh Krishnaswamy | c56a8cc | 2013-01-24 21:47:51 -0800 | [diff] [blame] | 214 | log.error("deleteLink(): titan exception {} {}", new Object[]{lt, e.toString()}); |
| 215 | e.printStackTrace(); |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 216 | } |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 217 | } |
| 218 | |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 219 | @Override |
| 220 | public List<Link> getLinks(Long dpid, short port) { |
Pankaj Berde | 6201614 | 2013-04-09 15:35:50 -0700 | [diff] [blame] | 221 | GraphDBConnection conn = GraphDBConnection.getInstance(this.conf); |
mininet | c7f49a8 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 222 | IPortObject vportSrc; |
| 223 | |
| 224 | List<Link> links = new ArrayList<Link>(); |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 225 | |
Pankaj Berde | 6201614 | 2013-04-09 15:35:50 -0700 | [diff] [blame] | 226 | vportSrc = conn.utils().searchPort(conn, HexString.toHexString(dpid), port); |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 227 | if (vportSrc != null) { |
mininet | c7f49a8 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 228 | |
| 229 | for (Edge e : vportSrc.asVertex().getEdges(Direction.IN)) { |
| 230 | if(e.getLabel().equals("link")) { |
| 231 | Vertex v = e.getVertex(Direction.OUT); |
| 232 | short dst_port = v.getProperty("number"); |
| 233 | for(Edge e2 : v.getEdges(Direction.IN)) { |
| 234 | if(e2.getLabel().equals("on")) { |
| 235 | Vertex v2 = e2.getVertex(Direction.OUT); |
| 236 | long dst_dpid = HexString.toLong((String) v2.getProperty("dpid")); |
| 237 | |
| 238 | Link lt = new Link(dpid, port, dst_dpid, dst_port); |
| 239 | links.add(lt); |
| 240 | } |
| 241 | } |
| 242 | } |
| 243 | } |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 244 | } |
mininet | c7f49a8 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 245 | |
| 246 | return links; |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 247 | } |
| 248 | |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 249 | @Override |
| 250 | public void init(String conf) { |
Pankaj Berde | 1f10be0 | 2013-02-01 14:06:02 -0800 | [diff] [blame] | 251 | //TODO extract the DB location from properties |
Pankaj Berde | 67f88fb | 2013-01-15 17:16:01 -0800 | [diff] [blame] | 252 | |
Pankaj Berde | 5fb2763 | 2013-04-05 08:56:12 -0700 | [diff] [blame] | 253 | this.conf = conf; |
Pankaj Berde | 6201614 | 2013-04-09 15:35:50 -0700 | [diff] [blame] | 254 | |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 255 | } |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 256 | |
| 257 | @Override |
| 258 | public void deleteLinksOnPort(Long dpid, short port) { |
mininet | c7f49a8 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 259 | List<Link> linksToDelete = getLinks(dpid,port); |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 260 | |
mininet | c7f49a8 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 261 | for(Link l : linksToDelete) { |
| 262 | deleteLink(l); |
| 263 | } |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 264 | } |
| 265 | |
Pankaj Berde | ff42180 | 2013-01-29 20:28:52 -0800 | [diff] [blame] | 266 | @Override |
| 267 | public List<Link> getLinks(String dpid) { |
mininet | c7f49a8 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 268 | GraphDBConnection conn = GraphDBConnection.getInstance(this.conf); |
| 269 | ISwitchObject vswitch; |
| 270 | List<Link> links = new ArrayList<Link>(); |
| 271 | |
| 272 | vswitch = conn.utils().searchSwitch(conn, dpid); |
| 273 | |
| 274 | for(IPortObject vportSrc : vswitch.getPorts()) { |
| 275 | // TODO array concatenation may be heavy |
| 276 | List<Link> sublinks = getLinks(HexString.toLong(dpid), vportSrc.getNumber()); |
| 277 | links.addAll(sublinks); |
| 278 | } |
| 279 | |
| 280 | return links; |
Pankaj Berde | ff42180 | 2013-01-29 20:28:52 -0800 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | public List<Link> getActiveLinks() { |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 284 | |
Pankaj Berde | 6201614 | 2013-04-09 15:35:50 -0700 | [diff] [blame] | 285 | GraphDBConnection conn = GraphDBConnection.getInstance(this.conf); |
Pankaj Berde | ff42180 | 2013-01-29 20:28:52 -0800 | [diff] [blame] | 286 | |
Pankaj Berde | 6201614 | 2013-04-09 15:35:50 -0700 | [diff] [blame] | 287 | Iterable<ISwitchObject> switches = conn.utils().getActiveSwitches(conn); |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 288 | |
| 289 | List<Link> links = new ArrayList<Link>(); |
| 290 | for (ISwitchObject sw : switches) { |
| 291 | GremlinPipeline<Vertex, Link> pipe = new GremlinPipeline<Vertex, Link>(); |
| 292 | ExtractLink extractor = new ExtractLink(); |
| 293 | |
| 294 | pipe.start(sw.asVertex()); |
| 295 | pipe.enablePath(true); |
Pankaj Berde | 1f10be0 | 2013-02-01 14:06:02 -0800 | [diff] [blame] | 296 | pipe.out("on").out("link").in("on").path().step(extractor); |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 297 | |
Pankaj Berde | 1f10be0 | 2013-02-01 14:06:02 -0800 | [diff] [blame] | 298 | while (pipe.hasNext() ) { |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 299 | Link l = pipe.next(); |
| 300 | links.add(l); |
| 301 | } |
| 302 | |
| 303 | } |
| 304 | return links; |
Pankaj Berde | ff42180 | 2013-01-29 20:28:52 -0800 | [diff] [blame] | 305 | } |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 306 | |
| 307 | static class ExtractLink implements PipeFunction<PathPipe<Vertex>, Link> { |
| 308 | |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 309 | @Override |
| 310 | public Link compute(PathPipe<Vertex> pipe ) { |
Pankaj Berde | d18c762 | 2013-02-04 10:28:35 -0800 | [diff] [blame] | 311 | // TODO Auto-generated method stub |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 312 | long s_dpid = 0; |
| 313 | long d_dpid = 0; |
| 314 | short s_port = 0; |
| 315 | short d_port = 0; |
| 316 | List<Vertex> V = new ArrayList<Vertex>(); |
| 317 | V = pipe.next(); |
| 318 | Vertex src_sw = V.get(0); |
| 319 | Vertex dest_sw = V.get(3); |
| 320 | Vertex src_port = V.get(1); |
| 321 | Vertex dest_port = V.get(2); |
| 322 | s_dpid = HexString.toLong((String) src_sw.getProperty("dpid")); |
| 323 | d_dpid = HexString.toLong((String) dest_sw.getProperty("dpid")); |
| 324 | s_port = (Short) src_port.getProperty("number"); |
| 325 | d_port = (Short) dest_port.getProperty("number"); |
| 326 | |
| 327 | Link l = new Link(s_dpid,s_port,d_dpid,d_port); |
| 328 | |
| 329 | return l; |
| 330 | } |
| 331 | } |
Pankaj Berde | d18c762 | 2013-02-04 10:28:35 -0800 | [diff] [blame] | 332 | |
| 333 | public void finalize() { |
| 334 | close(); |
| 335 | } |
| 336 | |
| 337 | @Override |
| 338 | public void close() { |
| 339 | // TODO Auto-generated method stub |
Pankaj Berde | 6201614 | 2013-04-09 15:35:50 -0700 | [diff] [blame] | 340 | // graph.shutdown(); |
Pankaj Berde | d18c762 | 2013-02-04 10:28:35 -0800 | [diff] [blame] | 341 | } |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 342 | |
Pankaj Berde | ff42180 | 2013-01-29 20:28:52 -0800 | [diff] [blame] | 343 | |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 344 | } |