blob: 11a1015fac61bc029e2e0147368352b09843ab00 [file] [log] [blame]
Jonathan Hart313fdf02014-04-10 14:09:46 -07001package net.onrc.onos.core.packetservice;
Jonathan Hart7804bea2014-01-07 10:50:52 -08002
Jonathan Hart8ed69c52014-04-09 13:29:16 -07003import java.util.Arrays;
Jonathan Hart7804bea2014-01-07 10:50:52 -08004
Yuta HIGUCHId92b10c2014-08-25 09:30:28 -07005import net.onrc.onos.core.topology.MutableTopology;
Jonathan Hartf5bd2582014-04-09 17:43:41 -07006
Jonathan Harte6e63732014-04-16 14:29:49 -07007import com.google.common.collect.Multimap;
8
Jonathan Hart7804bea2014-01-07 10:50:52 -08009/**
10 * A PacketOutNotification contains data sent between ONOS instances that
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070011 * directs other instances to send a packet out a set of ports. This is an
12 * abstract base class that will be subclassed by specific types of
13 * notifications.
Jonathan Hart7804bea2014-01-07 10:50:52 -080014 */
pingping-lin0426dee2014-08-27 15:03:17 -070015public abstract class PacketOutNotification {
Jonathan Hart7804bea2014-01-07 10:50:52 -080016
Jonathan Hart313fdf02014-04-10 14:09:46 -070017 private final byte[] packet;
Ray Milkey269ffb92014-04-03 14:43:30 -070018
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070019 /**
Jonathan Hart51dc5e12014-04-22 11:03:59 -070020 * Default constructor, used for deserialization.
Jonathan Harte6e63732014-04-16 14:29:49 -070021 */
22 protected PacketOutNotification() {
23 packet = null;
24 }
25
26 /**
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070027 * Class constructor.
Ray Milkey269ffb92014-04-03 14:43:30 -070028 *
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070029 * @param packet the packet data to send in the packet-out
30 */
31 public PacketOutNotification(byte[] packet) {
Jonathan Hart8ed69c52014-04-09 13:29:16 -070032 this.packet = Arrays.copyOf(packet, packet.length);
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070033 }
Jonathan Hart313fdf02014-04-10 14:09:46 -070034
Jonathan Harte6e63732014-04-16 14:29:49 -070035 /**
36 * Gets the packet that needs to be sent into the network.
37 *
38 * @return the packet data as a serialized byte array
39 */
Jonathan Hart313fdf02014-04-10 14:09:46 -070040 public byte[] getPacketData() {
41 return Arrays.copyOf(packet, packet.length);
42 }
Jonathan Harte6e63732014-04-16 14:29:49 -070043
44 /**
45 * Calculate a list of local ports that the packet should be sent out.
46 * <p/>
47 * A {@link PacketOutNotification} contains a high-level description of the
48 * where to send the packet. The receiver of the notification needs to know
49 * an explicit list of ports to send the packet out. This function will
50 * calculate that list, given the list of edge ports controlled by this
51 * instance.
52 *
Jonathan Hartf5bd2582014-04-09 17:43:41 -070053 * @param localPorts the map of locally-controlled ports
Yuta HIGUCHId92b10c2014-08-25 09:30:28 -070054 * @param mutableTopology an instance of the global topology
Jonathan Harte6e63732014-04-16 14:29:49 -070055 * @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(
Yuta HIGUCHId92b10c2014-08-25 09:30:28 -070060 Multimap<Long, Short> localPorts, MutableTopology mutableTopology);
Jonathan Hart7804bea2014-01-07 10:50:52 -080061}