blob: 9d5fdba48a4017c11fd0c37a53465d41aacdfb5a [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;
Pankaj Berdeae5ebd22013-06-10 21:23:07 -070011import net.onrc.onos.util.GraphDBConnection.Transaction;
Pankaj Berde15193092013-03-21 17:30:14 -070012
13import org.slf4j.Logger;
14import org.slf4j.LoggerFactory;
15
16import com.tinkerpop.blueprints.Vertex;
17import com.tinkerpop.gremlin.java.GremlinPipeline;
Pankaj Berde5024ec12013-01-31 17:07:29 -080018
19public class TopoLinkServiceImpl implements ITopoLinkService {
20
Pankaj Berde15193092013-03-21 17:30:14 -070021 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 Berde5024ec12013-01-31 17:07:29 -080033
Pankaj Berde5024ec12013-01-31 17:07:29 -080034 @Override
Pankaj Berde1cde50b2013-02-19 20:16:06 -080035 public List<Link> getActiveLinks() {
Pankaj Berde5024ec12013-01-31 17:07:29 -080036 // TODO Auto-generated method stub
Pankaj Berde15193092013-03-21 17:30:14 -070037 conn = GraphDBConnection.getInstance("");
Jonathan Harte6e91872013-04-13 11:10:32 -070038 conn.close(); //Commit to ensure we see latest data
Pankaj Berde15193092013-03-21 17:30:14 -070039 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 Berdeae5ebd22013-06-10 21:23:07 -070055 conn.endTx(Transaction.COMMIT);
Pankaj Berde15193092013-03-21 17:30:14 -070056 return links;
Pankaj Berde5024ec12013-01-31 17:07:29 -080057 }
58
59 @Override
Pankaj Berde1cde50b2013-02-19 20:16:06 -080060 public List<Link> getLinksOnSwitch(String dpid) {
Pankaj Berde5024ec12013-01-31 17:07:29 -080061 // TODO Auto-generated method stub
Pankaj Berde15193092013-03-21 17:30:14 -070062 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 Berde5024ec12013-01-31 17:07:29 -080077 }
Pankaj Berde15193092013-03-21 17:30:14 -070078
Pankaj Berde5024ec12013-01-31 17:07:29 -080079}