blob: 3e098ed6a727633f95bb551755357e5d1384a715 [file] [log] [blame]
Jonathan Hart313fdf02014-04-10 14:09:46 -07001package net.onrc.onos.core.packetservice;
Jonathan Hart7804bea2014-01-07 10:50:52 -08002
Jonathan Harte6e63732014-04-16 14:29:49 -07003import java.util.Map;
TeruU7feef8a2014-04-03 00:15:49 -07004
Jonathan Harte6e63732014-04-16 14:29:49 -07005import com.google.common.collect.HashMultimap;
6import com.google.common.collect.Multimap;
7
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -07008// TODO The generic broadcast packet shouldn't contain an IP address which is
9// only for ARP packets.
Ray Milkey269ffb92014-04-03 14:43:30 -070010
Jonathan Hart7804bea2014-01-07 10:50:52 -080011/**
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 Hart7804bea2014-01-07 10:50:52 -080016 */
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070017public class BroadcastPacketOutNotification extends PacketOutNotification {
Jonathan Hart7804bea2014-01-07 10:50:52 -080018
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070019 private static final long serialVersionUID = 1L;
Jonathan Hart7804bea2014-01-07 10:50:52 -080020
TeruU7feef8a2014-04-03 00:15:49 -070021 private final int address;
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070022 private final long inSwitch;
23 private final short inPort;
Jonathan Hart7804bea2014-01-07 10:50:52 -080024
TeruU7feef8a2014-04-03 00:15:49 -070025 protected BroadcastPacketOutNotification() {
Ray Milkey269ffb92014-04-03 14:43:30 -070026 super();
TeruU7feef8a2014-04-03 00:15:49 -070027 this.address = -1;
28 this.inSwitch = -1;
29 this.inPort = -1;
30 }
Ray Milkey269ffb92014-04-03 14:43:30 -070031
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070032 /**
33 * Class constructor.
34 *
Ray Milkey269ffb92014-04-03 14:43:30 -070035 * @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 Hart7c9a2fb2014-03-27 09:51:41 -070039 */
TeruU7feef8a2014-04-03 00:15:49 -070040 public BroadcastPacketOutNotification(byte[] packet, int address,
Ray Milkey269ffb92014-04-03 14:43:30 -070041 long inSwitch, short inPort) {
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070042 super(packet);
Jonathan Hart7804bea2014-01-07 10:50:52 -080043
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070044 this.address = address;
45 this.inSwitch = inSwitch;
46 this.inPort = inPort;
47 }
Ray Milkey269ffb92014-04-03 14:43:30 -070048
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070049 /**
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 Milkey269ffb92014-04-03 14:43:30 -070071 * not an ARP packet
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070072 */
TeruU7feef8a2014-04-03 00:15:49 -070073 public int getTargetAddress() {
Jonathan Hart7c9a2fb2014-03-27 09:51:41 -070074 return address;
75 }
Jonathan Harte6e63732014-04-16 14:29:49 -070076
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 Hart7804bea2014-01-07 10:50:52 -080090}