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; |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 10 | |
Naoki Shiota | 991093a | 2013-12-10 14:47:18 -0800 | [diff] [blame] | 11 | import org.openflow.util.HexString; |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 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; |
Naoki Shiota | 991093a | 2013-12-10 14:47:18 -0800 | [diff] [blame] | 18 | import com.tinkerpop.pipes.PipeFunction; |
| 19 | import com.tinkerpop.pipes.transform.PathPipe; |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 20 | |
| 21 | public class TopoLinkServiceImpl implements ITopoLinkService { |
| 22 | |
yoshi | 2db7ff4 | 2013-11-25 19:30:25 -0800 | [diff] [blame] | 23 | protected DBOperation dbop; |
Yuta HIGUCHI | 6ac8d18 | 2013-10-22 15:24:56 -0700 | [diff] [blame] | 24 | protected final static Logger log = LoggerFactory.getLogger(TopoLinkServiceImpl.class); |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 25 | |
Yuta HIGUCHI | 67a7a3e | 2014-01-03 14:51:34 -0800 | [diff] [blame] | 26 | @Override |
| 27 | protected void finalize() { |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 28 | close(); |
| 29 | } |
Yuta HIGUCHI | 67a7a3e | 2014-01-03 14:51:34 -0800 | [diff] [blame] | 30 | |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 31 | @Override |
| 32 | public void close() { |
yoshi | 2db7ff4 | 2013-11-25 19:30:25 -0800 | [diff] [blame] | 33 | dbop.close(); |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 34 | } |
Yuta HIGUCHI | 67a7a3e | 2014-01-03 14:51:34 -0800 | [diff] [blame] | 35 | |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 36 | @Override |
Pankaj Berde | 1cde50b | 2013-02-19 20:16:06 -0800 | [diff] [blame] | 37 | public List<Link> getActiveLinks() { |
yoshi | e929d0d | 2014-01-13 13:15:07 -0800 | [diff] [blame^] | 38 | <<<<<<< HEAD |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 39 | // TODO Auto-generated method stub |
yoshi | d38cd31 | 2013-12-02 19:54:44 -0800 | [diff] [blame] | 40 | dbop = GraphDBManager.getDBOperation("ramcloud", "/tmp/ramcloudconf"); |
| 41 | //dbop = GraphDBManager.getDBOperation("", ""); |
yoshi | 9535fc8 | 2013-12-05 11:34:52 -0800 | [diff] [blame] | 42 | //dbop.commit(); //Commit to ensure we see latest data |
yoshi | 2db7ff4 | 2013-11-25 19:30:25 -0800 | [diff] [blame] | 43 | Iterable<ISwitchObject> switches = dbop.getActiveSwitches(); |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 44 | List<Link> links = new ArrayList<Link>(); |
yoshi | e929d0d | 2014-01-13 13:15:07 -0800 | [diff] [blame^] | 45 | ======= |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 46 | op = new GraphDBOperation(""); |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 47 | op.commit(); //Commit to ensure we see latest data |
| 48 | Iterable<ISwitchObject> switches = op.getActiveSwitches(); |
Yuta HIGUCHI | 67a7a3e | 2014-01-03 14:51:34 -0800 | [diff] [blame] | 49 | List<Link> links = new ArrayList<Link>(); |
yoshi | e929d0d | 2014-01-13 13:15:07 -0800 | [diff] [blame^] | 50 | >>>>>>> df6f52e87c8beeec9a50e4050634d70f124e9bc3 |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 51 | for (ISwitchObject sw : switches) { |
| 52 | GremlinPipeline<Vertex, Link> pipe = new GremlinPipeline<Vertex, Link>(); |
| 53 | ExtractLink extractor = new ExtractLink(); |
| 54 | |
| 55 | pipe.start(sw.asVertex()); |
| 56 | pipe.enablePath(true); |
| 57 | pipe.out("on").out("link").in("on").path().step(extractor); |
Yuta HIGUCHI | 67a7a3e | 2014-01-03 14:51:34 -0800 | [diff] [blame] | 58 | |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 59 | while (pipe.hasNext() ) { |
| 60 | Link l = pipe.next(); |
| 61 | links.add(l); |
| 62 | } |
Yuta HIGUCHI | 67a7a3e | 2014-01-03 14:51:34 -0800 | [diff] [blame] | 63 | |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 64 | } |
yoshi | 2db7ff4 | 2013-11-25 19:30:25 -0800 | [diff] [blame] | 65 | dbop.commit(); |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 66 | return links; |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | @Override |
Pankaj Berde | 1cde50b | 2013-02-19 20:16:06 -0800 | [diff] [blame] | 70 | public List<Link> getLinksOnSwitch(String dpid) { |
yoshi | e929d0d | 2014-01-13 13:15:07 -0800 | [diff] [blame^] | 71 | <<<<<<< HEAD |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 72 | List<Link> links = new ArrayList<Link>(); |
yoshi | 2db7ff4 | 2013-11-25 19:30:25 -0800 | [diff] [blame] | 73 | ISwitchObject sw = dbop.searchSwitch(dpid); |
yoshi | e929d0d | 2014-01-13 13:15:07 -0800 | [diff] [blame^] | 74 | ======= |
Yuta HIGUCHI | 67a7a3e | 2014-01-03 14:51:34 -0800 | [diff] [blame] | 75 | List<Link> links = new ArrayList<Link>(); |
Toshio Koide | 22f192c | 2013-06-13 14:01:45 -0700 | [diff] [blame] | 76 | ISwitchObject sw = op.searchSwitch(dpid); |
yoshi | e929d0d | 2014-01-13 13:15:07 -0800 | [diff] [blame^] | 77 | >>>>>>> df6f52e87c8beeec9a50e4050634d70f124e9bc3 |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 78 | GremlinPipeline<Vertex, Link> pipe = new GremlinPipeline<Vertex, Link>(); |
| 79 | ExtractLink extractor = new ExtractLink(); |
| 80 | |
| 81 | pipe.start(sw.asVertex()); |
| 82 | pipe.enablePath(true); |
| 83 | pipe.out("on").out("link").in("on").path().step(extractor); |
Yuta HIGUCHI | 67a7a3e | 2014-01-03 14:51:34 -0800 | [diff] [blame] | 84 | |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 85 | while (pipe.hasNext() ) { |
| 86 | Link l = pipe.next(); |
| 87 | links.add(l); |
| 88 | } |
| 89 | return links; |
| 90 | |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 91 | } |
Naoki Shiota | 991093a | 2013-12-10 14:47:18 -0800 | [diff] [blame] | 92 | |
| 93 | private class ExtractLink implements PipeFunction<PathPipe<Vertex>, Link> { |
| 94 | @Override |
| 95 | public Link compute(PathPipe<Vertex> pipe) { |
| 96 | long s_dpid = 0; |
| 97 | long d_dpid = 0; |
| 98 | short s_port = 0; |
| 99 | short d_port = 0; |
Yuta HIGUCHI | 67a7a3e | 2014-01-03 14:51:34 -0800 | [diff] [blame] | 100 | |
Naoki Shiota | de5d842 | 2013-12-11 13:56:57 -0800 | [diff] [blame] | 101 | List<?> V = pipe.next(); |
| 102 | Vertex src_sw = (Vertex)V.get(0); |
| 103 | Vertex dest_sw = (Vertex)V.get(3); |
| 104 | Vertex src_port = (Vertex)V.get(1); |
| 105 | Vertex dest_port = (Vertex)V.get(2); |
Naoki Shiota | 991093a | 2013-12-10 14:47:18 -0800 | [diff] [blame] | 106 | s_dpid = HexString.toLong((String) src_sw.getProperty("dpid")); |
| 107 | d_dpid = HexString.toLong((String) dest_sw.getProperty("dpid")); |
| 108 | s_port = (Short) src_port.getProperty("number"); |
| 109 | d_port = (Short) dest_port.getProperty("number"); |
Yuta HIGUCHI | 67a7a3e | 2014-01-03 14:51:34 -0800 | [diff] [blame] | 110 | |
Naoki Shiota | 991093a | 2013-12-10 14:47:18 -0800 | [diff] [blame] | 111 | Link l = new Link(s_dpid,s_port,d_dpid,d_port); |
Yuta HIGUCHI | 67a7a3e | 2014-01-03 14:51:34 -0800 | [diff] [blame] | 112 | |
Naoki Shiota | 991093a | 2013-12-10 14:47:18 -0800 | [diff] [blame] | 113 | return l; |
| 114 | } |
| 115 | } |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 116 | } |