blob: c49388731faeca542da778a69c48c7d719e87344 [file] [log] [blame]
Pankaj Berde5024ec12013-01-31 17:07:29 -08001package net.floodlightcontroller.linkdiscovery.internal;
2
Pankaj Berde15193092013-03-21 17:30:14 -07003import java.util.ArrayList;
Pankaj Berde5024ec12013-01-31 17:07:29 -08004import java.util.List;
5
Pankaj Berde15193092013-03-21 17:30:14 -07006import net.floodlightcontroller.core.INetMapTopologyObjects.ISwitchObject;
Pankaj Berde5024ec12013-01-31 17:07:29 -08007import net.floodlightcontroller.core.INetMapTopologyService.ITopoLinkService;
Pankaj Berde15193092013-03-21 17:30:14 -07008import net.floodlightcontroller.linkdiscovery.internal.LinkStorageImpl.ExtractLink;
Pankaj Berde5024ec12013-01-31 17:07:29 -08009import net.floodlightcontroller.routing.Link;
Pankaj Berde15193092013-03-21 17:30:14 -070010import net.onrc.onos.util.GraphDBConnection;
11
12import org.slf4j.Logger;
13import org.slf4j.LoggerFactory;
14
15import com.tinkerpop.blueprints.Vertex;
16import com.tinkerpop.gremlin.java.GremlinPipeline;
Pankaj Berde5024ec12013-01-31 17:07:29 -080017
18public class TopoLinkServiceImpl implements ITopoLinkService {
19
Pankaj Berde15193092013-03-21 17:30:14 -070020 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 Berde5024ec12013-01-31 17:07:29 -080032
Pankaj Berde5024ec12013-01-31 17:07:29 -080033 @Override
Pankaj Berde1cde50b2013-02-19 20:16:06 -080034 public List<Link> getActiveLinks() {
Pankaj Berde5024ec12013-01-31 17:07:29 -080035 // TODO Auto-generated method stub
Pankaj Berde15193092013-03-21 17:30:14 -070036 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 Berde5024ec12013-01-31 17:07:29 -080054 }
55
56 @Override
Pankaj Berde1cde50b2013-02-19 20:16:06 -080057 public List<Link> getLinksOnSwitch(String dpid) {
Pankaj Berde5024ec12013-01-31 17:07:29 -080058 // TODO Auto-generated method stub
Pankaj Berde15193092013-03-21 17:30:14 -070059 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 Berde5024ec12013-01-31 17:07:29 -080074 }
Pankaj Berde15193092013-03-21 17:30:14 -070075
Pankaj Berde5024ec12013-01-31 17:07:29 -080076}