HIGUCHI Yuta | f05c480 | 2013-06-17 11:15:50 -0700 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.core.internal; |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 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 | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 6 | import net.floodlightcontroller.routing.Link; |
yoshi | 2db7ff4 | 2013-11-25 19:30:25 -0800 | [diff] [blame] | 7 | import net.onrc.onos.graph.DBOperation; |
HIGUCHI Yuta | 2051490 | 2013-06-12 11:24:16 -0700 | [diff] [blame] | 8 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject; |
| 9 | import net.onrc.onos.ofcontroller.core.INetMapTopologyService.ITopoLinkService; |
HIGUCHI Yuta | 2d01158 | 2013-06-15 01:47:11 -0700 | [diff] [blame] | 10 | import net.onrc.onos.ofcontroller.core.internal.LinkStorageImpl.ExtractLink; |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 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; |
yoshi | 2db7ff4 | 2013-11-25 19:30:25 -0800 | [diff] [blame] | 17 | import net.onrc.onos.graph.GraphDBManager; |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 18 | |
| 19 | public class TopoLinkServiceImpl implements ITopoLinkService { |
| 20 | |
yoshi | 2db7ff4 | 2013-11-25 19:30:25 -0800 | [diff] [blame] | 21 | protected DBOperation dbop; |
Yuta HIGUCHI | 6ac8d18 | 2013-10-22 15:24:56 -0700 | [diff] [blame] | 22 | protected final static Logger log = LoggerFactory.getLogger(TopoLinkServiceImpl.class); |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 23 | |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 24 | public void finalize() { |
| 25 | close(); |
| 26 | } |
| 27 | |
| 28 | @Override |
| 29 | public void close() { |
yoshi | 2db7ff4 | 2013-11-25 19:30:25 -0800 | [diff] [blame] | 30 | dbop.close(); |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 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 |
yoshi | d38cd31 | 2013-12-02 19:54:44 -0800 | [diff] [blame] | 36 | dbop = GraphDBManager.getDBOperation("ramcloud", "/tmp/ramcloudconf"); |
| 37 | //dbop = GraphDBManager.getDBOperation("", ""); |
yoshi | 9535fc8 | 2013-12-05 11:34:52 -0800 | [diff] [blame^] | 38 | //dbop.commit(); //Commit to ensure we see latest data |
yoshi | 2db7ff4 | 2013-11-25 19:30:25 -0800 | [diff] [blame] | 39 | Iterable<ISwitchObject> switches = dbop.getActiveSwitches(); |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 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 | } |
yoshi | 2db7ff4 | 2013-11-25 19:30:25 -0800 | [diff] [blame] | 55 | dbop.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>(); |
yoshi | 2db7ff4 | 2013-11-25 19:30:25 -0800 | [diff] [blame] | 63 | ISwitchObject sw = dbop.searchSwitch(dpid); |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 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 | } |