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