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