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