Jonathan Hart
Committed by Gerrit Code Review

Finish off a couple of things to get PIM to send HELLOs.

Also added packet request to PacketService to get punt flows installed in switches.

Change-Id: I7340d09a1cf2ec06fb33ac0c4fc14eb43e94f496
...@@ -37,10 +37,12 @@ import org.onosproject.net.flow.TrafficSelector; ...@@ -37,10 +37,12 @@ import org.onosproject.net.flow.TrafficSelector;
37 import org.onosproject.net.mcast.MulticastRouteService; 37 import org.onosproject.net.mcast.MulticastRouteService;
38 import org.onosproject.net.packet.InboundPacket; 38 import org.onosproject.net.packet.InboundPacket;
39 import org.onosproject.net.packet.PacketContext; 39 import org.onosproject.net.packet.PacketContext;
40 +import org.onosproject.net.packet.PacketPriority;
40 import org.onosproject.net.packet.PacketProcessor; 41 import org.onosproject.net.packet.PacketProcessor;
41 import org.onosproject.net.packet.PacketService; 42 import org.onosproject.net.packet.PacketService;
42 import org.slf4j.Logger; 43 import org.slf4j.Logger;
43 44
45 +import java.util.Optional;
44 import java.util.Set; 46 import java.util.Set;
45 47
46 import static org.slf4j.LoggerFactory.getLogger; 48 import static org.slf4j.LoggerFactory.getLogger;
...@@ -85,6 +87,8 @@ public class PIMApplication { ...@@ -85,6 +87,8 @@ public class PIMApplication {
85 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 87 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
86 protected PIMInterfaceService pimInterfaceManager; 88 protected PIMInterfaceService pimInterfaceManager;
87 89
90 + private final PIMPacketProcessor processor = new PIMPacketProcessor();
91 +
88 /** 92 /**
89 * Activate the PIM component. 93 * Activate the PIM component.
90 */ 94 */
...@@ -100,10 +104,11 @@ public class PIMApplication { ...@@ -100,10 +104,11 @@ public class PIMApplication {
100 selector.matchIPProtocol(IPv4.PROTOCOL_PIM); 104 selector.matchIPProtocol(IPv4.PROTOCOL_PIM);
101 105
102 // Use the traffic selector to tell the packet service which packets we want. 106 // Use the traffic selector to tell the packet service which packets we want.
103 - // PIMPacketService is an inner class defined below
104 - PIMPacketProcessor processor = new PIMPacketProcessor();
105 packetService.addProcessor(processor, PacketProcessor.director(5)); 107 packetService.addProcessor(processor, PacketProcessor.director(5));
106 108
109 + packetService.requestPackets(selector.build(), PacketPriority.CONTROL,
110 + appId, Optional.empty());
111 +
107 // Register for notifications from the Network config & Interface services. 112 // Register for notifications from the Network config & Interface services.
108 // We'll use these services to represent "PIMInterfaces" 113 // We'll use these services to represent "PIMInterfaces"
109 114
...@@ -121,6 +126,8 @@ public class PIMApplication { ...@@ -121,6 +126,8 @@ public class PIMApplication {
121 */ 126 */
122 @Deactivate 127 @Deactivate
123 public void deactivate() { 128 public void deactivate() {
129 + packetService.removeProcessor(processor);
130 +
124 log.info("Stopped"); 131 log.info("Stopped");
125 } 132 }
126 133
......
...@@ -24,9 +24,14 @@ import org.onlab.packet.PIM; ...@@ -24,9 +24,14 @@ import org.onlab.packet.PIM;
24 import org.onlab.packet.pim.PIMHello; 24 import org.onlab.packet.pim.PIMHello;
25 import org.onlab.packet.pim.PIMHelloOption; 25 import org.onlab.packet.pim.PIMHelloOption;
26 import org.onosproject.incubator.net.intf.Interface; 26 import org.onosproject.incubator.net.intf.Interface;
27 +import org.onosproject.net.flow.DefaultTrafficTreatment;
28 +import org.onosproject.net.flow.TrafficTreatment;
27 import org.onosproject.net.host.InterfaceIpAddress; 29 import org.onosproject.net.host.InterfaceIpAddress;
30 +import org.onosproject.net.packet.DefaultOutboundPacket;
31 +import org.onosproject.net.packet.PacketService;
28 import org.slf4j.Logger; 32 import org.slf4j.Logger;
29 33
34 +import java.nio.ByteBuffer;
30 import java.util.HashMap; 35 import java.util.HashMap;
31 import java.util.Map; 36 import java.util.Map;
32 import java.util.Set; 37 import java.util.Set;
...@@ -42,7 +47,10 @@ public class PIMInterface { ...@@ -42,7 +47,10 @@ public class PIMInterface {
42 47
43 private final Logger log = getLogger(getClass()); 48 private final Logger log = getLogger(getClass());
44 49
50 + private final PacketService packetService;
51 +
45 private Interface onosInterface; 52 private Interface onosInterface;
53 + private final TrafficTreatment outputTreatment;
46 54
47 // Our hello opt holdtime 55 // Our hello opt holdtime
48 private short holdtime = PIMHelloOption.DEFAULT_HOLDTIME; 56 private short holdtime = PIMHelloOption.DEFAULT_HOLDTIME;
...@@ -67,8 +75,10 @@ public class PIMInterface { ...@@ -67,8 +75,10 @@ public class PIMInterface {
67 * 75 *
68 * @param intf the ONOS Interface. 76 * @param intf the ONOS Interface.
69 */ 77 */
70 - public PIMInterface(Interface intf) { 78 + public PIMInterface(Interface intf, PacketService packetService) {
71 onosInterface = intf; 79 onosInterface = intf;
80 + outputTreatment = createOutputTreatment();
81 + this.packetService = packetService;
72 IpAddress ourIp = getIpAddress(); 82 IpAddress ourIp = getIpAddress();
73 MacAddress mac = intf.mac(); 83 MacAddress mac = intf.mac();
74 84
...@@ -82,6 +92,12 @@ public class PIMInterface { ...@@ -82,6 +92,12 @@ public class PIMInterface {
82 drIpaddress = ourIp; 92 drIpaddress = ourIp;
83 } 93 }
84 94
95 + private TrafficTreatment createOutputTreatment() {
96 + return DefaultTrafficTreatment.builder()
97 + .setOutput(onosInterface.connectPoint().port())
98 + .build();
99 + }
100 +
85 /** 101 /**
86 * Return the ONOS Interface. 102 * Return the ONOS Interface.
87 * 103 *
...@@ -187,7 +203,10 @@ public class PIMInterface { ...@@ -187,7 +203,10 @@ public class PIMInterface {
187 // Now set the hello option payload 203 // Now set the hello option payload
188 pimPacket.setPIMPayload(hello); 204 pimPacket.setPIMPayload(hello);
189 205
190 - // TODO: How to send the packet.?. 206 + packetService.emit(new DefaultOutboundPacket(
207 + onosInterface.connectPoint().deviceId(),
208 + outputTreatment,
209 + ByteBuffer.wrap(pimPacket.getEthernet().serialize())));
191 } 210 }
192 211
193 /** 212 /**
......
...@@ -25,6 +25,7 @@ import org.apache.felix.scr.annotations.Service; ...@@ -25,6 +25,7 @@ import org.apache.felix.scr.annotations.Service;
25 import org.onosproject.incubator.net.intf.Interface; 25 import org.onosproject.incubator.net.intf.Interface;
26 import org.onosproject.incubator.net.intf.InterfaceService; 26 import org.onosproject.incubator.net.intf.InterfaceService;
27 import org.onosproject.net.ConnectPoint; 27 import org.onosproject.net.ConnectPoint;
28 +import org.onosproject.net.packet.PacketService;
28 import org.onosproject.net.provider.ProviderId; 29 import org.onosproject.net.provider.ProviderId;
29 import org.slf4j.Logger; 30 import org.slf4j.Logger;
30 import java.util.Map; 31 import java.util.Map;
...@@ -62,6 +63,9 @@ public class PIMInterfaceManager implements PIMInterfaceService { ...@@ -62,6 +63,9 @@ public class PIMInterfaceManager implements PIMInterfaceService {
62 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 63 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
63 protected InterfaceService interfaceService; 64 protected InterfaceService interfaceService;
64 65
66 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
67 + protected PacketService packetService;
68 +
65 // Store PIM Interfaces in a map key'd by ConnectPoint 69 // Store PIM Interfaces in a map key'd by ConnectPoint
66 private final Map<ConnectPoint, PIMInterface> pimInterfaces = Maps.newConcurrentMap(); 70 private final Map<ConnectPoint, PIMInterface> pimInterfaces = Maps.newConcurrentMap();
67 71
...@@ -72,7 +76,7 @@ public class PIMInterfaceManager implements PIMInterfaceService { ...@@ -72,7 +76,7 @@ public class PIMInterfaceManager implements PIMInterfaceService {
72 76
73 // Create PIM Interfaces for each of the existing ONOS Interfaces. 77 // Create PIM Interfaces for each of the existing ONOS Interfaces.
74 for (Interface intf : interfaceService.getInterfaces()) { 78 for (Interface intf : interfaceService.getInterfaces()) {
75 - pimInterfaces.put(intf.connectPoint(), new PIMInterface(intf)); 79 + pimInterfaces.put(intf.connectPoint(), new PIMInterface(intf, packetService));
76 } 80 }
77 81
78 // Schedule the periodic hello sender. 82 // Schedule the periodic hello sender.
...@@ -107,7 +111,7 @@ public class PIMInterfaceManager implements PIMInterfaceService { ...@@ -107,7 +111,7 @@ public class PIMInterfaceManager implements PIMInterfaceService {
107 111
108 log.debug("Updating Interface for " + intf.connectPoint().toString()); 112 log.debug("Updating Interface for " + intf.connectPoint().toString());
109 pimInterfaces.compute(cp, (k, v) -> (v == null) ? 113 pimInterfaces.compute(cp, (k, v) -> (v == null) ?
110 - new PIMInterface(intf) : 114 + new PIMInterface(intf, packetService) :
111 v.setInterface(intf)); 115 v.setInterface(intf));
112 } 116 }
113 117
......