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