blob: cd604ea51fca451ba6c308d5ae6ee0e04727067f [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 Hartf5bd2582014-04-09 17:43:41 -070019 protected SinglePacketOutNotification() {
20 address = 0;
21 outSwitch = 0;
22 outPort = 0;
23 }
24
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070025 /**
26 * Class constructor.
Ray Milkey269ffb92014-04-03 14:43:30 -070027 *
28 * @param packet the packet data to send in the packet-out
29 * @param address target IP address if the packet is an ARP packet
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070030 * @param outSwitch the dpid of the switch to send the packet on
Ray Milkey269ffb92014-04-03 14:43:30 -070031 * @param outPort the port number of the port to send the packet out
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070032 */
TeruU7feef8a2014-04-03 00:15:49 -070033 public SinglePacketOutNotification(byte[] packet, int address,
Ray Milkey269ffb92014-04-03 14:43:30 -070034 long outSwitch, short outPort) {
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070035 super(packet);
Jonathan Hart7804bea2014-01-07 10:50:52 -080036
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070037 this.address = address;
38 this.outSwitch = outSwitch;
39 this.outPort = outPort;
40 }
41
42 /**
43 * Get the dpid of the switch the packet will be sent out.
Ray Milkey269ffb92014-04-03 14:43:30 -070044 *
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070045 * @return the switch's dpid
46 */
47 public long getOutSwitch() {
48 return outSwitch;
49 }
50
51 /**
52 * Get the port number of the port the packet will be sent out.
Ray Milkey269ffb92014-04-03 14:43:30 -070053 *
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070054 * @return the port number
55 */
56 public short getOutPort() {
57 return outPort;
58 }
59
60 /**
61 * Get the target IP address if the packet is an ARP packet.
Ray Milkey269ffb92014-04-03 14:43:30 -070062 *
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070063 * @return the target IP address for ARP packets, or null if the packet is
Ray Milkey269ffb92014-04-03 14:43:30 -070064 * not an ARP packet
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070065 */
TeruU7feef8a2014-04-03 00:15:49 -070066 public int getTargetAddress() {
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070067 return address;
68 }
Jonathan Harte6e63732014-04-16 14:29:49 -070069
70 @Override
Jonathan Hartf5bd2582014-04-09 17:43:41 -070071 public Multimap<Long, Short> calculateOutPorts(
72 Multimap<Long, Short> localPorts, NetworkGraph networkGraph) {
Jonathan Harte6e63732014-04-16 14:29:49 -070073 Multimap<Long, Short> outPorts = HashMultimap.create();
74
Jonathan Hartf5bd2582014-04-09 17:43:41 -070075 if (localPorts.containsEntry(outSwitch, outPort)) {
Jonathan Harte6e63732014-04-16 14:29:49 -070076 outPorts.put(outSwitch, outPort);
77 }
78
79 return outPorts;
80 }
Jonathan Hart7804bea2014-01-07 10:50:52 -080081}