host provider detects hosts on ip as well
Change-Id: I76a1d51fb444a074c76a4b44818f02e7aa2944ef
Showing
2 changed files
with
17 additions
and
5 deletions
... | @@ -28,7 +28,7 @@ import com.google.common.collect.Lists; | ... | @@ -28,7 +28,7 @@ import com.google.common.collect.Lists; |
28 | 28 | ||
29 | 29 | ||
30 | /** | 30 | /** |
31 | - * Sample reactive forwarding application. | 31 | + * Sample mobility application. Cleans up flowmods when a host moves. |
32 | */ | 32 | */ |
33 | @Component(immediate = true) | 33 | @Component(immediate = true) |
34 | public class HostMobility { | 34 | public class HostMobility { |
... | @@ -82,6 +82,10 @@ public class HostMobility { | ... | @@ -82,6 +82,10 @@ public class HostMobility { |
82 | 82 | ||
83 | } | 83 | } |
84 | 84 | ||
85 | + /** | ||
86 | + * For a given host, remove any flow rule which references it's addresses. | ||
87 | + * @param host the host to clean up for | ||
88 | + */ | ||
85 | private void cleanup(Host host) { | 89 | private void cleanup(Host host) { |
86 | Iterable<Device> devices = deviceService.getDevices(); | 90 | Iterable<Device> devices = deviceService.getDevices(); |
87 | List<FlowRule> flowRules = Lists.newLinkedList(); | 91 | List<FlowRule> flowRules = Lists.newLinkedList(); |
... | @@ -102,7 +106,6 @@ public class HostMobility { | ... | @@ -102,7 +106,6 @@ public class HostMobility { |
102 | EthCriterion eth = (EthCriterion) c; | 106 | EthCriterion eth = (EthCriterion) c; |
103 | if (eth.mac().equals(mac)) { | 107 | if (eth.mac().equals(mac)) { |
104 | flowRules.add(rule); | 108 | flowRules.add(rule); |
105 | - break; | ||
106 | } | 109 | } |
107 | } | 110 | } |
108 | } | 111 | } | ... | ... |
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; | ... | @@ -31,6 +31,7 @@ import org.onlab.onos.openflow.controller.OpenFlowPacketContext; |
31 | import org.onlab.onos.openflow.controller.PacketListener; | 31 | import org.onlab.onos.openflow.controller.PacketListener; |
32 | import org.onlab.packet.ARP; | 32 | import org.onlab.packet.ARP; |
33 | import org.onlab.packet.Ethernet; | 33 | import org.onlab.packet.Ethernet; |
34 | +import org.onlab.packet.IPv4; | ||
34 | import org.onlab.packet.IpPrefix; | 35 | import org.onlab.packet.IpPrefix; |
35 | import org.onlab.packet.VlanId; | 36 | import org.onlab.packet.VlanId; |
36 | import org.slf4j.Logger; | 37 | import org.slf4j.Logger; |
... | @@ -92,8 +93,6 @@ public class OpenFlowHostProvider extends AbstractProvider implements HostProvid | ... | @@ -92,8 +93,6 @@ public class OpenFlowHostProvider extends AbstractProvider implements HostProvid |
92 | public void handlePacket(OpenFlowPacketContext pktCtx) { | 93 | public void handlePacket(OpenFlowPacketContext pktCtx) { |
93 | Ethernet eth = pktCtx.parsed(); | 94 | Ethernet eth = pktCtx.parsed(); |
94 | 95 | ||
95 | - // Potentially a new or moved host | ||
96 | - if (eth.getEtherType() == Ethernet.TYPE_ARP) { | ||
97 | VlanId vlan = VlanId.vlanId(eth.getVlanID()); | 96 | VlanId vlan = VlanId.vlanId(eth.getVlanID()); |
98 | ConnectPoint heardOn = new ConnectPoint(deviceId(Dpid.uri(pktCtx.dpid())), | 97 | ConnectPoint heardOn = new ConnectPoint(deviceId(Dpid.uri(pktCtx.dpid())), |
99 | portNumber(pktCtx.inPort())); | 98 | portNumber(pktCtx.inPort())); |
... | @@ -107,14 +106,24 @@ public class OpenFlowHostProvider extends AbstractProvider implements HostProvid | ... | @@ -107,14 +106,24 @@ public class OpenFlowHostProvider extends AbstractProvider implements HostProvid |
107 | HostLocation hloc = new HostLocation(deviceId(Dpid.uri(pktCtx.dpid())), | 106 | HostLocation hloc = new HostLocation(deviceId(Dpid.uri(pktCtx.dpid())), |
108 | portNumber(pktCtx.inPort()), | 107 | portNumber(pktCtx.inPort()), |
109 | System.currentTimeMillis()); | 108 | System.currentTimeMillis()); |
110 | - | ||
111 | HostId hid = HostId.hostId(eth.getSourceMAC(), vlan); | 109 | HostId hid = HostId.hostId(eth.getSourceMAC(), vlan); |
110 | + // Potentially a new or moved host | ||
111 | + if (eth.getEtherType() == Ethernet.TYPE_ARP) { | ||
112 | + | ||
113 | + | ||
112 | ARP arp = (ARP) eth.getPayload(); | 114 | ARP arp = (ARP) eth.getPayload(); |
113 | Set<IpPrefix> ips = newHashSet(IpPrefix.valueOf(arp.getSenderProtocolAddress())); | 115 | Set<IpPrefix> ips = newHashSet(IpPrefix.valueOf(arp.getSenderProtocolAddress())); |
114 | HostDescription hdescr = | 116 | HostDescription hdescr = |
115 | new DefaultHostDescription(eth.getSourceMAC(), vlan, hloc, ips); | 117 | new DefaultHostDescription(eth.getSourceMAC(), vlan, hloc, ips); |
116 | providerService.hostDetected(hid, hdescr); | 118 | providerService.hostDetected(hid, hdescr); |
117 | 119 | ||
120 | + } else if (eth.getEtherType() == Ethernet.TYPE_IPV4) { | ||
121 | + IPv4 ip = (IPv4) eth.getPayload(); | ||
122 | + Set<IpPrefix> ips = newHashSet(IpPrefix.valueOf(ip.getSourceAddress())); | ||
123 | + HostDescription hdescr = | ||
124 | + new DefaultHostDescription(eth.getSourceMAC(), vlan, hloc, ips); | ||
125 | + providerService.hostDetected(hid, hdescr); | ||
126 | + | ||
118 | } | 127 | } |
119 | 128 | ||
120 | // TODO: Use DHCP packets as well later... | 129 | // TODO: Use DHCP packets as well later... | ... | ... |
-
Please register or login to post a comment