HIGUCHI Yuta | 8388949 | 2013-06-12 13:20:48 -0700 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.linkdiscovery.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 | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 6 | import net.floodlightcontroller.linkdiscovery.internal.LinkStorageImpl.ExtractLink; |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 7 | import net.floodlightcontroller.routing.Link; |
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; |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 10 | import net.onrc.onos.util.GraphDBConnection; |
Toshio Koide | 22f192c | 2013-06-13 14:01:45 -0700 | [diff] [blame] | 11 | import net.onrc.onos.util.GraphDBOperation; |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 12 | |
| 13 | import org.slf4j.Logger; |
| 14 | import org.slf4j.LoggerFactory; |
| 15 | |
| 16 | import com.tinkerpop.blueprints.Vertex; |
| 17 | import com.tinkerpop.gremlin.java.GremlinPipeline; |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 18 | |
| 19 | public class TopoLinkServiceImpl implements ITopoLinkService { |
| 20 | |
Toshio Koide | 22f192c | 2013-06-13 14:01:45 -0700 | [diff] [blame] | 21 | protected GraphDBOperation op; |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 22 | protected static Logger log = LoggerFactory.getLogger(TopoLinkServiceImpl.class); |
| 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() { |
Toshio Koide | 22f192c | 2013-06-13 14:01:45 -0700 | [diff] [blame] | 30 | op.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 |
Toshio Koide | 22f192c | 2013-06-13 14:01:45 -0700 | [diff] [blame] | 36 | op = new GraphDBOperation(GraphDBConnection.getInstance("")); |
| 37 | op.close(); //Commit to ensure we see latest data |
| 38 | Iterable<ISwitchObject> switches = op.getActiveSwitches(); |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 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 | } |
Toshio Koide | 22f192c | 2013-06-13 14:01:45 -0700 | [diff] [blame] | 54 | op.commit(); |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 55 | return links; |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | @Override |
Pankaj Berde | 1cde50b | 2013-02-19 20:16:06 -0800 | [diff] [blame] | 59 | public List<Link> getLinksOnSwitch(String dpid) { |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 60 | // TODO Auto-generated method stub |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 61 | List<Link> links = new ArrayList<Link>(); |
Toshio Koide | 22f192c | 2013-06-13 14:01:45 -0700 | [diff] [blame] | 62 | ISwitchObject sw = op.searchSwitch(dpid); |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 63 | GremlinPipeline<Vertex, Link> pipe = new GremlinPipeline<Vertex, Link>(); |
| 64 | ExtractLink extractor = new ExtractLink(); |
| 65 | |
| 66 | pipe.start(sw.asVertex()); |
| 67 | pipe.enablePath(true); |
| 68 | pipe.out("on").out("link").in("on").path().step(extractor); |
| 69 | |
| 70 | while (pipe.hasNext() ) { |
| 71 | Link l = pipe.next(); |
| 72 | links.add(l); |
| 73 | } |
| 74 | return links; |
| 75 | |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 76 | } |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 77 | |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 78 | } |