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)) { |
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); |
Pankaj Berde | 254abb4 | 2013-06-10 21:21:49 -0700 | [diff] [blame] | 138 | 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] | 139 | } |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 140 | } else { |
Pankaj Berde | 254abb4 | 2013-06-10 21:21:49 -0700 | [diff] [blame] | 141 | log.error("updateLink(): failed invalid vertices {} {} src {} dst {}", new Object[]{op, lt, vportSrc, vportDst}); |
| 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 | 254abb4 | 2013-06-10 21:21:49 -0700 | [diff] [blame] | 149 | log.error("updateLink(): 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 | cae568a | 2013-06-05 17:53:41 -0700 | [diff] [blame] | 193 | |
Pankaj Berde | 5fb2763 | 2013-04-05 08:56:12 -0700 | [diff] [blame] | 194 | conn.endTx(Transaction.COMMIT); |
Pankaj Berde | 2239f0d | 2013-04-04 09:42:43 -0700 | [diff] [blame] | 195 | log.debug("deleteLink(): deleted edges src {} dst {}", new Object[]{ |
| 196 | lt, vportSrc, vportDst}); |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 197 | |
| 198 | } else { |
Umesh Krishnaswamy | 9306f95 | 2013-01-24 20:42:59 -0800 | [diff] [blame] | 199 | 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] | 200 | conn.endTx(Transaction.ROLLBACK); |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 201 | } |
| 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 | log.error("deleteLink(): titan exception {} {}", new Object[]{lt, e.toString()}); |
Pankaj Berde | 254abb4 | 2013-06-10 21:21:49 -0700 | [diff] [blame] | 208 | conn.endTx(Transaction.ROLLBACK); |
Umesh Krishnaswamy | c56a8cc | 2013-01-24 21:47:51 -0800 | [diff] [blame] | 209 | e.printStackTrace(); |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 210 | } |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 211 | } |
| 212 | |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 213 | @Override |
| 214 | public List<Link> getLinks(Long dpid, short port) { |
Pankaj Berde | 6201614 | 2013-04-09 15:35:50 -0700 | [diff] [blame] | 215 | GraphDBConnection conn = GraphDBConnection.getInstance(this.conf); |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 216 | IPortObject vportSrc; |
| 217 | |
| 218 | List<Link> links = new ArrayList<Link>(); |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 219 | |
Pankaj Berde | 6201614 | 2013-04-09 15:35:50 -0700 | [diff] [blame] | 220 | vportSrc = conn.utils().searchPort(conn, HexString.toHexString(dpid), port); |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 221 | if (vportSrc != null) { |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 222 | |
| 223 | for (Edge e : vportSrc.asVertex().getEdges(Direction.IN)) { |
| 224 | if(e.getLabel().equals("link")) { |
| 225 | Vertex v = e.getVertex(Direction.OUT); |
| 226 | short dst_port = v.getProperty("number"); |
| 227 | for(Edge e2 : v.getEdges(Direction.IN)) { |
| 228 | if(e2.getLabel().equals("on")) { |
| 229 | Vertex v2 = e2.getVertex(Direction.OUT); |
| 230 | long dst_dpid = HexString.toLong((String) v2.getProperty("dpid")); |
| 231 | |
| 232 | Link lt = new Link(dpid, port, dst_dpid, dst_port); |
| 233 | links.add(lt); |
| 234 | } |
| 235 | } |
| 236 | } |
| 237 | } |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 238 | } |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 239 | |
| 240 | return links; |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 241 | } |
| 242 | |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 243 | @Override |
| 244 | public void init(String conf) { |
Pankaj Berde | 1f10be0 | 2013-02-01 14:06:02 -0800 | [diff] [blame] | 245 | //TODO extract the DB location from properties |
Pankaj Berde | 67f88fb | 2013-01-15 17:16:01 -0800 | [diff] [blame] | 246 | |
Pankaj Berde | 5fb2763 | 2013-04-05 08:56:12 -0700 | [diff] [blame] | 247 | this.conf = conf; |
Pankaj Berde | 6201614 | 2013-04-09 15:35:50 -0700 | [diff] [blame] | 248 | |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 249 | } |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 250 | |
| 251 | @Override |
| 252 | public void deleteLinksOnPort(Long dpid, short port) { |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 253 | List<Link> linksToDelete = getLinks(dpid,port); |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 254 | |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 255 | for(Link l : linksToDelete) { |
| 256 | deleteLink(l); |
| 257 | } |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 258 | } |
| 259 | |
Naoki Shiota | 1b97286 | 2013-06-05 19:49:09 -0700 | [diff] [blame] | 260 | // TODO: Fix me |
Pankaj Berde | ff42180 | 2013-01-29 20:28:52 -0800 | [diff] [blame] | 261 | @Override |
| 262 | public List<Link> getLinks(String dpid) { |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 263 | GraphDBConnection conn = GraphDBConnection.getInstance(this.conf); |
| 264 | ISwitchObject vswitch; |
| 265 | List<Link> links = new ArrayList<Link>(); |
| 266 | |
Naoki Shiota | 1b97286 | 2013-06-05 19:49:09 -0700 | [diff] [blame] | 267 | // BEGIN: Trial code |
| 268 | // author: Naoki Shiota |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 269 | vswitch = conn.utils().searchSwitch(conn, dpid); |
| 270 | |
| 271 | for(IPortObject vportSrc : vswitch.getPorts()) { |
Naoki Shiota | 1b97286 | 2013-06-05 19:49:09 -0700 | [diff] [blame] | 272 | // array concatenation may be heavy... |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 273 | List<Link> sublinks = getLinks(HexString.toLong(dpid), vportSrc.getNumber()); |
| 274 | links.addAll(sublinks); |
| 275 | } |
Naoki Shiota | 1b97286 | 2013-06-05 19:49:09 -0700 | [diff] [blame] | 276 | // END: Trial code |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 277 | |
| 278 | return links; |
Pankaj Berde | ff42180 | 2013-01-29 20:28:52 -0800 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | public List<Link> getActiveLinks() { |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 282 | |
Pankaj Berde | 6201614 | 2013-04-09 15:35:50 -0700 | [diff] [blame] | 283 | GraphDBConnection conn = GraphDBConnection.getInstance(this.conf); |
Pankaj Berde | ff42180 | 2013-01-29 20:28:52 -0800 | [diff] [blame] | 284 | |
Pankaj Berde | 6201614 | 2013-04-09 15:35:50 -0700 | [diff] [blame] | 285 | Iterable<ISwitchObject> switches = conn.utils().getActiveSwitches(conn); |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 286 | |
| 287 | List<Link> links = new ArrayList<Link>(); |
| 288 | for (ISwitchObject sw : switches) { |
| 289 | GremlinPipeline<Vertex, Link> pipe = new GremlinPipeline<Vertex, Link>(); |
| 290 | ExtractLink extractor = new ExtractLink(); |
| 291 | |
| 292 | pipe.start(sw.asVertex()); |
| 293 | pipe.enablePath(true); |
Pankaj Berde | 1f10be0 | 2013-02-01 14:06:02 -0800 | [diff] [blame] | 294 | pipe.out("on").out("link").in("on").path().step(extractor); |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 295 | |
Pankaj Berde | 1f10be0 | 2013-02-01 14:06:02 -0800 | [diff] [blame] | 296 | while (pipe.hasNext() ) { |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 297 | Link l = pipe.next(); |
| 298 | links.add(l); |
| 299 | } |
| 300 | |
| 301 | } |
| 302 | return links; |
Pankaj Berde | ff42180 | 2013-01-29 20:28:52 -0800 | [diff] [blame] | 303 | } |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 304 | |
| 305 | static class ExtractLink implements PipeFunction<PathPipe<Vertex>, Link> { |
| 306 | |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 307 | @Override |
| 308 | public Link compute(PathPipe<Vertex> pipe ) { |
Pankaj Berde | d18c762 | 2013-02-04 10:28:35 -0800 | [diff] [blame] | 309 | // TODO Auto-generated method stub |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 310 | long s_dpid = 0; |
| 311 | long d_dpid = 0; |
| 312 | short s_port = 0; |
| 313 | short d_port = 0; |
| 314 | List<Vertex> V = new ArrayList<Vertex>(); |
| 315 | V = pipe.next(); |
| 316 | Vertex src_sw = V.get(0); |
| 317 | Vertex dest_sw = V.get(3); |
| 318 | Vertex src_port = V.get(1); |
| 319 | Vertex dest_port = V.get(2); |
| 320 | s_dpid = HexString.toLong((String) src_sw.getProperty("dpid")); |
| 321 | d_dpid = HexString.toLong((String) dest_sw.getProperty("dpid")); |
| 322 | s_port = (Short) src_port.getProperty("number"); |
| 323 | d_port = (Short) dest_port.getProperty("number"); |
| 324 | |
| 325 | Link l = new Link(s_dpid,s_port,d_dpid,d_port); |
| 326 | |
| 327 | return l; |
| 328 | } |
| 329 | } |
Pankaj Berde | d18c762 | 2013-02-04 10:28:35 -0800 | [diff] [blame] | 330 | |
| 331 | public void finalize() { |
| 332 | close(); |
| 333 | } |
| 334 | |
| 335 | @Override |
| 336 | public void close() { |
| 337 | // TODO Auto-generated method stub |
Pankaj Berde | 6201614 | 2013-04-09 15:35:50 -0700 | [diff] [blame] | 338 | // graph.shutdown(); |
Pankaj Berde | d18c762 | 2013-02-04 10:28:35 -0800 | [diff] [blame] | 339 | } |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 340 | |
Pankaj Berde | ff42180 | 2013-01-29 20:28:52 -0800 | [diff] [blame] | 341 | |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 342 | } |