blob: 85896e73e527e92a88c3044de262669440c8e108 [file] [log] [blame]
Jonathan Hart313fdf02014-04-10 14:09:46 -07001package net.onrc.onos.core.packetservice;
Jonathan Hart7804bea2014-01-07 10:50:52 -08002
Yuta HIGUCHId92b10c2014-08-25 09:30:28 -07003import net.onrc.onos.core.topology.MutableTopology;
Jonathan Hartf5bd2582014-04-09 17:43:41 -07004
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
TeruU7feef8a2014-04-03 00:15:49 -070013 private final int address;
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070014 private final long outSwitch;
15 private final short outPort;
Jonathan Hart7804bea2014-01-07 10:50:52 -080016
Jonathan Hart51dc5e12014-04-22 11:03:59 -070017 /**
18 * Default constructor, used for deserialization.
19 */
Jonathan Hartf5bd2582014-04-09 17:43:41 -070020 protected SinglePacketOutNotification() {
21 address = 0;
22 outSwitch = 0;
23 outPort = 0;
24 }
25
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070026 /**
27 * Class constructor.
Ray Milkey269ffb92014-04-03 14:43:30 -070028 *
29 * @param packet the packet data to send in the packet-out
30 * @param address target IP address if the packet is an ARP packet
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070031 * @param outSwitch the dpid of the switch to send the packet on
Ray Milkey269ffb92014-04-03 14:43:30 -070032 * @param outPort the port number of the port to send the packet out
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070033 */
TeruU7feef8a2014-04-03 00:15:49 -070034 public SinglePacketOutNotification(byte[] packet, int address,
Ray Milkey269ffb92014-04-03 14:43:30 -070035 long outSwitch, short outPort) {
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070036 super(packet);
Jonathan Hart7804bea2014-01-07 10:50:52 -080037
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070038 this.address = address;
39 this.outSwitch = outSwitch;
40 this.outPort = outPort;
41 }
42
43 /**
44 * Get the dpid of the switch the packet will be sent out.
Ray Milkey269ffb92014-04-03 14:43:30 -070045 *
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070046 * @return the switch's dpid
47 */
48 public long getOutSwitch() {
49 return outSwitch;
50 }
51
52 /**
53 * Get the port number of the port the packet will be sent out.
Ray Milkey269ffb92014-04-03 14:43:30 -070054 *
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070055 * @return the port number
56 */
57 public short getOutPort() {
58 return outPort;
59 }
60
61 /**
62 * Get the target IP address if the packet is an ARP packet.
Ray Milkey269ffb92014-04-03 14:43:30 -070063 *
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070064 * @return the target IP address for ARP packets, or null if the packet is
Ray Milkey269ffb92014-04-03 14:43:30 -070065 * not an ARP packet
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070066 */
TeruU7feef8a2014-04-03 00:15:49 -070067 public int getTargetAddress() {
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070068 return address;
69 }
Jonathan Harte6e63732014-04-16 14:29:49 -070070
71 @Override
Jonathan Hartf5bd2582014-04-09 17:43:41 -070072 public Multimap<Long, Short> calculateOutPorts(
Yuta HIGUCHId92b10c2014-08-25 09:30:28 -070073 Multimap<Long, Short> localPorts, MutableTopology mutableTopology) {
Jonathan Harte6e63732014-04-16 14:29:49 -070074 Multimap<Long, Short> outPorts = HashMultimap.create();
75
Jonathan Hartf5bd2582014-04-09 17:43:41 -070076 if (localPorts.containsEntry(outSwitch, outPort)) {
Jonathan Harte6e63732014-04-16 14:29:49 -070077 outPorts.put(outSwitch, outPort);
78 }
79
80 return outPorts;
81 }
Jonathan Hart7804bea2014-01-07 10:50:52 -080082}