diff --git a/apps/mobility/src/main/java/org/onlab/onos/mobility/HostMobility.java b/apps/mobility/src/main/java/org/onlab/onos/mobility/HostMobility.java index cb60405c79..7958f993be 100644 --- a/apps/mobility/src/main/java/org/onlab/onos/mobility/HostMobility.java +++ b/apps/mobility/src/main/java/org/onlab/onos/mobility/HostMobility.java @@ -28,7 +28,7 @@ import com.google.common.collect.Lists; /** - * Sample reactive forwarding application. + * Sample mobility application. Cleans up flowmods when a host moves. */ @Component(immediate = true) public class HostMobility { @@ -82,6 +82,10 @@ public class HostMobility { } + /** + * For a given host, remove any flow rule which references it's addresses. + * @param host the host to clean up for + */ private void cleanup(Host host) { Iterable devices = deviceService.getDevices(); List flowRules = Lists.newLinkedList(); @@ -102,7 +106,6 @@ public class HostMobility { EthCriterion eth = (EthCriterion) c; if (eth.mac().equals(mac)) { flowRules.add(rule); - break; } } } diff --git a/providers/openflow/host/src/main/java/org/onlab/onos/provider/of/host/impl/OpenFlowHostProvider.java b/providers/openflow/host/src/main/java/org/onlab/onos/provider/of/host/impl/OpenFlowHostProvider.java index d124f2a983..4f5bb81eff 100644 --- a/providers/openflow/host/src/main/java/org/onlab/onos/provider/of/host/impl/OpenFlowHostProvider.java +++ b/providers/openflow/host/src/main/java/org/onlab/onos/provider/of/host/impl/OpenFlowHostProvider.java @@ -31,6 +31,7 @@ import org.onlab.onos.openflow.controller.OpenFlowPacketContext; import org.onlab.onos.openflow.controller.PacketListener; import org.onlab.packet.ARP; import org.onlab.packet.Ethernet; +import org.onlab.packet.IPv4; import org.onlab.packet.IpPrefix; import org.onlab.packet.VlanId; import org.slf4j.Logger; @@ -92,29 +93,37 @@ public class OpenFlowHostProvider extends AbstractProvider implements HostProvid public void handlePacket(OpenFlowPacketContext pktCtx) { Ethernet eth = pktCtx.parsed(); + VlanId vlan = VlanId.vlanId(eth.getVlanID()); + ConnectPoint heardOn = new ConnectPoint(deviceId(Dpid.uri(pktCtx.dpid())), + portNumber(pktCtx.inPort())); + + // If this is not an edge port, bail out. + Topology topology = topologyService.currentTopology(); + if (topologyService.isInfrastructure(topology, heardOn)) { + return; + } + + HostLocation hloc = new HostLocation(deviceId(Dpid.uri(pktCtx.dpid())), + portNumber(pktCtx.inPort()), + System.currentTimeMillis()); + HostId hid = HostId.hostId(eth.getSourceMAC(), vlan); // Potentially a new or moved host if (eth.getEtherType() == Ethernet.TYPE_ARP) { - VlanId vlan = VlanId.vlanId(eth.getVlanID()); - ConnectPoint heardOn = new ConnectPoint(deviceId(Dpid.uri(pktCtx.dpid())), - portNumber(pktCtx.inPort())); - // If this is not an edge port, bail out. - Topology topology = topologyService.currentTopology(); - if (topologyService.isInfrastructure(topology, heardOn)) { - return; - } - HostLocation hloc = new HostLocation(deviceId(Dpid.uri(pktCtx.dpid())), - portNumber(pktCtx.inPort()), - System.currentTimeMillis()); - - HostId hid = HostId.hostId(eth.getSourceMAC(), vlan); ARP arp = (ARP) eth.getPayload(); Set ips = newHashSet(IpPrefix.valueOf(arp.getSenderProtocolAddress())); HostDescription hdescr = new DefaultHostDescription(eth.getSourceMAC(), vlan, hloc, ips); providerService.hostDetected(hid, hdescr); + } else if (eth.getEtherType() == Ethernet.TYPE_IPV4) { + IPv4 ip = (IPv4) eth.getPayload(); + Set ips = newHashSet(IpPrefix.valueOf(ip.getSourceAddress())); + HostDescription hdescr = + new DefaultHostDescription(eth.getSourceMAC(), vlan, hloc, ips); + providerService.hostDetected(hid, hdescr); + } // TODO: Use DHCP packets as well later...