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