Jonathan Hart | 472062d | 2014-04-03 10:56:48 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.topology; |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 2 | |
Yuta HIGUCHI | fa74284 | 2014-07-03 22:35:13 -0700 | [diff] [blame] | 3 | import java.util.Collection; |
| 4 | |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 5 | import net.floodlightcontroller.util.MACAddress; |
Yuta HIGUCHI | a7f1cdd | 2014-06-09 15:05:20 -0700 | [diff] [blame] | 6 | import net.onrc.onos.core.topology.web.serializers.TopologySerializer; |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 7 | import net.onrc.onos.core.util.Dpid; |
| 8 | import net.onrc.onos.core.util.PortNumber; |
| 9 | import net.onrc.onos.core.util.SwitchPort; |
Yuta HIGUCHI | a7f1cdd | 2014-06-09 15:05:20 -0700 | [diff] [blame] | 10 | |
Ray Milkey | 0fe4385 | 2014-06-05 14:41:46 -0700 | [diff] [blame] | 11 | import org.codehaus.jackson.map.annotate.JsonSerialize; |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 12 | |
| 13 | /** |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 14 | * The northbound interface to the topology. This interface |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 15 | * is presented to the rest of ONOS. It is currently read-only, as we want |
| 16 | * only the discovery modules to be allowed to modify the topology. |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 17 | */ |
Ray Milkey | 0fe4385 | 2014-06-05 14:41:46 -0700 | [diff] [blame] | 18 | @JsonSerialize(using = TopologySerializer.class) |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 19 | public interface Topology { |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 20 | |
Pavlin Radoslavov | 06df22a | 2014-02-18 19:16:27 -0800 | [diff] [blame] | 21 | /** |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 22 | * Gets the switch for a given switch DPID. |
Pavlin Radoslavov | 06df22a | 2014-02-18 19:16:27 -0800 | [diff] [blame] | 23 | * |
| 24 | * @param dpid the switch dpid. |
Pavlin Radoslavov | 7c8f69a | 2014-02-19 19:01:45 -0800 | [diff] [blame] | 25 | * @return the switch if found, otherwise null. |
Pavlin Radoslavov | 06df22a | 2014-02-18 19:16:27 -0800 | [diff] [blame] | 26 | */ |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 27 | public Switch getSwitch(Dpid dpid); |
Yuta HIGUCHI | c6174df | 2014-02-10 20:44:38 -0800 | [diff] [blame] | 28 | |
Pavlin Radoslavov | 06df22a | 2014-02-18 19:16:27 -0800 | [diff] [blame] | 29 | /** |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 30 | * Gets all switches in the network. |
Pavlin Radoslavov | 06df22a | 2014-02-18 19:16:27 -0800 | [diff] [blame] | 31 | * |
| 32 | * @return all switches in the network. |
| 33 | */ |
| 34 | public Iterable<Switch> getSwitches(); |
Yuta HIGUCHI | c6174df | 2014-02-10 20:44:38 -0800 | [diff] [blame] | 35 | |
Pavlin Radoslavov | 06df22a | 2014-02-18 19:16:27 -0800 | [diff] [blame] | 36 | /** |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 37 | * Gets the port on a switch. |
Pavlin Radoslavov | 06df22a | 2014-02-18 19:16:27 -0800 | [diff] [blame] | 38 | * |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 39 | * @param dpid the switch DPID. |
Pavlin Radoslavov | 06df22a | 2014-02-18 19:16:27 -0800 | [diff] [blame] | 40 | * @param number the switch port number. |
Pavlin Radoslavov | 7c8f69a | 2014-02-19 19:01:45 -0800 | [diff] [blame] | 41 | * @return the switch port if found, otherwise null. |
Pavlin Radoslavov | 06df22a | 2014-02-18 19:16:27 -0800 | [diff] [blame] | 42 | */ |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 43 | public Port getPort(Dpid dpid, PortNumber number); |
Pavlin Radoslavov | 06df22a | 2014-02-18 19:16:27 -0800 | [diff] [blame] | 44 | |
| 45 | /** |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 46 | * Gets the port on a switch. |
| 47 | * |
| 48 | * @param port port identifier |
| 49 | * @return the switch port if found, otherwise null. |
| 50 | */ |
| 51 | public Port getPort(SwitchPort port); |
| 52 | |
| 53 | /** |
Yuta HIGUCHI | fa74284 | 2014-07-03 22:35:13 -0700 | [diff] [blame] | 54 | * Gets all ports on a switch specified. |
| 55 | * |
| 56 | * @param dpid Switch dpid |
| 57 | * @return ports. |
| 58 | */ |
| 59 | public Collection<Port> getPorts(Dpid dpid); |
| 60 | |
| 61 | /** |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 62 | * Gets the outgoing link from a switch port. |
Pavlin Radoslavov | 7c8f69a | 2014-02-19 19:01:45 -0800 | [diff] [blame] | 63 | * |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 64 | * @param dpid the switch DPID. |
Pavlin Radoslavov | 7c8f69a | 2014-02-19 19:01:45 -0800 | [diff] [blame] | 65 | * @param number the switch port number. |
| 66 | * @return the outgoing link if found, otherwise null. |
| 67 | */ |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 68 | public Link getOutgoingLink(Dpid dpid, PortNumber number); |
Jonathan Hart | 25bd53e | 2014-04-30 23:44:09 -0700 | [diff] [blame] | 69 | |
| 70 | /** |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 71 | * Gets the outgoing link from a switch port. |
| 72 | * |
| 73 | * @param port port identifier |
| 74 | * @return the switch port if found, otherwise null. |
| 75 | */ |
| 76 | public Link getOutgoingLink(SwitchPort port); |
| 77 | |
| 78 | /** |
| 79 | * Gets the incoming link to a switch port. |
Jonathan Hart | 25bd53e | 2014-04-30 23:44:09 -0700 | [diff] [blame] | 80 | * |
| 81 | * @param dpid the switch DPID. |
| 82 | * @param number the switch port number. |
| 83 | * @return the incoming link if found, otherwise null. |
| 84 | */ |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 85 | public Link getIncomingLink(Dpid dpid, PortNumber number); |
Pavlin Radoslavov | 7c8f69a | 2014-02-19 19:01:45 -0800 | [diff] [blame] | 86 | |
| 87 | /** |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 88 | * Gets the incoming link to a switch port. |
| 89 | * |
| 90 | * @param port port identifier |
| 91 | * @return the switch port if found, otherwise null. |
| 92 | */ |
| 93 | public Link getIncomingLink(SwitchPort port); |
| 94 | |
| 95 | /** |
| 96 | * Gets the outgoing link from a switch and a port to another switch and |
Pavlin Radoslavov | 7c8f69a | 2014-02-19 19:01:45 -0800 | [diff] [blame] | 97 | * a port. |
| 98 | * |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 99 | * @param srcDpid the source switch DPID. |
Pavlin Radoslavov | 7c8f69a | 2014-02-19 19:01:45 -0800 | [diff] [blame] | 100 | * @param srcNumber the source switch port number. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 101 | * @param dstDpid the destination switch DPID. |
Pavlin Radoslavov | 7c8f69a | 2014-02-19 19:01:45 -0800 | [diff] [blame] | 102 | * @param dstNumber the destination switch port number. |
| 103 | * @return the outgoing link if found, otherwise null. |
| 104 | */ |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 105 | public Link getLink(Dpid srcDpid, PortNumber srcNumber, |
| 106 | Dpid dstDpid, PortNumber dstNumber); |
Pavlin Radoslavov | 7c8f69a | 2014-02-19 19:01:45 -0800 | [diff] [blame] | 107 | |
| 108 | /** |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 109 | * Gets all links in the network. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 110 | * <p/> |
Pavlin Radoslavov | 06df22a | 2014-02-18 19:16:27 -0800 | [diff] [blame] | 111 | * TODO: Not clear if this method is needed. Remove if not used. |
| 112 | * |
| 113 | * @return all links in the network. |
| 114 | */ |
| 115 | public Iterable<Link> getLinks(); |
| 116 | |
| 117 | /** |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 118 | * Gets the network device for a given MAC address. |
Pavlin Radoslavov | 06df22a | 2014-02-18 19:16:27 -0800 | [diff] [blame] | 119 | * |
| 120 | * @param address the MAC address to use. |
| 121 | * @return the network device for the MAC address if found, otherwise null. |
| 122 | */ |
| 123 | public Device getDeviceByMac(MACAddress address); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 124 | |
Jonathan Hart | 26f291b | 2014-02-18 16:57:24 -0800 | [diff] [blame] | 125 | /** |
Yuta HIGUCHI | fa74284 | 2014-07-03 22:35:13 -0700 | [diff] [blame] | 126 | * Gets all devices in the network. |
| 127 | * |
| 128 | * @return all devices in the network |
| 129 | */ |
| 130 | public Iterable<Device> getDevices(); |
| 131 | |
| 132 | /** |
| 133 | * Gets all devices on specified port. |
| 134 | * |
| 135 | * @param port port which the device is attached |
| 136 | * @return all devices attached to the port. |
| 137 | */ |
| 138 | public Collection<Device> getDevices(SwitchPort port); |
| 139 | |
| 140 | /** |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 141 | * Acquire a read lock on the entire topology. The topology will not |
| 142 | * change while readers have the lock. Must be released using |
Sho SHIMIZU | bfe4a45 | 2014-06-09 15:18:11 -0700 | [diff] [blame] | 143 | * {@link #releaseReadLock()}. This method will block until a read lock is |
Jonathan Hart | 26f291b | 2014-02-18 16:57:24 -0800 | [diff] [blame] | 144 | * available. |
| 145 | */ |
Pavlin Radoslavov | 8ffb8bf | 2014-02-20 15:34:26 -0800 | [diff] [blame] | 146 | public void acquireReadLock(); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 147 | |
Pavlin Radoslavov | 7c8f69a | 2014-02-19 19:01:45 -0800 | [diff] [blame] | 148 | /** |
| 149 | * Release the read lock on the topology. |
| 150 | */ |
Pavlin Radoslavov | 8ffb8bf | 2014-02-20 15:34:26 -0800 | [diff] [blame] | 151 | public void releaseReadLock(); |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 152 | } |