blob: d95ddf2c28e1f31410aafd3e581ad47bf421051e [file] [log] [blame]
Jonathan Hart313fdf02014-04-10 14:09:46 -07001package net.onrc.onos.core.packetservice;
Jonathan Hart7804bea2014-01-07 10:50:52 -08002
3import java.io.Serializable;
Jonathan Hart8ed69c52014-04-09 13:29:16 -07004import java.util.Arrays;
Jonathan Hart7804bea2014-01-07 10:50:52 -08005
Jonathan Hartf5bd2582014-04-09 17:43:41 -07006import net.onrc.onos.core.topology.NetworkGraph;
7
Jonathan Harte6e63732014-04-16 14:29:49 -07008import com.google.common.collect.Multimap;
9
Jonathan Hart7804bea2014-01-07 10:50:52 -080010/**
11 * A PacketOutNotification contains data sent between ONOS instances that
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070012 * 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 Hart7804bea2014-01-07 10:50:52 -080015 */
Ray Milkey269ffb92014-04-03 14:43:30 -070016public abstract class PacketOutNotification implements Serializable {
Jonathan Hart7804bea2014-01-07 10:50:52 -080017
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070018 private static final long serialVersionUID = 1L;
Jonathan Hart7804bea2014-01-07 10:50:52 -080019
Jonathan Hart313fdf02014-04-10 14:09:46 -070020 private final byte[] packet;
Ray Milkey269ffb92014-04-03 14:43:30 -070021
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070022 /**
Jonathan Harte6e63732014-04-16 14:29:49 -070023 * Default constructor.
24 */
25 protected PacketOutNotification() {
26 packet = null;
27 }
28
29 /**
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070030 * Class constructor.
Ray Milkey269ffb92014-04-03 14:43:30 -070031 *
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070032 * @param packet the packet data to send in the packet-out
33 */
34 public PacketOutNotification(byte[] packet) {
Jonathan Hart8ed69c52014-04-09 13:29:16 -070035 this.packet = Arrays.copyOf(packet, packet.length);
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070036 }
Jonathan Hart313fdf02014-04-10 14:09:46 -070037
Jonathan Harte6e63732014-04-16 14:29:49 -070038 /**
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 Hart313fdf02014-04-10 14:09:46 -070043 public byte[] getPacketData() {
44 return Arrays.copyOf(packet, packet.length);
45 }
Jonathan Harte6e63732014-04-16 14:29:49 -070046
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 Hartf5bd2582014-04-09 17:43:41 -070056 * @param localPorts the map of locally-controlled ports
57 * @param networkGraph an instance of the global network graph
Jonathan Harte6e63732014-04-16 14:29:49 -070058 * @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 Hartf5bd2582014-04-09 17:43:41 -070063 Multimap<Long, Short> localPorts, NetworkGraph networkGraph);
Jonathan Hart7804bea2014-01-07 10:50:52 -080064}