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 | e6e6373 | 2014-04-16 14:29:49 -0700 | [diff] [blame^] | 3 | import java.util.Map; |
TeruU | 7feef8a | 2014-04-03 00:15:49 -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; |
| 7 | |
Jonathan Hart | 7c9a2fb | 2014-03-27 09:51:41 -0700 | [diff] [blame] | 8 | // TODO The generic broadcast packet shouldn't contain an IP address which is |
| 9 | // only for ARP packets. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 10 | |
Jonathan Hart | 7804bea | 2014-01-07 10:50:52 -0800 | [diff] [blame] | 11 | /** |
| 12 | * Notification to all ONOS instances to broadcast this packet out the edge of |
| 13 | * the network. The edge is defined as any port that doesn't have a link to |
| 14 | * another switch. The one exception is the port that the packet was received |
| 15 | * on. |
Jonathan Hart | 7804bea | 2014-01-07 10:50:52 -0800 | [diff] [blame] | 16 | */ |
Jonathan Hart | 7c9a2fb | 2014-03-27 09:51:41 -0700 | [diff] [blame] | 17 | public class BroadcastPacketOutNotification extends PacketOutNotification { |
Jonathan Hart | 7804bea | 2014-01-07 10:50:52 -0800 | [diff] [blame] | 18 | |
Jonathan Hart | 7c9a2fb | 2014-03-27 09:51:41 -0700 | [diff] [blame] | 19 | private static final long serialVersionUID = 1L; |
Jonathan Hart | 7804bea | 2014-01-07 10:50:52 -0800 | [diff] [blame] | 20 | |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 21 | private final int address; |
Jonathan Hart | 7c9a2fb | 2014-03-27 09:51:41 -0700 | [diff] [blame] | 22 | private final long inSwitch; |
| 23 | private final short inPort; |
Jonathan Hart | 7804bea | 2014-01-07 10:50:52 -0800 | [diff] [blame] | 24 | |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 25 | protected BroadcastPacketOutNotification() { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 26 | super(); |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 27 | this.address = -1; |
| 28 | this.inSwitch = -1; |
| 29 | this.inPort = -1; |
| 30 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 31 | |
Jonathan Hart | 7c9a2fb | 2014-03-27 09:51:41 -0700 | [diff] [blame] | 32 | /** |
| 33 | * Class constructor. |
| 34 | * |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 35 | * @param packet packet data to send in the packet-out |
| 36 | * @param address target IP address if the packet is an ARP packet |
| 37 | * @param inSwitch dpid of the switch the packet was received on |
| 38 | * @param inPort port number of the receiving port |
Jonathan Hart | 7c9a2fb | 2014-03-27 09:51:41 -0700 | [diff] [blame] | 39 | */ |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 40 | public BroadcastPacketOutNotification(byte[] packet, int address, |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 41 | long inSwitch, short inPort) { |
Jonathan Hart | 7c9a2fb | 2014-03-27 09:51:41 -0700 | [diff] [blame] | 42 | super(packet); |
Jonathan Hart | 7804bea | 2014-01-07 10:50:52 -0800 | [diff] [blame] | 43 | |
Jonathan Hart | 7c9a2fb | 2014-03-27 09:51:41 -0700 | [diff] [blame] | 44 | this.address = address; |
| 45 | this.inSwitch = inSwitch; |
| 46 | this.inPort = inPort; |
| 47 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 48 | |
Jonathan Hart | 7c9a2fb | 2014-03-27 09:51:41 -0700 | [diff] [blame] | 49 | /** |
| 50 | * Get the dpid of the switch the packet was received on. |
| 51 | * |
| 52 | * @return receiving switch dpid |
| 53 | */ |
| 54 | public long getInSwitch() { |
| 55 | return inSwitch; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Get the port number of the port the packet was received on. |
| 60 | * |
| 61 | * @return receiving port number |
| 62 | */ |
| 63 | public short getInPort() { |
| 64 | return inPort; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Get the target IP address if the packet is an ARP packet. |
| 69 | * |
| 70 | * @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] | 71 | * not an ARP packet |
Jonathan Hart | 7c9a2fb | 2014-03-27 09:51:41 -0700 | [diff] [blame] | 72 | */ |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 73 | public int getTargetAddress() { |
Jonathan Hart | 7c9a2fb | 2014-03-27 09:51:41 -0700 | [diff] [blame] | 74 | return address; |
| 75 | } |
Jonathan Hart | e6e6373 | 2014-04-16 14:29:49 -0700 | [diff] [blame^] | 76 | |
| 77 | @Override |
| 78 | public Multimap<Long, Short> calculateOutPorts(Multimap<Long, Short> localSwitches) { |
| 79 | Multimap<Long, Short> outPorts = HashMultimap.create(); |
| 80 | |
| 81 | for (Map.Entry<Long, Short> entry : localSwitches.entries()) { |
| 82 | if (!entry.getKey().equals(inSwitch) || |
| 83 | !entry.getValue().equals(inPort)) { |
| 84 | outPorts.put(entry.getKey(), entry.getValue()); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | return outPorts; |
| 89 | } |
Jonathan Hart | 7804bea | 2014-01-07 10:50:52 -0800 | [diff] [blame] | 90 | } |