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 | |
Jonathan Hart | f5bd258 | 2014-04-09 17:43:41 -0700 | [diff] [blame] | 3 | import net.onrc.onos.core.topology.NetworkGraph; |
| 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 | |
Jonathan Hart | 7c9a2fb | 2014-03-27 09:51:41 -0700 | [diff] [blame] | 13 | private static final long serialVersionUID = 1L; |
Jonathan Hart | 7804bea | 2014-01-07 10:50:52 -0800 | [diff] [blame] | 14 | |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 15 | private final int address; |
Jonathan Hart | 7c9a2fb | 2014-03-27 09:51:41 -0700 | [diff] [blame] | 16 | private final long outSwitch; |
| 17 | private final short outPort; |
Jonathan Hart | 7804bea | 2014-01-07 10:50:52 -0800 | [diff] [blame] | 18 | |
Jonathan Hart | f5bd258 | 2014-04-09 17:43:41 -0700 | [diff] [blame] | 19 | protected SinglePacketOutNotification() { |
| 20 | address = 0; |
| 21 | outSwitch = 0; |
| 22 | outPort = 0; |
| 23 | } |
| 24 | |
Jonathan Hart | 7c9a2fb | 2014-03-27 09:51:41 -0700 | [diff] [blame] | 25 | /** |
| 26 | * Class constructor. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 27 | * |
| 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 Hart | 7c9a2fb | 2014-03-27 09:51:41 -0700 | [diff] [blame] | 30 | * @param outSwitch the dpid of the switch to send the packet on |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 31 | * @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] | 32 | */ |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 33 | public SinglePacketOutNotification(byte[] packet, int address, |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 34 | long outSwitch, short outPort) { |
Jonathan Hart | 7c9a2fb | 2014-03-27 09:51:41 -0700 | [diff] [blame] | 35 | super(packet); |
Jonathan Hart | 7804bea | 2014-01-07 10:50:52 -0800 | [diff] [blame] | 36 | |
Jonathan Hart | 7c9a2fb | 2014-03-27 09:51:41 -0700 | [diff] [blame] | 37 | 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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 44 | * |
Jonathan Hart | 7c9a2fb | 2014-03-27 09:51:41 -0700 | [diff] [blame] | 45 | * @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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 53 | * |
Jonathan Hart | 7c9a2fb | 2014-03-27 09:51:41 -0700 | [diff] [blame] | 54 | * @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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 62 | * |
Jonathan Hart | 7c9a2fb | 2014-03-27 09:51:41 -0700 | [diff] [blame] | 63 | * @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] | 64 | * not an ARP packet |
Jonathan Hart | 7c9a2fb | 2014-03-27 09:51:41 -0700 | [diff] [blame] | 65 | */ |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 66 | public int getTargetAddress() { |
Jonathan Hart | 7c9a2fb | 2014-03-27 09:51:41 -0700 | [diff] [blame] | 67 | return address; |
| 68 | } |
Jonathan Hart | e6e6373 | 2014-04-16 14:29:49 -0700 | [diff] [blame] | 69 | |
| 70 | @Override |
Jonathan Hart | f5bd258 | 2014-04-09 17:43:41 -0700 | [diff] [blame] | 71 | public Multimap<Long, Short> calculateOutPorts( |
| 72 | Multimap<Long, Short> localPorts, NetworkGraph networkGraph) { |
Jonathan Hart | e6e6373 | 2014-04-16 14:29:49 -0700 | [diff] [blame] | 73 | Multimap<Long, Short> outPorts = HashMultimap.create(); |
| 74 | |
Jonathan Hart | f5bd258 | 2014-04-09 17:43:41 -0700 | [diff] [blame] | 75 | if (localPorts.containsEntry(outSwitch, outPort)) { |
Jonathan Hart | e6e6373 | 2014-04-16 14:29:49 -0700 | [diff] [blame] | 76 | outPorts.put(outSwitch, outPort); |
| 77 | } |
| 78 | |
| 79 | return outPorts; |
| 80 | } |
Jonathan Hart | 7804bea | 2014-01-07 10:50:52 -0800 | [diff] [blame] | 81 | } |