Jonathan Hart | 313fdf0 | 2014-04-10 14:09:46 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.packetservice; |
Jonathan Hart | 7804bea | 2014-01-07 10:50:52 -0800 | [diff] [blame] | 2 | |
| 3 | import java.io.Serializable; |
Jonathan Hart | 8ed69c5 | 2014-04-09 13:29:16 -0700 | [diff] [blame] | 4 | import java.util.Arrays; |
Jonathan Hart | 7804bea | 2014-01-07 10:50:52 -0800 | [diff] [blame] | 5 | |
Jonathan Hart | f5bd258 | 2014-04-09 17:43:41 -0700 | [diff] [blame] | 6 | import net.onrc.onos.core.topology.NetworkGraph; |
| 7 | |
Jonathan Hart | e6e6373 | 2014-04-16 14:29:49 -0700 | [diff] [blame] | 8 | import com.google.common.collect.Multimap; |
| 9 | |
Jonathan Hart | 7804bea | 2014-01-07 10:50:52 -0800 | [diff] [blame] | 10 | /** |
| 11 | * A PacketOutNotification contains data sent between ONOS instances that |
Jonathan Hart | 7c9a2fb | 2014-03-27 09:51:41 -0700 | [diff] [blame] | 12 | * directs other instances to send a packet out a set of ports. This is an |
| 13 | * abstract base class that will be subclassed by specific types of |
| 14 | * notifications. |
Jonathan Hart | 7804bea | 2014-01-07 10:50:52 -0800 | [diff] [blame] | 15 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 16 | public abstract class PacketOutNotification implements Serializable { |
Jonathan Hart | 7804bea | 2014-01-07 10:50:52 -0800 | [diff] [blame] | 17 | |
Jonathan Hart | 7c9a2fb | 2014-03-27 09:51:41 -0700 | [diff] [blame] | 18 | private static final long serialVersionUID = 1L; |
Jonathan Hart | 7804bea | 2014-01-07 10:50:52 -0800 | [diff] [blame] | 19 | |
Jonathan Hart | 313fdf0 | 2014-04-10 14:09:46 -0700 | [diff] [blame] | 20 | private final byte[] packet; |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 21 | |
Jonathan Hart | 7c9a2fb | 2014-03-27 09:51:41 -0700 | [diff] [blame] | 22 | /** |
Jonathan Hart | e6e6373 | 2014-04-16 14:29:49 -0700 | [diff] [blame] | 23 | * Default constructor. |
| 24 | */ |
| 25 | protected PacketOutNotification() { |
| 26 | packet = null; |
| 27 | } |
| 28 | |
| 29 | /** |
Jonathan Hart | 7c9a2fb | 2014-03-27 09:51:41 -0700 | [diff] [blame] | 30 | * Class constructor. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 31 | * |
Jonathan Hart | 7c9a2fb | 2014-03-27 09:51:41 -0700 | [diff] [blame] | 32 | * @param packet the packet data to send in the packet-out |
| 33 | */ |
| 34 | public PacketOutNotification(byte[] packet) { |
Jonathan Hart | 8ed69c5 | 2014-04-09 13:29:16 -0700 | [diff] [blame] | 35 | this.packet = Arrays.copyOf(packet, packet.length); |
Jonathan Hart | 7c9a2fb | 2014-03-27 09:51:41 -0700 | [diff] [blame] | 36 | } |
Jonathan Hart | 313fdf0 | 2014-04-10 14:09:46 -0700 | [diff] [blame] | 37 | |
Jonathan Hart | e6e6373 | 2014-04-16 14:29:49 -0700 | [diff] [blame] | 38 | /** |
| 39 | * Gets the packet that needs to be sent into the network. |
| 40 | * |
| 41 | * @return the packet data as a serialized byte array |
| 42 | */ |
Jonathan Hart | 313fdf0 | 2014-04-10 14:09:46 -0700 | [diff] [blame] | 43 | public byte[] getPacketData() { |
| 44 | return Arrays.copyOf(packet, packet.length); |
| 45 | } |
Jonathan Hart | e6e6373 | 2014-04-16 14:29:49 -0700 | [diff] [blame] | 46 | |
| 47 | /** |
| 48 | * Calculate a list of local ports that the packet should be sent out. |
| 49 | * <p/> |
| 50 | * A {@link PacketOutNotification} contains a high-level description of the |
| 51 | * where to send the packet. The receiver of the notification needs to know |
| 52 | * an explicit list of ports to send the packet out. This function will |
| 53 | * calculate that list, given the list of edge ports controlled by this |
| 54 | * instance. |
| 55 | * |
Jonathan Hart | f5bd258 | 2014-04-09 17:43:41 -0700 | [diff] [blame] | 56 | * @param localPorts the map of locally-controlled ports |
| 57 | * @param networkGraph an instance of the global network graph |
Jonathan Hart | e6e6373 | 2014-04-16 14:29:49 -0700 | [diff] [blame] | 58 | * @return a multimap of ports that the packet should be sent out, |
| 59 | * in the form |
| 60 | * {@code {dpid1 => {portnum1, portnum2, ...}, dpid2 => {portnum1}, ...}} |
| 61 | */ |
| 62 | public abstract Multimap<Long, Short> calculateOutPorts( |
Jonathan Hart | f5bd258 | 2014-04-09 17:43:41 -0700 | [diff] [blame] | 63 | Multimap<Long, Short> localPorts, NetworkGraph networkGraph); |
Jonathan Hart | 7804bea | 2014-01-07 10:50:52 -0800 | [diff] [blame] | 64 | } |