Jonathan Hart | 313fdf0 | 2014-04-10 14:09:46 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.packetservice; |
Jonathan Hart | 7804bea | 2014-01-07 10:50:52 -0800 | [diff] [blame] | 2 | |
Yuta HIGUCHI | d92b10c | 2014-08-25 09:30:28 -0700 | [diff] [blame] | 3 | import net.onrc.onos.core.topology.MutableTopology; |
Jonathan Hart | f5bd258 | 2014-04-09 17:43:41 -0700 | [diff] [blame] | 4 | |
Jonathan Hart | e6e6373 | 2014-04-16 14:29:49 -0700 | [diff] [blame] | 5 | import com.google.common.collect.HashMultimap; |
| 6 | import com.google.common.collect.Multimap; |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 7 | |
Jonathan Hart | 7804bea | 2014-01-07 10:50:52 -0800 | [diff] [blame] | 8 | /** |
| 9 | * Notification to another ONOS instance to send a packet out a single port. |
Jonathan Hart | 7804bea | 2014-01-07 10:50:52 -0800 | [diff] [blame] | 10 | */ |
| 11 | public class SinglePacketOutNotification extends PacketOutNotification { |
| 12 | |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 13 | private final int address; |
Jonathan Hart | 7c9a2fb | 2014-03-27 09:51:41 -0700 | [diff] [blame] | 14 | private final long outSwitch; |
| 15 | private final short outPort; |
Jonathan Hart | 7804bea | 2014-01-07 10:50:52 -0800 | [diff] [blame] | 16 | |
Jonathan Hart | 51dc5e1 | 2014-04-22 11:03:59 -0700 | [diff] [blame] | 17 | /** |
| 18 | * Default constructor, used for deserialization. |
| 19 | */ |
Jonathan Hart | f5bd258 | 2014-04-09 17:43:41 -0700 | [diff] [blame] | 20 | protected SinglePacketOutNotification() { |
| 21 | address = 0; |
| 22 | outSwitch = 0; |
| 23 | outPort = 0; |
| 24 | } |
| 25 | |
Jonathan Hart | 7c9a2fb | 2014-03-27 09:51:41 -0700 | [diff] [blame] | 26 | /** |
| 27 | * Class constructor. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 28 | * |
| 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 Hart | 7c9a2fb | 2014-03-27 09:51:41 -0700 | [diff] [blame] | 31 | * @param outSwitch the dpid of the switch to send the packet on |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 32 | * @param outPort the port number of the port to send the packet out |
Jonathan Hart | 7c9a2fb | 2014-03-27 09:51:41 -0700 | [diff] [blame] | 33 | */ |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 34 | public SinglePacketOutNotification(byte[] packet, int address, |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 35 | long outSwitch, short outPort) { |
Jonathan Hart | 7c9a2fb | 2014-03-27 09:51:41 -0700 | [diff] [blame] | 36 | super(packet); |
Jonathan Hart | 7804bea | 2014-01-07 10:50:52 -0800 | [diff] [blame] | 37 | |
Jonathan Hart | 7c9a2fb | 2014-03-27 09:51:41 -0700 | [diff] [blame] | 38 | 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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 45 | * |
Jonathan Hart | 7c9a2fb | 2014-03-27 09:51:41 -0700 | [diff] [blame] | 46 | * @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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 54 | * |
Jonathan Hart | 7c9a2fb | 2014-03-27 09:51:41 -0700 | [diff] [blame] | 55 | * @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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 63 | * |
Jonathan Hart | 7c9a2fb | 2014-03-27 09:51:41 -0700 | [diff] [blame] | 64 | * @return the target IP address for ARP packets, or null if the packet is |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 65 | * not an ARP packet |
Jonathan Hart | 7c9a2fb | 2014-03-27 09:51:41 -0700 | [diff] [blame] | 66 | */ |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 67 | public int getTargetAddress() { |
Jonathan Hart | 7c9a2fb | 2014-03-27 09:51:41 -0700 | [diff] [blame] | 68 | return address; |
| 69 | } |
Jonathan Hart | e6e6373 | 2014-04-16 14:29:49 -0700 | [diff] [blame] | 70 | |
| 71 | @Override |
Jonathan Hart | f5bd258 | 2014-04-09 17:43:41 -0700 | [diff] [blame] | 72 | public Multimap<Long, Short> calculateOutPorts( |
Yuta HIGUCHI | d92b10c | 2014-08-25 09:30:28 -0700 | [diff] [blame] | 73 | Multimap<Long, Short> localPorts, MutableTopology mutableTopology) { |
Jonathan Hart | e6e6373 | 2014-04-16 14:29:49 -0700 | [diff] [blame] | 74 | Multimap<Long, Short> outPorts = HashMultimap.create(); |
| 75 | |
Jonathan Hart | f5bd258 | 2014-04-09 17:43:41 -0700 | [diff] [blame] | 76 | if (localPorts.containsEntry(outSwitch, outPort)) { |
Jonathan Hart | e6e6373 | 2014-04-16 14:29:49 -0700 | [diff] [blame] | 77 | outPorts.put(outSwitch, outPort); |
| 78 | } |
| 79 | |
| 80 | return outPorts; |
| 81 | } |
Jonathan Hart | 7804bea | 2014-01-07 10:50:52 -0800 | [diff] [blame] | 82 | } |