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. |
Yuta HIGUCHI | cd14dda | 2014-07-24 09:57:22 -0700 | [diff] [blame] | 40 | * @param portNumber 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 | cd14dda | 2014-07-24 09:57:22 -0700 | [diff] [blame] | 43 | public Port getPort(Dpid dpid, PortNumber portNumber); |
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. |
Yuta HIGUCHI | 8313f0b | 2014-07-09 16:36:03 -0700 | [diff] [blame] | 63 | * <p/> |
| 64 | * FIXME As a temporary workaround, it will look for type "packet" and |
| 65 | * returns it if found, else return whichever link is found first. |
Pavlin Radoslavov | 7c8f69a | 2014-02-19 19:01:45 -0800 | [diff] [blame] | 66 | * |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 67 | * @param dpid the switch DPID. |
Yuta HIGUCHI | cd14dda | 2014-07-24 09:57:22 -0700 | [diff] [blame] | 68 | * @param portNumber the switch port number. |
Pavlin Radoslavov | 7c8f69a | 2014-02-19 19:01:45 -0800 | [diff] [blame] | 69 | * @return the outgoing link if found, otherwise null. |
| 70 | */ |
Yuta HIGUCHI | cd14dda | 2014-07-24 09:57:22 -0700 | [diff] [blame] | 71 | public Link getOutgoingLink(Dpid dpid, PortNumber portNumber); |
Jonathan Hart | 25bd53e | 2014-04-30 23:44:09 -0700 | [diff] [blame] | 72 | |
| 73 | /** |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 74 | * Gets the outgoing link from a switch port. |
| 75 | * |
Yuta HIGUCHI | 8313f0b | 2014-07-09 16:36:03 -0700 | [diff] [blame] | 76 | * @param dpid the switch DPID. |
Yuta HIGUCHI | cd14dda | 2014-07-24 09:57:22 -0700 | [diff] [blame] | 77 | * @param portNumber the switch port number. |
Yuta HIGUCHI | 8313f0b | 2014-07-09 16:36:03 -0700 | [diff] [blame] | 78 | * @param type type of the link |
| 79 | * @return the outgoing link if found, otherwise null. |
| 80 | */ |
Yuta HIGUCHI | cd14dda | 2014-07-24 09:57:22 -0700 | [diff] [blame] | 81 | public Link getOutgoingLink(Dpid dpid, PortNumber portNumber, String type); |
Yuta HIGUCHI | 8313f0b | 2014-07-09 16:36:03 -0700 | [diff] [blame] | 82 | |
| 83 | /** |
| 84 | * Gets the outgoing link from a switch port. |
| 85 | * <p/> |
| 86 | * FIXME As a temporary workaround, it will look for type "packet" and |
| 87 | * returns it if found, else return whichever link is found first. |
| 88 | * |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 89 | * @param port port identifier |
Yuta HIGUCHI | 8313f0b | 2014-07-09 16:36:03 -0700 | [diff] [blame] | 90 | * @return the outgoing link if found, otherwise null. |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 91 | */ |
| 92 | public Link getOutgoingLink(SwitchPort port); |
| 93 | |
| 94 | /** |
Yuta HIGUCHI | 8313f0b | 2014-07-09 16:36:03 -0700 | [diff] [blame] | 95 | * Gets the outgoing link from a switch port. |
| 96 | * |
| 97 | * @param port port identifier |
| 98 | * @param type type of the link |
| 99 | * @return the outgoing link if found, otherwise null. |
| 100 | */ |
| 101 | public Link getOutgoingLink(SwitchPort port, String type); |
| 102 | |
| 103 | /** |
| 104 | * Gets all the outgoing link from a switch port. |
| 105 | * |
| 106 | * @param port port identifier |
| 107 | * @return outgoing links |
| 108 | */ |
| 109 | public Collection<Link> getOutgoingLinks(SwitchPort port); |
| 110 | |
| 111 | /** |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 112 | * Gets the incoming link to a switch port. |
Yuta HIGUCHI | 8313f0b | 2014-07-09 16:36:03 -0700 | [diff] [blame] | 113 | * <p/> |
| 114 | * FIXME As a temporary workaround, it will look for type "packet" and |
| 115 | * returns it if found, else return whichever link is found first. |
Jonathan Hart | 25bd53e | 2014-04-30 23:44:09 -0700 | [diff] [blame] | 116 | * |
| 117 | * @param dpid the switch DPID. |
Yuta HIGUCHI | cd14dda | 2014-07-24 09:57:22 -0700 | [diff] [blame] | 118 | * @param portNumber the switch port number. |
Jonathan Hart | 25bd53e | 2014-04-30 23:44:09 -0700 | [diff] [blame] | 119 | * @return the incoming link if found, otherwise null. |
| 120 | */ |
Yuta HIGUCHI | cd14dda | 2014-07-24 09:57:22 -0700 | [diff] [blame] | 121 | public Link getIncomingLink(Dpid dpid, PortNumber portNumber); |
Pavlin Radoslavov | 7c8f69a | 2014-02-19 19:01:45 -0800 | [diff] [blame] | 122 | |
| 123 | /** |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 124 | * Gets the incoming link to a switch port. |
Yuta HIGUCHI | 8313f0b | 2014-07-09 16:36:03 -0700 | [diff] [blame] | 125 | * <p/> |
| 126 | * FIXME As a temporary workaround, it will look for type "packet" and |
| 127 | * returns it if found, else return whichever link is found first. |
| 128 | * |
| 129 | * @param dpid the switch DPID. |
Yuta HIGUCHI | cd14dda | 2014-07-24 09:57:22 -0700 | [diff] [blame] | 130 | * @param portNumber the switch port number. |
Yuta HIGUCHI | 8313f0b | 2014-07-09 16:36:03 -0700 | [diff] [blame] | 131 | * @param type type of the link |
| 132 | * @return the incoming link if found, otherwise null. |
| 133 | */ |
Yuta HIGUCHI | cd14dda | 2014-07-24 09:57:22 -0700 | [diff] [blame] | 134 | public Link getIncomingLink(Dpid dpid, PortNumber portNumber, String type); |
Yuta HIGUCHI | 8313f0b | 2014-07-09 16:36:03 -0700 | [diff] [blame] | 135 | |
| 136 | |
| 137 | /** |
| 138 | * Gets the incoming link to a switch port. |
| 139 | * <p/> |
| 140 | * FIXME As a temporary workaround, it will look for type "packet" and |
| 141 | * returns it if found, else return whichever link is found first. |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 142 | * |
| 143 | * @param port port identifier |
Yuta HIGUCHI | 8313f0b | 2014-07-09 16:36:03 -0700 | [diff] [blame] | 144 | * @return the incoming link if found, otherwise null. |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 145 | */ |
| 146 | public Link getIncomingLink(SwitchPort port); |
| 147 | |
| 148 | /** |
Yuta HIGUCHI | 8313f0b | 2014-07-09 16:36:03 -0700 | [diff] [blame] | 149 | * Gets the incoming link to a switch port. |
| 150 | * |
| 151 | * @param port port identifier |
| 152 | * @param type type of the link |
| 153 | * @return the incoming link if found, otherwise null. |
| 154 | */ |
| 155 | public Link getIncomingLink(SwitchPort port, String type); |
| 156 | |
| 157 | /** |
| 158 | * Gets all the incoming link from a switch port. |
| 159 | * |
| 160 | * @param port port identifier |
| 161 | * @return incoming links |
| 162 | */ |
| 163 | public Collection<Link> getIncomingLinks(SwitchPort port); |
| 164 | |
| 165 | /** |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 166 | * 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] | 167 | * a port. |
| 168 | * |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 169 | * @param srcDpid the source switch DPID. |
Yuta HIGUCHI | cd14dda | 2014-07-24 09:57:22 -0700 | [diff] [blame] | 170 | * @param srcPortNumber the source switch port number. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 171 | * @param dstDpid the destination switch DPID. |
Yuta HIGUCHI | cd14dda | 2014-07-24 09:57:22 -0700 | [diff] [blame] | 172 | * @param dstPortNumber the destination switch port number. |
Pavlin Radoslavov | 7c8f69a | 2014-02-19 19:01:45 -0800 | [diff] [blame] | 173 | * @return the outgoing link if found, otherwise null. |
| 174 | */ |
Yuta HIGUCHI | cd14dda | 2014-07-24 09:57:22 -0700 | [diff] [blame] | 175 | public Link getLink(Dpid srcDpid, PortNumber srcPortNumber, |
| 176 | Dpid dstDpid, PortNumber dstPortNumber); |
Pavlin Radoslavov | 7c8f69a | 2014-02-19 19:01:45 -0800 | [diff] [blame] | 177 | |
| 178 | /** |
Yuta HIGUCHI | 8313f0b | 2014-07-09 16:36:03 -0700 | [diff] [blame] | 179 | * Gets the outgoing link from a switch and a port to another switch and |
| 180 | * a port. |
| 181 | * |
| 182 | * @param srcDpid the source switch DPID. |
Yuta HIGUCHI | cd14dda | 2014-07-24 09:57:22 -0700 | [diff] [blame] | 183 | * @param srcPortNumber the source switch port number. |
Yuta HIGUCHI | 8313f0b | 2014-07-09 16:36:03 -0700 | [diff] [blame] | 184 | * @param dstDpid the destination switch DPID. |
Yuta HIGUCHI | cd14dda | 2014-07-24 09:57:22 -0700 | [diff] [blame] | 185 | * @param dstPortNumber the destination switch port number. |
Yuta HIGUCHI | 8313f0b | 2014-07-09 16:36:03 -0700 | [diff] [blame] | 186 | * @param type type of the link |
| 187 | * @return the outgoing link if found, otherwise null. |
| 188 | */ |
Yuta HIGUCHI | cd14dda | 2014-07-24 09:57:22 -0700 | [diff] [blame] | 189 | public Link getLink(Dpid srcDpid, PortNumber srcPortNumber, |
| 190 | Dpid dstDpid, PortNumber dstPortNumber, |
Yuta HIGUCHI | 8313f0b | 2014-07-09 16:36:03 -0700 | [diff] [blame] | 191 | String type); |
| 192 | |
| 193 | /** |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 194 | * Gets all links in the network. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 195 | * <p/> |
Pavlin Radoslavov | 06df22a | 2014-02-18 19:16:27 -0800 | [diff] [blame] | 196 | * |
| 197 | * @return all links in the network. |
| 198 | */ |
| 199 | public Iterable<Link> getLinks(); |
| 200 | |
| 201 | /** |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 202 | * Gets the network device for a given MAC address. |
Pavlin Radoslavov | 06df22a | 2014-02-18 19:16:27 -0800 | [diff] [blame] | 203 | * |
| 204 | * @param address the MAC address to use. |
| 205 | * @return the network device for the MAC address if found, otherwise null. |
| 206 | */ |
Yuta HIGUCHI | bfc77f0 | 2014-07-14 22:50:25 -0700 | [diff] [blame] | 207 | public Host getHostByMac(MACAddress address); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 208 | |
Jonathan Hart | 26f291b | 2014-02-18 16:57:24 -0800 | [diff] [blame] | 209 | /** |
Yuta HIGUCHI | fa74284 | 2014-07-03 22:35:13 -0700 | [diff] [blame] | 210 | * Gets all devices in the network. |
| 211 | * |
| 212 | * @return all devices in the network |
| 213 | */ |
Yuta HIGUCHI | bfc77f0 | 2014-07-14 22:50:25 -0700 | [diff] [blame] | 214 | public Iterable<Host> getHosts(); |
Yuta HIGUCHI | fa74284 | 2014-07-03 22:35:13 -0700 | [diff] [blame] | 215 | |
| 216 | /** |
| 217 | * Gets all devices on specified port. |
| 218 | * |
| 219 | * @param port port which the device is attached |
| 220 | * @return all devices attached to the port. |
| 221 | */ |
Yuta HIGUCHI | bfc77f0 | 2014-07-14 22:50:25 -0700 | [diff] [blame] | 222 | public Collection<Host> getHosts(SwitchPort port); |
Yuta HIGUCHI | fa74284 | 2014-07-03 22:35:13 -0700 | [diff] [blame] | 223 | |
| 224 | /** |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 225 | * Acquire a read lock on the entire topology. The topology will not |
| 226 | * change while readers have the lock. Must be released using |
Sho SHIMIZU | bfe4a45 | 2014-06-09 15:18:11 -0700 | [diff] [blame] | 227 | * {@link #releaseReadLock()}. This method will block until a read lock is |
Jonathan Hart | 26f291b | 2014-02-18 16:57:24 -0800 | [diff] [blame] | 228 | * available. |
| 229 | */ |
Pavlin Radoslavov | 8ffb8bf | 2014-02-20 15:34:26 -0800 | [diff] [blame] | 230 | public void acquireReadLock(); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 231 | |
Pavlin Radoslavov | 7c8f69a | 2014-02-19 19:01:45 -0800 | [diff] [blame] | 232 | /** |
| 233 | * Release the read lock on the topology. |
| 234 | */ |
Pavlin Radoslavov | 8ffb8bf | 2014-02-20 15:34:26 -0800 | [diff] [blame] | 235 | public void releaseReadLock(); |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 236 | } |