blob: edf017b9e2c8d6162ff921630a0394b25fa75449 [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 Hartf5bd2582014-04-09 17:43:41 -07003import net.onrc.onos.core.topology.NetworkGraph;
4
Jonathan Harte6e63732014-04-16 14:29:49 -07005import com.google.common.collect.HashMultimap;
6import com.google.common.collect.Multimap;
Ray Milkey269ffb92014-04-03 14:43:30 -07007
Jonathan Hart7804bea2014-01-07 10:50:52 -08008/**
9 * Notification to another ONOS instance to send a packet out a single port.
Jonathan Hart7804bea2014-01-07 10:50:52 -080010 */
11public class SinglePacketOutNotification extends PacketOutNotification {
12
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070013 private static final long serialVersionUID = 1L;
Jonathan Hart7804bea2014-01-07 10:50:52 -080014
TeruU7feef8a2014-04-03 00:15:49 -070015 private final int address;
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070016 private final long outSwitch;
17 private final short outPort;
Jonathan Hart7804bea2014-01-07 10:50:52 -080018
Jonathan Hart51dc5e12014-04-22 11:03:59 -070019 /**
20 * Default constructor, used for deserialization.
21 */
Jonathan Hartf5bd2582014-04-09 17:43:41 -070022 protected SinglePacketOutNotification() {
23 address = 0;
24 outSwitch = 0;
25 outPort = 0;
26 }
27
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070028 /**
29 * Class constructor.
Ray Milkey269ffb92014-04-03 14:43:30 -070030 *
31 * @param packet the packet data to send in the packet-out
32 * @param address target IP address if the packet is an ARP packet
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070033 * @param outSwitch the dpid of the switch to send the packet on
Ray Milkey269ffb92014-04-03 14:43:30 -070034 * @param outPort the port number of the port to send the packet out
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070035 */
TeruU7feef8a2014-04-03 00:15:49 -070036 public SinglePacketOutNotification(byte[] packet, int address,
Ray Milkey269ffb92014-04-03 14:43:30 -070037 long outSwitch, short outPort) {
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070038 super(packet);
Jonathan Hart7804bea2014-01-07 10:50:52 -080039
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070040 this.address = address;
41 this.outSwitch = outSwitch;
42 this.outPort = outPort;
43 }
44
45 /**
46 * Get the dpid of the switch the packet will be sent out.
Ray Milkey269ffb92014-04-03 14:43:30 -070047 *
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070048 * @return the switch's dpid
49 */
50 public long getOutSwitch() {
51 return outSwitch;
52 }
53
54 /**
55 * Get the port number of the port the packet will be sent out.
Ray Milkey269ffb92014-04-03 14:43:30 -070056 *
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070057 * @return the port number
58 */
59 public short getOutPort() {
60 return outPort;
61 }
62
63 /**
64 * Get the target IP address if the packet is an ARP packet.
Ray Milkey269ffb92014-04-03 14:43:30 -070065 *
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070066 * @return the target IP address for ARP packets, or null if the packet is
Ray Milkey269ffb92014-04-03 14:43:30 -070067 * not an ARP packet
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070068 */
TeruU7feef8a2014-04-03 00:15:49 -070069 public int getTargetAddress() {
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070070 return address;
71 }
Jonathan Harte6e63732014-04-16 14:29:49 -070072
73 @Override
Jonathan Hartf5bd2582014-04-09 17:43:41 -070074 public Multimap<Long, Short> calculateOutPorts(
75 Multimap<Long, Short> localPorts, NetworkGraph networkGraph) {
Jonathan Harte6e63732014-04-16 14:29:49 -070076 Multimap<Long, Short> outPorts = HashMultimap.create();
77
Jonathan Hartf5bd2582014-04-09 17:43:41 -070078 if (localPorts.containsEntry(outSwitch, outPort)) {
Jonathan Harte6e63732014-04-16 14:29:49 -070079 outPorts.put(outSwitch, outPort);
80 }
81
82 return outPorts;
83 }
Jonathan Hart7804bea2014-01-07 10:50:52 -080084}