Aaron Kruglikov
Committed by Gerrit Code Review

Include logic for cancelling requests for packets.

Change-Id: I8244b8e417dd2b4c6feae57b810fe750635e87a7
......@@ -54,7 +54,6 @@ import org.onosproject.net.packet.DefaultOutboundPacket;
import org.onosproject.net.packet.InboundPacket;
import org.onosproject.net.packet.OutboundPacket;
import org.onosproject.net.packet.PacketContext;
import org.onosproject.net.packet.PacketPriority;
import org.onosproject.net.packet.PacketProcessor;
import org.onosproject.net.packet.PacketService;
import org.onosproject.xosintegration.VoltTenantService;
......@@ -71,6 +70,7 @@ import java.util.Map;
import java.util.Optional;
import java.util.Set;
import static org.onosproject.net.packet.PacketPriority.CONTROL;
import static org.slf4j.LoggerFactory.getLogger;
......@@ -117,7 +117,7 @@ public class AAA {
// RADIUS server shared secret
private static final String DEFAULT_RADIUS_SECRET = "ONOSecret";
// RADIUS MAC address
private static final String RADIUS_MAC_ADDRESS = "00:00:00:00:01:10";
private static final String RADIUS_MAC_ADDRESS = "00:00:00:00:01:10";
// NAS MAC address
private static final String NAS_MAC_ADDRESS = "00:00:00:00:10:01";
// Radius Switch Id
......@@ -130,7 +130,7 @@ public class AAA {
private String radiusIpAddress = DEFAULT_RADIUS_IP;
@Property(name = "nasIpAddress", value = DEFAULT_NAS_IP,
label = "NAP IP Address")
label = "NAS IP Address")
private String nasIpAddress = DEFAULT_NAS_IP;
@Property(name = "radiusMacAddress", value = RADIUS_MAC_ADDRESS,
......@@ -138,7 +138,7 @@ public class AAA {
private String radiusMacAddress = RADIUS_MAC_ADDRESS;
@Property(name = "nasMacAddress", value = NAS_MAC_ADDRESS,
label = "NAP MAC Address")
label = "NAS MAC Address")
private String nasMacAddress = NAS_MAC_ADDRESS;
@Property(name = "radiusSecret", value = DEFAULT_RADIUS_SECRET,
......@@ -205,12 +205,7 @@ public class AAA {
appId = coreService.registerApplication("org.onosproject.aaa");
// register our event handler
packetService.addProcessor(processor, PacketProcessor.ADVISOR_MAX + 2);
TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
selector.matchEthType(EthType.EtherType.EAPOL.ethType().toShort());
packetService.requestPackets(selector.build(),
PacketPriority.CONTROL, appId);
requestIntercepts();
// Instantiate the map of the state machines
stateMachineMap = Collections.synchronizedMap(Maps.newHashMap());
......@@ -221,22 +216,45 @@ public class AAA {
@Deactivate
public void deactivate() {
cfgService.unregisterProperties(getClass(), false);
appId = coreService.registerApplication("org.onosproject.aaa");
withdrawIntercepts();
// de-register and null our handler
packetService.removeProcessor(processor);
processor = null;
}
/**
* Request packet in via PacketService.
*/
private void requestIntercepts() {
TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
selector.matchEthType(EthType.EtherType.EAPOL.ethType().toShort());
packetService.requestPackets(selector.build(),
CONTROL, appId);
}
/**
* Cancel request for packet in via PacketService.
*/
private void withdrawIntercepts() {
TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
selector.matchEthType(EthType.EtherType.EAPOL.ethType().toShort());
packetService.cancelPackets(selector.build(), CONTROL, appId);
}
/**
* Builds an EAPOL packet based on the given parameters.
*
* @param dstMac destination MAC address
* @param srcMac source MAC address
* @param dstMac destination MAC address
* @param srcMac source MAC address
* @param vlan vlan identifier
* @param eapolType EAPOL type
* @param eap EAP payload
* @param eap EAP payload
* @return Ethernet frame
*/
private static Ethernet buildEapolResponse(MacAddress dstMac, MacAddress srcMac,
short vlan, byte eapolType, EAP eap) {
short vlan, byte eapolType, EAP eap) {
Ethernet eth = new Ethernet();
eth.setDestinationMACAddress(dstMac.toBytes());
......@@ -328,9 +346,9 @@ public class AAA {
//send an EAP Request/Identify to the supplicant
EAP eapPayload = new EAP(EAP.REQUEST, stateMachine.getIdentifier(), EAP.ATTR_IDENTITY, null);
Ethernet eth = buildEapolResponse(srcMAC, MacAddress.valueOf(1L),
ethPkt.getVlanID(), EAPOL.EAPOL_PACKET,
eapPayload);
Ethernet eth = buildEapolResponse(srcMAC, MacAddress.valueOf(1L),
ethPkt.getVlanID(), EAPOL.EAPOL_PACKET,
eapPayload);
stateMachine.supplicantAddress = srcMAC;
stateMachine.vlanId = ethPkt.getVlanID();
......@@ -350,13 +368,13 @@ public class AAA {
try {
//request id access to RADIUS
RADIUS radiusPayload = new RADIUS(RADIUS.RADIUS_CODE_ACCESS_REQUEST,
eapPacket.getIdentifier());
eapPacket.getIdentifier());
radiusPayload.setIdentifier(stateMachine.getIdentifier());
radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_USERNAME,
eapPacket.getData());
eapPacket.getData());
stateMachine.setUsername(eapPacket.getData());
radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_NAS_IP,
AAA.this.parsedNasIpAddress.getAddress());
AAA.this.parsedNasIpAddress.getAddress());
radiusPayload.encapsulateMessage(eapPacket);
......@@ -377,17 +395,17 @@ public class AAA {
if (eapPacket.getIdentifier() == stateMachine.getChallengeIdentifier()) {
//send the RADIUS challenge response
RADIUS radiusPayload = new RADIUS(RADIUS.RADIUS_CODE_ACCESS_REQUEST,
eapPacket.getIdentifier());
eapPacket.getIdentifier());
radiusPayload.setIdentifier(stateMachine.getChallengeIdentifier());
radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_USERNAME,
stateMachine.getUsername());
stateMachine.getUsername());
radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_NAS_IP,
AAA.this.parsedNasIpAddress.getAddress());
AAA.this.parsedNasIpAddress.getAddress());
radiusPayload.encapsulateMessage(eapPacket);
radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_STATE,
stateMachine.getChallengeState());
stateMachine.getChallengeState());
radiusPayload.addMessageAuthenticator(AAA.this.radiusSecret);
sendRadiusMessage(radiusPayload);
}
......@@ -396,17 +414,17 @@ public class AAA {
try {
//request id access to RADIUS
RADIUS radiusPayload = new RADIUS(RADIUS.RADIUS_CODE_ACCESS_REQUEST,
eapPacket.getIdentifier());
eapPacket.getIdentifier());
radiusPayload.setIdentifier(stateMachine.getIdentifier());
radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_USERNAME,
stateMachine.getUsername());
stateMachine.getUsername());
radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_NAS_IP,
AAA.this.parsedNasIpAddress.getAddress());
AAA.this.parsedNasIpAddress.getAddress());
radiusPayload.encapsulateMessage(eapPacket);
radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_STATE,
stateMachine.getChallengeState());
stateMachine.getChallengeState());
stateMachine.setRequestAuthenticator(radiusPayload.generateAuthCode());
radiusPayload.addMessageAuthenticator(AAA.this.radiusSecret);
......@@ -447,7 +465,8 @@ public class AAA {
eapPayload = radiusPacket.decapsulateMessage();
stateMachine.setChallengeInfo(eapPayload.getIdentifier(), challengeState);
eth = buildEapolResponse(stateMachine.supplicantAddress,
MacAddress.valueOf(1L), stateMachine.vlanId, EAPOL.EAPOL_PACKET, eapPayload);
MacAddress.valueOf(1L), stateMachine.vlanId, EAPOL.EAPOL_PACKET,
eapPayload);
this.sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint);
break;
case RADIUS.RADIUS_CODE_ACCESS_ACCEPT:
......@@ -458,7 +477,8 @@ public class AAA {
eapPayload = new EAP();
eapPayload = (EAP) eapPayload.deserialize(eapMessage, 0, eapMessage.length);
eth = buildEapolResponse(stateMachine.supplicantAddress,
MacAddress.valueOf(1L), stateMachine.vlanId, EAPOL.EAPOL_PACKET, eapPayload);
MacAddress.valueOf(1L), stateMachine.vlanId, EAPOL.EAPOL_PACKET,
eapPayload);
this.sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint);
stateMachine.authorizeAccess();
......@@ -556,7 +576,7 @@ public class AAA {
TrafficTreatment treatment = DefaultTrafficTreatment.builder()
.setOutput(PortNumber.portNumber(Integer.parseInt(radiusPort))).build();
OutboundPacket packet = new DefaultOutboundPacket(DeviceId.deviceId(radiusSwitch),
treatment, ByteBuffer.wrap(ethPkt.serialize()));
treatment, ByteBuffer.wrap(ethPkt.serialize()));
packetService.emit(packet);
}
......@@ -564,13 +584,13 @@ public class AAA {
/**
* Send the ethernet packet to the supplicant.
*
* @param ethernetPkt the ethernet packet
* @param ethernetPkt the ethernet packet
* @param connectPoint the connect point to send out
*/
private void sendPacketToSupplicant(Ethernet ethernetPkt, ConnectPoint connectPoint) {
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(connectPoint.port()).build();
OutboundPacket packet = new DefaultOutboundPacket(connectPoint.deviceId(),
treatment, ByteBuffer.wrap(ethernetPkt.serialize()));
treatment, ByteBuffer.wrap(ethernetPkt.serialize()));
packetService.emit(packet);
}
......
......@@ -203,7 +203,7 @@ public class ReactiveForwarding {
}
/**
* Request packet in via PacketService.
* Cancel request for packet in via PacketService.
*/
private void withdrawIntercepts() {
TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
......
......@@ -23,8 +23,6 @@ import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onlab.packet.Ethernet;
import org.onlab.packet.ICMP6;
import org.onlab.packet.IPv6;
import org.onosproject.cfg.ComponentConfigService;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
......@@ -32,7 +30,6 @@ import org.onosproject.net.flow.DefaultTrafficSelector;
import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.packet.InboundPacket;
import org.onosproject.net.packet.PacketContext;
import org.onosproject.net.packet.PacketPriority;
import org.onosproject.net.packet.PacketProcessor;
import org.onosproject.net.packet.PacketService;
import org.onosproject.net.proxyarp.ProxyArpService;
......@@ -42,6 +39,12 @@ import org.slf4j.Logger;
import java.util.Dictionary;
import static com.google.common.base.Strings.isNullOrEmpty;
import static org.onlab.packet.Ethernet.TYPE_ARP;
import static org.onlab.packet.Ethernet.TYPE_IPV6;
import static org.onlab.packet.ICMP6.NEIGHBOR_ADVERTISEMENT;
import static org.onlab.packet.ICMP6.NEIGHBOR_SOLICITATION;
import static org.onlab.packet.IPv6.PROTOCOL_ICMP6;
import static org.onosproject.net.packet.PacketPriority.CONTROL;
import static org.slf4j.LoggerFactory.getLogger;
/**
......@@ -86,8 +89,8 @@ public class ProxyArp {
@Deactivate
public void deactivate() {
// TODO revoke all packet requests when deactivate
cfgService.unregisterProperties(getClass(), false);
withdrawIntercepts();
packetService.removeProcessor(processor);
processor = null;
log.info("Stopped");
......@@ -95,7 +98,6 @@ public class ProxyArp {
@Modified
public void modified(ComponentContext context) {
// TODO revoke unnecessary packet requests when config being modified
readComponentConfiguration(context);
requestPackests();
}
......@@ -106,27 +108,58 @@ public class ProxyArp {
private void requestPackests() {
TrafficSelector.Builder selectorBuilder =
DefaultTrafficSelector.builder();
selectorBuilder.matchEthType(Ethernet.TYPE_ARP);
selectorBuilder.matchEthType(TYPE_ARP);
packetService.requestPackets(selectorBuilder.build(),
PacketPriority.CONTROL, appId);
CONTROL, appId);
selectorBuilder = DefaultTrafficSelector.builder();
selectorBuilder.matchEthType(TYPE_IPV6);
selectorBuilder.matchIPProtocol(PROTOCOL_ICMP6);
selectorBuilder.matchIcmpv6Type(NEIGHBOR_SOLICITATION);
if (ipv6NeighborDiscovery) {
// IPv6 Neighbor Solicitation packet.
selectorBuilder = DefaultTrafficSelector.builder();
selectorBuilder.matchEthType(Ethernet.TYPE_IPV6);
selectorBuilder.matchIPProtocol(IPv6.PROTOCOL_ICMP6);
selectorBuilder.matchIcmpv6Type(ICMP6.NEIGHBOR_SOLICITATION);
packetService.requestPackets(selectorBuilder.build(),
PacketPriority.CONTROL, appId);
CONTROL, appId);
} else {
packetService.cancelPackets(selectorBuilder.build(),
CONTROL, appId);
}
// IPv6 Neighbor Advertisement packet.
selectorBuilder = DefaultTrafficSelector.builder();
selectorBuilder.matchEthType(Ethernet.TYPE_IPV6);
selectorBuilder.matchIPProtocol(IPv6.PROTOCOL_ICMP6);
selectorBuilder.matchIcmpv6Type(ICMP6.NEIGHBOR_ADVERTISEMENT);
// IPv6 Neighbor Advertisement packet.
selectorBuilder = DefaultTrafficSelector.builder();
selectorBuilder.matchEthType(TYPE_IPV6);
selectorBuilder.matchIPProtocol(PROTOCOL_ICMP6);
selectorBuilder.matchIcmpv6Type(NEIGHBOR_ADVERTISEMENT);
if (ipv6NeighborDiscovery) {
packetService.requestPackets(selectorBuilder.build(),
PacketPriority.CONTROL, appId);
CONTROL, appId);
} else {
packetService.cancelPackets(selectorBuilder.build(),
CONTROL, appId);
}
}
/**
* Cancel requested packet in via packet service.
*/
private void withdrawIntercepts() {
TrafficSelector.Builder selectorBuilder =
DefaultTrafficSelector.builder();
selectorBuilder.matchEthType(TYPE_ARP);
packetService.cancelPackets(selectorBuilder.build(), CONTROL, appId);
selectorBuilder = DefaultTrafficSelector.builder();
selectorBuilder.matchEthType(TYPE_IPV6);
selectorBuilder.matchIPProtocol(PROTOCOL_ICMP6);
selectorBuilder.matchIcmpv6Type(NEIGHBOR_SOLICITATION);
packetService.cancelPackets(selectorBuilder.build(), CONTROL, appId);
selectorBuilder = DefaultTrafficSelector.builder();
selectorBuilder.matchEthType(TYPE_IPV6);
selectorBuilder.matchIPProtocol(PROTOCOL_ICMP6);
selectorBuilder.matchIcmpv6Type(NEIGHBOR_ADVERTISEMENT);
packetService.cancelPackets(selectorBuilder.build(), CONTROL, appId);
}
/**
......@@ -187,7 +220,7 @@ public class ProxyArp {
if (ethPkt == null) {
return;
}
if (!ipv6NeighborDiscovery && (ethPkt.getEtherType() == Ethernet.TYPE_IPV6)) {
if (!ipv6NeighborDiscovery && (ethPkt.getEtherType() == TYPE_IPV6)) {
return;
}
//handle the arp packet.
......
......@@ -14,6 +14,7 @@
* limitations under the License.
*/
package org.onosproject.reactive.routing;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
......@@ -37,7 +38,6 @@ import org.onosproject.net.packet.DefaultOutboundPacket;
import org.onosproject.net.packet.InboundPacket;
import org.onosproject.net.packet.OutboundPacket;
import org.onosproject.net.packet.PacketContext;
import org.onosproject.net.packet.PacketPriority;
import org.onosproject.net.packet.PacketProcessor;
import org.onosproject.net.packet.PacketService;
import org.onosproject.routing.RoutingService;
......@@ -46,6 +46,9 @@ import org.slf4j.Logger;
import java.nio.ByteBuffer;
import static org.onlab.packet.Ethernet.TYPE_ARP;
import static org.onlab.packet.Ethernet.TYPE_IPV4;
import static org.onosproject.net.packet.PacketPriority.REACTIVE;
import static org.slf4j.LoggerFactory.getLogger;
/**
......@@ -83,26 +86,46 @@ public class SdnIpReactiveRouting {
appId = coreService.registerApplication(APP_NAME);
packetService.addProcessor(processor,
PacketProcessor.ADVISOR_MAX + 2);
TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
// TODO: to support IPv6 later
selector.matchEthType(Ethernet.TYPE_IPV4);
packetService.requestPackets(selector.build(),
PacketPriority.REACTIVE, appId);
selector.matchEthType(Ethernet.TYPE_ARP);
packetService.requestPackets(selector.build(),
PacketPriority.REACTIVE, appId);
requestIntercepts();
log.info("SDN-IP Reactive Routing Started");
}
@Deactivate
public void deactivate() {
withdrawIntercepts();
packetService.removeProcessor(processor);
processor = null;
log.info("SDN-IP Reactive Routing Stopped");
}
/**
* Request packet in via the PacketService.
*/
private void requestIntercepts() {
//TODO: to support IPv6 later
TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
selector.matchEthType(TYPE_IPV4);
packetService.requestPackets(selector.build(),
REACTIVE, appId);
selector.matchEthType(TYPE_ARP);
packetService.requestPackets(selector.build(),
REACTIVE, appId);
}
/**
* Cancel request for packet in via PacketService.
*/
private void withdrawIntercepts() {
TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
selector.matchEthType(TYPE_IPV4);
packetService.requestPackets(selector.build(),
REACTIVE, appId);
selector = DefaultTrafficSelector.builder();
selector.matchEthType(TYPE_ARP);
packetService.requestPackets(selector.build(),
REACTIVE, appId);
}
private class ReactiveRoutingProcessor implements PacketProcessor {
@Override
public void process(PacketContext context) {
......@@ -169,9 +192,9 @@ public class SdnIpReactiveRouting {
/**
* Emits the specified packet onto the network.
*
* @param context the packet context
* @param context the packet context
* @param connectPoint the connect point where the packet should be
* sent out
* sent out
*/
private void forwardPacketToDst(PacketContext context,
ConnectPoint connectPoint) {
......
......@@ -81,24 +81,41 @@ public class VirtualPublicHosts {
packetService.addProcessor(processor,
PacketProcessor.ADVISOR_MAX + 6);
TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
// Only IPv4 is supported in current vBNG.
selector.matchEthType(Ethernet.TYPE_ARP);
packetService.requestPackets(selector.build(),
PacketPriority.REACTIVE, appId);
requestIntercepts();
log.info("vBNG virtual public hosts started");
}
@Deactivate
public void deactivate() {
withdrawIntercepts();
packetService.removeProcessor(processor);
processor = null;
log.info("vBNG virtual public hosts Stopped");
}
/**
* Request packet in via PacketService.
*/
private void requestIntercepts() {
TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
// Only IPv4 is supported in current vBNG.
selector.matchEthType(Ethernet.TYPE_ARP);
packetService.requestPackets(selector.build(),
PacketPriority.REACTIVE, appId);
}
/**
* Cancel request for packet in via PacketService.
*/
private void withdrawIntercepts() {
TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
// Only IPv4 is supported in current vBNG.
selector.matchEthType(Ethernet.TYPE_ARP);
packetService.cancelPackets(selector.build(),
PacketPriority.REACTIVE, appId);
}
/**
* This class filters out the ARP request packets, generates the ARP
* reply packets, and emits those packets.
*/
......
......@@ -190,7 +190,7 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid
private void withdrawIntercepts() {
TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
selector.matchEthType(Ethernet.TYPE_ARP);
packetService.requestPackets(selector.build(), PacketPriority.CONTROL, appId);
packetService.cancelPackets(selector.build(), PacketPriority.CONTROL, appId);
// IPv6 Neighbor Solicitation packet.
selector.matchEthType(Ethernet.TYPE_IPV6);
......
......@@ -145,7 +145,7 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider {
// to load configuration at startup
modified(context);
if (disableLinkDiscovery) {
log.info("Link Discovery has been permanently disabled by configuration");
log.info("LinkDiscovery has been permanently disabled by configuration");
return;
}
......