blob: 8fe8efe5204cfff666096f5114ed136a452e9351 [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 Harte6e63732014-04-16 14:29:49 -07006import com.google.common.collect.Multimap;
7
Jonathan Hart7804bea2014-01-07 10:50:52 -08008/**
9 * A PacketOutNotification contains data sent between ONOS instances that
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070010 * directs other instances to send a packet out a set of ports. This is an
11 * abstract base class that will be subclassed by specific types of
12 * notifications.
Jonathan Hart7804bea2014-01-07 10:50:52 -080013 */
Ray Milkey269ffb92014-04-03 14:43:30 -070014public abstract class PacketOutNotification implements Serializable {
Jonathan Hart7804bea2014-01-07 10:50:52 -080015
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070016 private static final long serialVersionUID = 1L;
Jonathan Hart7804bea2014-01-07 10:50:52 -080017
Jonathan Hart313fdf02014-04-10 14:09:46 -070018 private final byte[] packet;
Ray Milkey269ffb92014-04-03 14:43:30 -070019
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070020 /**
Jonathan Harte6e63732014-04-16 14:29:49 -070021 * Default constructor.
22 */
23 protected PacketOutNotification() {
24 packet = null;
25 }
26
27 /**
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070028 * Class constructor.
Ray Milkey269ffb92014-04-03 14:43:30 -070029 *
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070030 * @param packet the packet data to send in the packet-out
31 */
32 public PacketOutNotification(byte[] packet) {
Jonathan Hart8ed69c52014-04-09 13:29:16 -070033 this.packet = Arrays.copyOf(packet, packet.length);
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070034 }
Jonathan Hart313fdf02014-04-10 14:09:46 -070035
Jonathan Harte6e63732014-04-16 14:29:49 -070036 /**
37 * Gets the packet that needs to be sent into the network.
38 *
39 * @return the packet data as a serialized byte array
40 */
Jonathan Hart313fdf02014-04-10 14:09:46 -070041 public byte[] getPacketData() {
42 return Arrays.copyOf(packet, packet.length);
43 }
Jonathan Harte6e63732014-04-16 14:29:49 -070044
45 /**
46 * Calculate a list of local ports that the packet should be sent out.
47 * <p/>
48 * A {@link PacketOutNotification} contains a high-level description of the
49 * where to send the packet. The receiver of the notification needs to know
50 * an explicit list of ports to send the packet out. This function will
51 * calculate that list, given the list of edge ports controlled by this
52 * instance.
53 *
54 * @param localSwitches the map of locally-controlled edge ports
55 * @return a multimap of ports that the packet should be sent out,
56 * in the form
57 * {@code {dpid1 => {portnum1, portnum2, ...}, dpid2 => {portnum1}, ...}}
58 */
59 public abstract Multimap<Long, Short> calculateOutPorts(
60 Multimap<Long, Short> localEdgePorts);
Jonathan Hart7804bea2014-01-07 10:50:52 -080061}