blob: e6260e088c97eecc918daea98521fdae7cb11b38 [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 Harte6e63732014-04-16 14:29:49 -07003import com.google.common.collect.HashMultimap;
4import com.google.common.collect.Multimap;
Ray Milkey269ffb92014-04-03 14:43:30 -07005
Jonathan Hart7804bea2014-01-07 10:50:52 -08006/**
7 * Notification to another ONOS instance to send a packet out a single port.
Jonathan Hart7804bea2014-01-07 10:50:52 -08008 */
9public class SinglePacketOutNotification extends PacketOutNotification {
10
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070011 private static final long serialVersionUID = 1L;
Jonathan Hart7804bea2014-01-07 10:50:52 -080012
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 Hart7c9a2fb2014-03-27 09:51:41 -070017 /**
18 * Class constructor.
Ray Milkey269ffb92014-04-03 14:43:30 -070019 *
20 * @param packet the packet data to send in the packet-out
21 * @param address target IP address if the packet is an ARP packet
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070022 * @param outSwitch the dpid of the switch to send the packet on
Ray Milkey269ffb92014-04-03 14:43:30 -070023 * @param outPort the port number of the port to send the packet out
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070024 */
TeruU7feef8a2014-04-03 00:15:49 -070025 public SinglePacketOutNotification(byte[] packet, int address,
Ray Milkey269ffb92014-04-03 14:43:30 -070026 long outSwitch, short outPort) {
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070027 super(packet);
Jonathan Hart7804bea2014-01-07 10:50:52 -080028
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070029 this.address = address;
30 this.outSwitch = outSwitch;
31 this.outPort = outPort;
32 }
33
34 /**
35 * Get the dpid of the switch the packet will be sent out.
Ray Milkey269ffb92014-04-03 14:43:30 -070036 *
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070037 * @return the switch's dpid
38 */
39 public long getOutSwitch() {
40 return outSwitch;
41 }
42
43 /**
44 * Get the port number of the port the packet will be sent out.
Ray Milkey269ffb92014-04-03 14:43:30 -070045 *
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070046 * @return the port number
47 */
48 public short getOutPort() {
49 return outPort;
50 }
51
52 /**
53 * Get the target IP address if the packet is an ARP packet.
Ray Milkey269ffb92014-04-03 14:43:30 -070054 *
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070055 * @return the target IP address for ARP packets, or null if the packet is
Ray Milkey269ffb92014-04-03 14:43:30 -070056 * not an ARP packet
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070057 */
TeruU7feef8a2014-04-03 00:15:49 -070058 public int getTargetAddress() {
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070059 return address;
60 }
Jonathan Harte6e63732014-04-16 14:29:49 -070061
62 @Override
63 public Multimap<Long, Short> calculateOutPorts(Multimap<Long, Short> localSwitches) {
64 Multimap<Long, Short> outPorts = HashMultimap.create();
65
66 if (localSwitches.containsEntry(outSwitch, outPort)) {
67 outPorts.put(outSwitch, outPort);
68 }
69
70 return outPorts;
71 }
Jonathan Hart7804bea2014-01-07 10:50:52 -080072}