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(""); |
| 37 | Iterable<ISwitchObject> switches = conn.utils().getActiveSwitches(conn); |
| 38 | List<Link> links = new ArrayList<Link>(); |
| 39 | for (ISwitchObject sw : switches) { |
| 40 | GremlinPipeline<Vertex, Link> pipe = new GremlinPipeline<Vertex, Link>(); |
| 41 | ExtractLink extractor = new ExtractLink(); |
| 42 | |
| 43 | pipe.start(sw.asVertex()); |
| 44 | pipe.enablePath(true); |
| 45 | pipe.out("on").out("link").in("on").path().step(extractor); |
| 46 | |
| 47 | while (pipe.hasNext() ) { |
| 48 | Link l = pipe.next(); |
| 49 | links.add(l); |
| 50 | } |
| 51 | |
| 52 | } |
| 53 | return links; |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | @Override |
Pankaj Berde | 1cde50b | 2013-02-19 20:16:06 -0800 | [diff] [blame] | 57 | public List<Link> getLinksOnSwitch(String dpid) { |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 58 | // TODO Auto-generated method stub |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 59 | List<Link> links = new ArrayList<Link>(); |
| 60 | ISwitchObject sw = conn.utils().searchSwitch(conn, dpid); |
| 61 | GremlinPipeline<Vertex, Link> pipe = new GremlinPipeline<Vertex, Link>(); |
| 62 | ExtractLink extractor = new ExtractLink(); |
| 63 | |
| 64 | pipe.start(sw.asVertex()); |
| 65 | pipe.enablePath(true); |
| 66 | pipe.out("on").out("link").in("on").path().step(extractor); |
| 67 | |
| 68 | while (pipe.hasNext() ) { |
| 69 | Link l = pipe.next(); |
| 70 | links.add(l); |
| 71 | } |
| 72 | return links; |
| 73 | |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 74 | } |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 75 | |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 76 | } |