Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 1 | package net.floodlightcontroller.linkdiscovery.internal; |
| 2 | |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 3 | import java.util.ArrayList; |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 4 | import java.util.List; |
| 5 | |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 6 | import net.floodlightcontroller.core.INetMapTopologyObjects.ISwitchObject; |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 7 | import net.floodlightcontroller.core.INetMapTopologyService.ITopoLinkService; |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 8 | import net.floodlightcontroller.linkdiscovery.internal.LinkStorageImpl.ExtractLink; |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 9 | import net.floodlightcontroller.routing.Link; |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 10 | import net.onrc.onos.util.GraphDBConnection; |
Pankaj Berde | ae5ebd2 | 2013-06-10 21:23:07 -0700 | [diff] [blame] | 11 | import net.onrc.onos.util.GraphDBConnection.Transaction; |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 12 | |
| 13 | import org.slf4j.Logger; |
| 14 | import org.slf4j.LoggerFactory; |
| 15 | |
| 16 | import com.tinkerpop.blueprints.Vertex; |
| 17 | import com.tinkerpop.gremlin.java.GremlinPipeline; |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 18 | |
| 19 | public class TopoLinkServiceImpl implements ITopoLinkService { |
| 20 | |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 21 | public GraphDBConnection conn; |
| 22 | protected static Logger log = LoggerFactory.getLogger(TopoLinkServiceImpl.class); |
| 23 | |
| 24 | |
| 25 | public void finalize() { |
| 26 | close(); |
| 27 | } |
| 28 | |
| 29 | @Override |
| 30 | public void close() { |
| 31 | conn.close(); |
| 32 | } |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 33 | |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 34 | @Override |
Pankaj Berde | 1cde50b | 2013-02-19 20:16:06 -0800 | [diff] [blame] | 35 | public List<Link> getActiveLinks() { |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 36 | // TODO Auto-generated method stub |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 37 | conn = GraphDBConnection.getInstance(""); |
Jonathan Hart | e6e9187 | 2013-04-13 11:10:32 -0700 | [diff] [blame] | 38 | conn.close(); //Commit to ensure we see latest data |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 39 | Iterable<ISwitchObject> switches = conn.utils().getActiveSwitches(conn); |
| 40 | List<Link> links = new ArrayList<Link>(); |
| 41 | for (ISwitchObject sw : switches) { |
| 42 | GremlinPipeline<Vertex, Link> pipe = new GremlinPipeline<Vertex, Link>(); |
| 43 | ExtractLink extractor = new ExtractLink(); |
| 44 | |
| 45 | pipe.start(sw.asVertex()); |
| 46 | pipe.enablePath(true); |
| 47 | pipe.out("on").out("link").in("on").path().step(extractor); |
| 48 | |
| 49 | while (pipe.hasNext() ) { |
| 50 | Link l = pipe.next(); |
| 51 | links.add(l); |
| 52 | } |
| 53 | |
| 54 | } |
Pankaj Berde | ae5ebd2 | 2013-06-10 21:23:07 -0700 | [diff] [blame] | 55 | conn.endTx(Transaction.COMMIT); |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 56 | return links; |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | @Override |
Pankaj Berde | 1cde50b | 2013-02-19 20:16:06 -0800 | [diff] [blame] | 60 | public List<Link> getLinksOnSwitch(String dpid) { |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 61 | // TODO Auto-generated method stub |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 62 | List<Link> links = new ArrayList<Link>(); |
| 63 | ISwitchObject sw = conn.utils().searchSwitch(conn, dpid); |
| 64 | GremlinPipeline<Vertex, Link> pipe = new GremlinPipeline<Vertex, Link>(); |
| 65 | ExtractLink extractor = new ExtractLink(); |
| 66 | |
| 67 | pipe.start(sw.asVertex()); |
| 68 | pipe.enablePath(true); |
| 69 | pipe.out("on").out("link").in("on").path().step(extractor); |
| 70 | |
| 71 | while (pipe.hasNext() ) { |
| 72 | Link l = pipe.next(); |
| 73 | links.add(l); |
| 74 | } |
| 75 | return links; |
| 76 | |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 77 | } |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 78 | |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 79 | } |