mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-10-25 14:21:33 +02:00
host provider detects hosts on ip as well
Change-Id: I76a1d51fb444a074c76a4b44818f02e7aa2944ef
This commit is contained in:
parent
02ca24eaeb
commit
0ff17adc97
@ -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<Device> devices = deviceService.getDevices();
|
||||
List<FlowRule> flowRules = Lists.newLinkedList();
|
||||
@ -102,7 +106,6 @@ public class HostMobility {
|
||||
EthCriterion eth = (EthCriterion) c;
|
||||
if (eth.mac().equals(mac)) {
|
||||
flowRules.add(rule);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<IpPrefix> 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<IpPrefix> 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...
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user