Pankaj Berde | 85016ab | 2013-06-21 11:34:53 -0700 | [diff] [blame] | 1 | package net.onrc.onos.graph; |
| 2 | |
Pankaj Berde | 85016ab | 2013-06-21 11:34:53 -0700 | [diff] [blame] | 3 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IPortObject; |
| 4 | |
| 5 | import org.slf4j.Logger; |
| 6 | import org.slf4j.LoggerFactory; |
| 7 | |
| 8 | import com.thinkaurelius.titan.core.TitanEdge; |
| 9 | import com.tinkerpop.blueprints.Direction; |
| 10 | import com.tinkerpop.blueprints.Edge; |
| 11 | import com.tinkerpop.blueprints.Vertex; |
| 12 | |
| 13 | public class LocalTopologyEventListener implements LocalGraphChangedListener { |
| 14 | |
Yuta HIGUCHI | 6ac8d18 | 2013-10-22 15:24:56 -0700 | [diff] [blame] | 15 | protected final static Logger log = LoggerFactory.getLogger(LocalTopologyEventListener.class); |
Pankaj Berde | 85016ab | 2013-06-21 11:34:53 -0700 | [diff] [blame] | 16 | protected static GraphDBConnection conn; |
| 17 | |
| 18 | public LocalTopologyEventListener(GraphDBConnection conn) { |
| 19 | LocalTopologyEventListener.conn = conn; |
| 20 | } |
| 21 | |
| 22 | @Override |
| 23 | public void edgeAdded(Edge arg0) { |
| 24 | // TODO Auto-generated method stub |
| 25 | // Convert this Event into NetMapEvent (LinkAdded, FlowEntryEnabled, HostAttached, PortEnabled) |
| 26 | } |
| 27 | |
| 28 | |
| 29 | @Override |
| 30 | public void edgePropertyRemoved(Edge arg0, String arg1, Object arg2) { |
| 31 | // TODO Auto-generated method stub |
| 32 | // Currently not needed |
| 33 | |
| 34 | } |
| 35 | |
| 36 | @Override |
| 37 | public void edgeRemoved(Edge e) { |
| 38 | // TODO Auto-generated method stub |
| 39 | // Fire NetMapEvents (LinkRemoved, FlowEntryRemoved, HostRemoved, PortRemoved) |
| 40 | TitanEdge edge = (TitanEdge) e; |
| 41 | log.debug("TopologyEvents: Received edge removed event: {}",edge.toString()); |
| 42 | String label = edge.getLabel(); |
| 43 | if (label.equals("link")) { |
| 44 | Vertex v = edge.getVertex(Direction.IN); |
| 45 | IPortObject src_port = conn.getFramedGraph().frame(v, IPortObject.class); |
| 46 | v = edge.getVertex(Direction.OUT); |
| 47 | IPortObject dest_port = conn.getFramedGraph().frame(v, IPortObject.class); |
| 48 | |
| 49 | log.debug("TopologyEvents: link broken {}", new Object []{src_port.getSwitch().getDPID(), |
| 50 | src_port.getNumber(), |
| 51 | dest_port.getSwitch().getDPID(), |
| 52 | dest_port.getNumber()}); |
Pankaj Berde | 85016ab | 2013-06-21 11:34:53 -0700 | [diff] [blame] | 53 | // TODO: Find the flows and add to reconcile queue |
Pavlin Radoslavov | fcf4222 | 2013-12-02 16:57:24 -0800 | [diff] [blame] | 54 | // |
| 55 | // NOTE: Old code/logic. |
| 56 | // |
| 57 | // IFlowService flowManager = ... |
| 58 | // flowManager.reconcileFlows(src_port); |
Pankaj Berde | 85016ab | 2013-06-21 11:34:53 -0700 | [diff] [blame] | 59 | } |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public void vertexAdded(Vertex arg0) { |
| 64 | // TODO Auto-generated method stub |
| 65 | |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public void vertexPropertyRemoved(Vertex arg0, String arg1, Object arg2) { |
| 70 | // TODO Auto-generated method stub |
| 71 | |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public void vertexRemoved(Vertex vertex) { |
| 76 | // TODO Auto-generated method stub |
| 77 | // Generate NetMapEvents |
| 78 | String type = (String) vertex.getProperty("type"); |
| 79 | log.debug("TopologyEvents: Received vertex removed event: {}",vertex.toString()); |
| 80 | if (type.equals("port")) { |
| 81 | // port is removed...lets fire reconcile here directly for now |
| 82 | |
| 83 | IPortObject src_port = conn.getFramedGraph().frame(vertex, IPortObject.class); |
| 84 | log.debug("TopologyEvents: Port removed: {}:{}",src_port.getSwitch().getDPID(),src_port.getNumber()); |
Pavlin Radoslavov | fcf4222 | 2013-12-02 16:57:24 -0800 | [diff] [blame] | 85 | |
| 86 | // NOTE: Old code/logic. |
| 87 | // |
| 88 | // IFlowService flowManager = ... |
| 89 | // flowManager.reconcileFlows(src_port); |
Pankaj Berde | 85016ab | 2013-06-21 11:34:53 -0700 | [diff] [blame] | 90 | } |
| 91 | } |
| 92 | |
| 93 | |
| 94 | @Override |
| 95 | public void edgePropertyChanged(Edge arg0, String arg1, Object arg2, |
| 96 | Object arg3) { |
| 97 | // TODO Auto-generated method stub |
| 98 | |
| 99 | } |
| 100 | |
| 101 | @Override |
| 102 | public void vertexPropertyChanged(Vertex arg0, String arg1, Object arg2, |
| 103 | Object arg3) { |
| 104 | // TODO Auto-generated method stub |
| 105 | |
| 106 | } |
| 107 | |
| 108 | } |