HIGUCHI Yuta | 2d01158 | 2013-06-15 01:47:11 -0700 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.core.internal; |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 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 | |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 6 | import net.floodlightcontroller.routing.Link; |
HIGUCHI Yuta | 2d01158 | 2013-06-15 01:47:11 -0700 | [diff] [blame] | 7 | import net.onrc.onos.ofcontroller.core.ILinkStorage; |
HIGUCHI Yuta | 2051490 | 2013-06-12 11:24:16 -0700 | [diff] [blame] | 8 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IPortObject; |
| 9 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject; |
HIGUCHI Yuta | a56fbde | 2013-06-17 14:26:05 -0700 | [diff] [blame] | 10 | import net.onrc.onos.ofcontroller.linkdiscovery.LinkInfo; |
Toshio Koide | 7bdea5b | 2013-06-13 13:57:18 -0700 | [diff] [blame] | 11 | import net.onrc.onos.util.GraphDBOperation; |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 12 | |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 13 | import org.openflow.util.HexString; |
| 14 | import org.slf4j.Logger; |
| 15 | import org.slf4j.LoggerFactory; |
| 16 | |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 17 | import com.thinkaurelius.titan.core.TitanException; |
Naoki Shiota | c57efb8 | 2013-06-18 13:40:28 -0700 | [diff] [blame] | 18 | import com.tinkerpop.blueprints.Direction; |
| 19 | import com.tinkerpop.blueprints.Edge; |
| 20 | import com.tinkerpop.blueprints.Vertex; |
| 21 | import com.tinkerpop.gremlin.java.GremlinPipeline; |
| 22 | import com.tinkerpop.pipes.PipeFunction; |
| 23 | import com.tinkerpop.pipes.transform.PathPipe; |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 24 | |
| 25 | public class LinkStorageImpl implements ILinkStorage { |
Pankaj Berde | 6201614 | 2013-04-09 15:35:50 -0700 | [diff] [blame] | 26 | |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 27 | protected static Logger log = LoggerFactory.getLogger(LinkStorageImpl.class); |
Toshio Koide | 7bdea5b | 2013-06-13 13:57:18 -0700 | [diff] [blame] | 28 | protected GraphDBOperation dbop; |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 29 | |
Naoki Shiota | 1151671 | 2013-06-05 22:36:01 -0700 | [diff] [blame] | 30 | /** |
| 31 | * Update a record in the LinkStorage in a way provided by op. |
| 32 | * @param link Record of a link to be updated. |
| 33 | * @param op Operation to be done. |
| 34 | */ |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 35 | @Override |
| 36 | public void update(Link link, DM_OPERATION op) { |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 37 | update(link, (LinkInfo)null, op); |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 38 | } |
| 39 | |
Naoki Shiota | 1151671 | 2013-06-05 22:36:01 -0700 | [diff] [blame] | 40 | /** |
| 41 | * Update multiple records in the LinkStorage in a way provided by op. |
| 42 | * @param links List of records to be updated. |
| 43 | * @param op Operation to be done. |
| 44 | */ |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 45 | @Override |
| 46 | public void update(List<Link> links, DM_OPERATION op) { |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 47 | for (Link lt: links) { |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 48 | update(lt, (LinkInfo)null, op); |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 49 | } |
| 50 | } |
| 51 | |
Naoki Shiota | 1151671 | 2013-06-05 22:36:01 -0700 | [diff] [blame] | 52 | /** |
| 53 | * Update a record of link with meta-information in the LinkStorage in a way provided by op. |
| 54 | * @param link Record of a link to update. |
| 55 | * @param linkinfo Meta-information of a link to be updated. |
| 56 | * @param op Operation to be done. |
| 57 | */ |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 58 | @Override |
| 59 | public void update(Link link, LinkInfo linkinfo, DM_OPERATION op) { |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 60 | switch (op) { |
| 61 | case UPDATE: |
| 62 | case CREATE: |
| 63 | case INSERT: |
Pankaj Berde | 254abb4 | 2013-06-10 21:21:49 -0700 | [diff] [blame] | 64 | updateLink(link, linkinfo, op); |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 65 | break; |
| 66 | case DELETE: |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 67 | deleteLink(link); |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 68 | break; |
| 69 | } |
| 70 | } |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 71 | |
Naoki Shiota | 1151671 | 2013-06-05 22:36:01 -0700 | [diff] [blame] | 72 | /** |
| 73 | * Perform INSERT/CREATE/UPDATE operation to update the LinkStorage. |
| 74 | * @param lt Record of a link to be updated. |
| 75 | * @param linkinfo Meta-information of a link to be updated. |
| 76 | * @param op Operation to be done. (only INSERT/CREATE/UPDATE is acceptable) |
| 77 | */ |
Pankaj Berde | 254abb4 | 2013-06-10 21:21:49 -0700 | [diff] [blame] | 78 | public void updateLink(Link lt, LinkInfo linkinfo, DM_OPERATION op) { |
Pankaj Berde | 5fb2763 | 2013-04-05 08:56:12 -0700 | [diff] [blame] | 79 | IPortObject vportSrc = null, vportDst = null; |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 80 | |
Pankaj Berde | 254abb4 | 2013-06-10 21:21:49 -0700 | [diff] [blame] | 81 | log.trace("updateLink(): op {} {} {}", new Object[]{op, lt, linkinfo}); |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 82 | |
| 83 | try { |
| 84 | // get source port vertex |
| 85 | String dpid = HexString.toHexString(lt.getSrc()); |
| 86 | short port = lt.getSrcPort(); |
Toshio Koide | 7bdea5b | 2013-06-13 13:57:18 -0700 | [diff] [blame] | 87 | vportSrc = dbop.searchPort(dpid, port); |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 88 | |
| 89 | // get dest port vertex |
| 90 | dpid = HexString.toHexString(lt.getDst()); |
| 91 | port = lt.getDstPort(); |
Toshio Koide | 7bdea5b | 2013-06-13 13:57:18 -0700 | [diff] [blame] | 92 | vportDst = dbop.searchPort(dpid, port); |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 93 | |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 94 | if (vportSrc != null && vportDst != null) { |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 95 | // check if the link exists |
Pankaj Berde | 77b5851 | 2013-04-05 12:06:37 -0700 | [diff] [blame] | 96 | |
Pankaj Berde | 6201614 | 2013-04-09 15:35:50 -0700 | [diff] [blame] | 97 | Iterable<IPortObject> currPorts = vportSrc.getLinkedPorts(); |
| 98 | List<IPortObject> currLinks = new ArrayList<IPortObject>(); |
Pankaj Berde | 77b5851 | 2013-04-05 12:06:37 -0700 | [diff] [blame] | 99 | for (IPortObject V : currPorts) { |
Pankaj Berde | 6debb04 | 2013-01-16 18:04:32 -0800 | [diff] [blame] | 100 | currLinks.add(V); |
| 101 | } |
Naoki Shiota | cae568a | 2013-06-05 17:53:41 -0700 | [diff] [blame] | 102 | |
Pankaj Berde | 6debb04 | 2013-01-16 18:04:32 -0800 | [diff] [blame] | 103 | if (currLinks.contains(vportDst)) { |
Naoki Shiota | b0d0c00 | 2013-06-05 20:21:20 -0700 | [diff] [blame] | 104 | // TODO: update linkinfo |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 105 | if (op.equals(DM_OPERATION.INSERT) || op.equals(DM_OPERATION.CREATE)) { |
Umesh Krishnaswamy | 9306f95 | 2013-01-24 20:42:59 -0800 | [diff] [blame] | 106 | log.debug("addOrUpdateLink(): failed link exists {} {} src {} dst {}", |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 107 | new Object[]{op, lt, vportSrc, vportDst}); |
| 108 | } |
Pankaj Berde | 0fc4e43 | 2013-01-12 09:47:22 -0800 | [diff] [blame] | 109 | } else { |
Naoki Shiota | b0d0c00 | 2013-06-05 20:21:20 -0700 | [diff] [blame] | 110 | vportSrc.setLinkPort(vportDst); |
Pankaj Berde | 6201614 | 2013-04-09 15:35:50 -0700 | [diff] [blame] | 111 | |
Toshio Koide | 7bdea5b | 2013-06-13 13:57:18 -0700 | [diff] [blame] | 112 | dbop.commit(); |
Pankaj Berde | 254abb4 | 2013-06-10 21:21:49 -0700 | [diff] [blame] | 113 | 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] | 114 | } |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 115 | } else { |
Pankaj Berde | 254abb4 | 2013-06-10 21:21:49 -0700 | [diff] [blame] | 116 | log.error("updateLink(): failed invalid vertices {} {} src {} dst {}", new Object[]{op, lt, vportSrc, vportDst}); |
Toshio Koide | 7bdea5b | 2013-06-13 13:57:18 -0700 | [diff] [blame] | 117 | dbop.rollback(); |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 118 | } |
| 119 | } catch (TitanException e) { |
| 120 | /* |
| 121 | * retry till we succeed? |
| 122 | */ |
Umesh Krishnaswamy | c56a8cc | 2013-01-24 21:47:51 -0800 | [diff] [blame] | 123 | e.printStackTrace(); |
Pankaj Berde | 254abb4 | 2013-06-10 21:21:49 -0700 | [diff] [blame] | 124 | log.error("updateLink(): titan exception {} {} {}", new Object[]{op, lt, e.toString()}); |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 125 | } |
| 126 | } |
| 127 | |
Naoki Shiota | 1151671 | 2013-06-05 22:36:01 -0700 | [diff] [blame] | 128 | /** |
| 129 | * Delete multiple records in the LinkStorage. |
| 130 | * @param links List of records to be deleted. |
| 131 | */ |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 132 | @Override |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 133 | public void deleteLinks(List<Link> links) { |
| 134 | |
| 135 | for (Link lt : links) { |
| 136 | deleteLink(lt); |
| 137 | } |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 138 | } |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 139 | |
Naoki Shiota | 1151671 | 2013-06-05 22:36:01 -0700 | [diff] [blame] | 140 | /** |
| 141 | * Delete a record in the LinkStorage. |
| 142 | * @param link Record to be deleted. |
| 143 | */ |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 144 | @Override |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 145 | public void deleteLink(Link lt) { |
Pankaj Berde | 2239f0d | 2013-04-04 09:42:43 -0700 | [diff] [blame] | 146 | IPortObject vportSrc = null, vportDst = null; |
Naoki Shiota | c57efb8 | 2013-06-18 13:40:28 -0700 | [diff] [blame] | 147 | int count = 0; |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 148 | |
| 149 | log.debug("deleteLink(): {}", lt); |
| 150 | |
| 151 | try { |
| 152 | // get source port vertex |
| 153 | String dpid = HexString.toHexString(lt.getSrc()); |
| 154 | short port = lt.getSrcPort(); |
Toshio Koide | 7bdea5b | 2013-06-13 13:57:18 -0700 | [diff] [blame] | 155 | vportSrc = dbop.searchPort(dpid, port); |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 156 | |
| 157 | // get dst port vertex |
| 158 | dpid = HexString.toHexString(lt.getDst()); |
| 159 | port = lt.getDstPort(); |
Toshio Koide | 7bdea5b | 2013-06-13 13:57:18 -0700 | [diff] [blame] | 160 | vportDst = dbop.searchPort(dpid, port); |
Pankaj Berde | 2239f0d | 2013-04-04 09:42:43 -0700 | [diff] [blame] | 161 | // FIXME: This needs to remove all edges |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 162 | |
| 163 | if (vportSrc != null && vportDst != null) { |
Pankaj Berde | 2239f0d | 2013-04-04 09:42:43 -0700 | [diff] [blame] | 164 | |
| 165 | /* for (Edge e : vportSrc.asVertex().getEdges(Direction.OUT)) { |
Umesh Krishnaswamy | 11060ed | 2013-01-23 19:24:36 -0800 | [diff] [blame] | 166 | log.debug("deleteLink(): {} in {} out {}", |
| 167 | new Object[]{e.getLabel(), e.getVertex(Direction.IN), e.getVertex(Direction.OUT)}); |
| 168 | if (e.getLabel().equals("link") && e.getVertex(Direction.IN).equals(vportDst)) { |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 169 | graph.removeEdge(e); |
| 170 | count++; |
| 171 | } |
Pankaj Berde | 2239f0d | 2013-04-04 09:42:43 -0700 | [diff] [blame] | 172 | }*/ |
| 173 | vportSrc.removeLink(vportDst); |
Toshio Koide | 7bdea5b | 2013-06-13 13:57:18 -0700 | [diff] [blame] | 174 | dbop.commit(); |
Pankaj Berde | 2239f0d | 2013-04-04 09:42:43 -0700 | [diff] [blame] | 175 | log.debug("deleteLink(): deleted edges src {} dst {}", new Object[]{ |
| 176 | lt, vportSrc, vportDst}); |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 177 | |
| 178 | } else { |
Umesh Krishnaswamy | 9306f95 | 2013-01-24 20:42:59 -0800 | [diff] [blame] | 179 | log.error("deleteLink(): failed invalid vertices {} src {} dst {}", new Object[]{lt, vportSrc, vportDst}); |
Toshio Koide | 7bdea5b | 2013-06-13 13:57:18 -0700 | [diff] [blame] | 180 | dbop.rollback(); |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | } catch (TitanException e) { |
| 184 | /* |
| 185 | * retry till we succeed? |
| 186 | */ |
Umesh Krishnaswamy | c56a8cc | 2013-01-24 21:47:51 -0800 | [diff] [blame] | 187 | log.error("deleteLink(): titan exception {} {}", new Object[]{lt, e.toString()}); |
Toshio Koide | 7bdea5b | 2013-06-13 13:57:18 -0700 | [diff] [blame] | 188 | dbop.rollback(); |
Umesh Krishnaswamy | c56a8cc | 2013-01-24 21:47:51 -0800 | [diff] [blame] | 189 | e.printStackTrace(); |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 190 | } |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 191 | } |
| 192 | |
Naoki Shiota | 1151671 | 2013-06-05 22:36:01 -0700 | [diff] [blame] | 193 | /** |
| 194 | * Get list of all links connected to the port specified by given DPID and port number. |
| 195 | * @param dpid DPID of desired port. |
| 196 | * @param port Port number of desired port. |
| 197 | * @return List of links. Empty list if no port was found. |
| 198 | */ |
Naoki Shiota | b0d0c00 | 2013-06-05 20:21:20 -0700 | [diff] [blame] | 199 | // TODO: Fix me |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 200 | @Override |
| 201 | public List<Link> getLinks(Long dpid, short port) { |
Naoki Shiota | 93ec171 | 2013-06-13 15:49:36 -0700 | [diff] [blame] | 202 | List<Link> links = new ArrayList<Link>(); |
| 203 | |
| 204 | IPortObject srcPort = dbop.searchPort(HexString.toHexString(dpid), port); |
| 205 | ISwitchObject srcSw = srcPort.getSwitch(); |
| 206 | |
| 207 | if(srcSw != null) { |
| 208 | for(IPortObject dstPort : srcPort.getLinkedPorts()) { |
| 209 | ISwitchObject dstSw = dstPort.getSwitch(); |
| 210 | Link link = new Link(HexString.toLong(srcSw.getDPID()), |
| 211 | srcPort.getNumber(), |
| 212 | HexString.toLong(dstSw.getDPID()), |
| 213 | dstPort.getNumber()); |
| 214 | |
| 215 | links.add(link); |
| 216 | } |
| 217 | } |
| 218 | |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 219 | return links; |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 220 | } |
| 221 | |
Naoki Shiota | 1151671 | 2013-06-05 22:36:01 -0700 | [diff] [blame] | 222 | /** |
| 223 | * Initialize the object. Open LinkStorage using given configuration file. |
| 224 | * @param conf Path (absolute path for now) to configuration file. |
| 225 | */ |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 226 | @Override |
| 227 | public void init(String conf) { |
Pankaj Berde | 1f10be0 | 2013-02-01 14:06:02 -0800 | [diff] [blame] | 228 | //TODO extract the DB location from properties |
Toshio Koide | bfe9b92 | 2013-06-18 10:56:05 -0700 | [diff] [blame] | 229 | this.dbop = new GraphDBOperation(conf); |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 230 | } |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 231 | |
Naoki Shiota | 1151671 | 2013-06-05 22:36:01 -0700 | [diff] [blame] | 232 | /** |
| 233 | * Delete records of the links connected to the port specified by given DPID and port number. |
| 234 | * @param dpid DPID of desired port. |
| 235 | * @param port Port number of desired port. |
| 236 | */ |
Naoki Shiota | b0d0c00 | 2013-06-05 20:21:20 -0700 | [diff] [blame] | 237 | // TODO: Fix me |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 238 | @Override |
| 239 | public void deleteLinksOnPort(Long dpid, short port) { |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 240 | List<Link> linksToDelete = getLinks(dpid,port); |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 241 | |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 242 | for(Link l : linksToDelete) { |
| 243 | deleteLink(l); |
| 244 | } |
Umesh Krishnaswamy | f962d64 | 2013-01-23 19:04:23 -0800 | [diff] [blame] | 245 | } |
| 246 | |
Naoki Shiota | 1151671 | 2013-06-05 22:36:01 -0700 | [diff] [blame] | 247 | /** |
| 248 | * Get list of all links connected to the switch specified by given DPID. |
| 249 | * @param dpid DPID of desired switch. |
| 250 | * @return List of links. Empty list if no port was found. |
| 251 | */ |
Naoki Shiota | 1b97286 | 2013-06-05 19:49:09 -0700 | [diff] [blame] | 252 | // TODO: Fix me |
Pankaj Berde | ff42180 | 2013-01-29 20:28:52 -0800 | [diff] [blame] | 253 | @Override |
| 254 | public List<Link> getLinks(String dpid) { |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 255 | List<Link> links = new ArrayList<Link>(); |
| 256 | |
Naoki Shiota | 93ec171 | 2013-06-13 15:49:36 -0700 | [diff] [blame] | 257 | ISwitchObject srcSw = dbop.searchSwitch(dpid); |
| 258 | |
| 259 | if(srcSw != null) { |
| 260 | for(IPortObject srcPort : srcSw.getPorts()) { |
| 261 | for(IPortObject dstPort : srcPort.getLinkedPorts()) { |
| 262 | ISwitchObject dstSw = dstPort.getSwitch(); |
| 263 | if(dstSw != null) { |
| 264 | Link link = new Link(HexString.toLong(srcSw.getDPID()), |
| 265 | srcPort.getNumber(), |
| 266 | HexString.toLong(dstSw.getDPID()), |
| 267 | dstPort.getNumber()); |
| 268 | links.add(link); |
| 269 | } |
| 270 | } |
| 271 | } |
| 272 | } |
| 273 | |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 274 | return links; |
Pankaj Berde | ff42180 | 2013-01-29 20:28:52 -0800 | [diff] [blame] | 275 | } |
| 276 | |
Naoki Shiota | 1151671 | 2013-06-05 22:36:01 -0700 | [diff] [blame] | 277 | /** |
| 278 | * Get list of all links whose state is ACTIVE. |
| 279 | * @return List of active links. Empty list if no port was found. |
| 280 | */ |
Pankaj Berde | ff42180 | 2013-01-29 20:28:52 -0800 | [diff] [blame] | 281 | public List<Link> getActiveLinks() { |
Toshio Koide | 7bdea5b | 2013-06-13 13:57:18 -0700 | [diff] [blame] | 282 | Iterable<ISwitchObject> switches = dbop.getActiveSwitches(); |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 283 | |
| 284 | List<Link> links = new ArrayList<Link>(); |
Naoki Shiota | 826e84a | 2013-06-18 13:13:25 -0700 | [diff] [blame] | 285 | |
| 286 | for (ISwitchObject srcSw : switches) { |
| 287 | for(IPortObject srcPort : srcSw.getPorts()) { |
| 288 | for(IPortObject dstPort : srcPort.getLinkedPorts()) { |
| 289 | ISwitchObject dstSw = dstPort.getSwitch(); |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 290 | |
Naoki Shiota | 826e84a | 2013-06-18 13:13:25 -0700 | [diff] [blame] | 291 | if(dstSw != null && dstSw.getState().equals("ACTIVE")) { |
| 292 | links.add(new Link(HexString.toLong(srcSw.getDPID()), |
| 293 | srcPort.getNumber(), |
| 294 | HexString.toLong(dstSw.getDPID()), |
| 295 | dstPort.getNumber())); |
| 296 | } |
| 297 | } |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 298 | } |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 299 | } |
Naoki Shiota | 826e84a | 2013-06-18 13:13:25 -0700 | [diff] [blame] | 300 | |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 301 | return links; |
Pankaj Berde | ff42180 | 2013-01-29 20:28:52 -0800 | [diff] [blame] | 302 | } |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 303 | |
HIGUCHI Yuta | f05c480 | 2013-06-17 11:15:50 -0700 | [diff] [blame] | 304 | static class ExtractLink implements PipeFunction<PathPipe<Vertex>, Link> { |
Naoki Shiota | c57efb8 | 2013-06-18 13:40:28 -0700 | [diff] [blame] | 305 | |
| 306 | @Override |
| 307 | public Link compute(PathPipe<Vertex> pipe ) { |
| 308 | // TODO Auto-generated method stub |
| 309 | long s_dpid = 0; |
| 310 | long d_dpid = 0; |
| 311 | short s_port = 0; |
| 312 | short d_port = 0; |
| 313 | List<Vertex> V = new ArrayList<Vertex>(); |
| 314 | V = pipe.next(); |
| 315 | Vertex src_sw = V.get(0); |
| 316 | Vertex dest_sw = V.get(3); |
| 317 | Vertex src_port = V.get(1); |
| 318 | Vertex dest_port = V.get(2); |
| 319 | s_dpid = HexString.toLong((String) src_sw.getProperty("dpid")); |
| 320 | d_dpid = HexString.toLong((String) dest_sw.getProperty("dpid")); |
| 321 | s_port = (Short) src_port.getProperty("number"); |
| 322 | d_port = (Short) dest_port.getProperty("number"); |
| 323 | |
| 324 | Link l = new Link(s_dpid,s_port,d_dpid,d_port); |
| 325 | |
| 326 | return l; |
| 327 | } |
| 328 | } |
| 329 | |
Naoki Shiota | 1151671 | 2013-06-05 22:36:01 -0700 | [diff] [blame] | 330 | /** |
| 331 | * Finalize the object. |
| 332 | */ |
Pankaj Berde | d18c762 | 2013-02-04 10:28:35 -0800 | [diff] [blame] | 333 | public void finalize() { |
| 334 | close(); |
| 335 | } |
| 336 | |
Naoki Shiota | 1151671 | 2013-06-05 22:36:01 -0700 | [diff] [blame] | 337 | /** |
| 338 | * Close LinkStorage. |
| 339 | */ |
Pankaj Berde | d18c762 | 2013-02-04 10:28:35 -0800 | [diff] [blame] | 340 | @Override |
| 341 | public void close() { |
| 342 | // TODO Auto-generated method stub |
Pankaj Berde | 6201614 | 2013-04-09 15:35:50 -0700 | [diff] [blame] | 343 | // graph.shutdown(); |
Pankaj Berde | d18c762 | 2013-02-04 10:28:35 -0800 | [diff] [blame] | 344 | } |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 345 | |
Pankaj Berde | ff42180 | 2013-01-29 20:28:52 -0800 | [diff] [blame] | 346 | |
Umesh Krishnaswamy | b676ca2 | 2013-01-11 12:39:25 -0800 | [diff] [blame] | 347 | } |