Merge remote-tracking branch 'origin/master' into dev/murrelet
diff --git a/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/Dhcp4HandlerImpl.java b/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/Dhcp4HandlerImpl.java
index ccdb407..235b4c5 100644
--- a/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/Dhcp4HandlerImpl.java
+++ b/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/Dhcp4HandlerImpl.java
@@ -44,8 +44,12 @@
import org.onosproject.dhcprelay.store.DhcpRelayStore;
import org.onosproject.net.host.HostEvent;
import org.onosproject.net.host.HostListener;
+import org.onosproject.net.host.HostProvider;
+import org.onosproject.net.host.HostProviderRegistry;
+import org.onosproject.net.host.HostProviderService;
import org.onosproject.net.intf.Interface;
import org.onosproject.net.intf.InterfaceService;
+import org.onosproject.net.provider.ProviderId;
import org.onosproject.routeservice.Route;
import org.onosproject.routeservice.RouteStore;
import org.onosproject.net.ConnectPoint;
@@ -57,7 +61,6 @@
import org.onosproject.net.host.DefaultHostDescription;
import org.onosproject.net.host.HostDescription;
import org.onosproject.net.host.HostService;
-import org.onosproject.net.host.HostStore;
import org.onosproject.net.host.InterfaceIpAddress;
import org.onosproject.net.packet.DefaultOutboundPacket;
import org.onosproject.net.packet.OutboundPacket;
@@ -85,7 +88,7 @@
@Component
@Service
@Property(name = "version", value = "4")
-public class Dhcp4HandlerImpl implements DhcpHandler {
+public class Dhcp4HandlerImpl implements DhcpHandler, HostProvider {
private static Logger log = LoggerFactory.getLogger(Dhcp4HandlerImpl.class);
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
@@ -95,9 +98,6 @@
protected PacketService packetService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected HostStore hostStore;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected RouteStore routeStore;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
@@ -106,6 +106,10 @@
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected HostService hostService;
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected HostProviderRegistry providerRegistry;
+
+ protected HostProviderService providerService;
private InternalHostListener hostListener = new InternalHostListener();
private Ip4Address dhcpServerIp = null;
@@ -130,10 +134,16 @@
@Activate
protected void activate() {
hostService.addListener(hostListener);
+ providerService = providerRegistry.register(this);
}
@Deactivate
protected void deactivate() {
+ providerRegistry.unregister(this);
+ hostService.removeListener(hostListener);
+ this.dhcpConnectMac = null;
+ this.dhcpConnectVlan = null;
+
if (dhcpGatewayIp != null) {
hostService.stopMonitoringIp(dhcpGatewayIp);
}
@@ -337,11 +347,6 @@
checkNotNull(incomingPacketType, "Can't get message type from DHCP payload {}", dhcpPayload);
switch (incomingPacketType) {
case DHCPDISCOVER:
- // Try update host if it is directly connected.
- if (directlyConnected(dhcpPayload)) {
- updateHost(context, dhcpPayload);
- }
-
// Add the gateway IP as virtual interface IP for server to understand
// the lease to be assigned and forward the packet to dhcp server.
Ethernet ethernetPacketDiscover =
@@ -387,22 +392,6 @@
}
/**
- * Updates host to host store according to DHCP payload.
- *
- * @param context the packet context
- * @param dhcpPayload the DHCP payload
- */
- private void updateHost(PacketContext context, DHCP dhcpPayload) {
- ConnectPoint location = context.inPacket().receivedFrom();
- HostLocation hostLocation = new HostLocation(location, System.currentTimeMillis());
- MacAddress macAddress = MacAddress.valueOf(dhcpPayload.getClientHardwareAddress());
- VlanId vlanId = VlanId.vlanId(context.inPacket().parsed().getVlanID());
- HostId hostId = HostId.hostId(macAddress, vlanId);
- HostDescription desc = new DefaultHostDescription(macAddress, vlanId, hostLocation);
- hostStore.createOrUpdateHost(DhcpRelayManager.PROVIDER_ID, hostId, desc, false);
- }
-
- /**
* Checks if this app has been configured.
*
* @return true if all information we need have been initialized
@@ -847,11 +836,18 @@
if (directlyConnected(dhcpPayload)) {
// Add to host store if it connect to network directly
Set<IpAddress> ips = Sets.newHashSet(ip);
- HostDescription desc = new DefaultHostDescription(macAddress, vlanId,
- hostLocation, ips);
+ Host host = hostService.getHost(hostId);
- // Replace the ip when dhcp server give the host new ip address
- hostStore.createOrUpdateHost(DhcpRelayManager.PROVIDER_ID, hostId, desc, false);
+ Set<HostLocation> hostLocations = Sets.newHashSet(hostLocation);
+ if (host != null) {
+ // Dual homing support:
+ // if host exists, use old locations and new location
+ hostLocations.addAll(host.locations());
+ }
+ HostDescription desc = new DefaultHostDescription(macAddress, vlanId,
+ hostLocations, ips, false);
+ // Add IP address when dhcp server give the host new ip address
+ providerService.hostDetected(hostId, desc, false);
} else {
// Add to route store if it does not connect to network directly
// Get gateway host IP according to host mac address
@@ -1010,6 +1006,16 @@
packetService.emit(o);
}
+ @Override
+ public void triggerProbe(Host host) {
+ // Do nothing here
+ }
+
+ @Override
+ public ProviderId id() {
+ return DhcpRelayManager.PROVIDER_ID;
+ }
+
class InternalHostListener implements HostListener {
@Override
public void event(HostEvent event) {
diff --git a/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/Dhcp6HandlerImpl.java b/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/Dhcp6HandlerImpl.java
index 19123dc..c247b90 100644
--- a/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/Dhcp6HandlerImpl.java
+++ b/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/Dhcp6HandlerImpl.java
@@ -17,78 +17,1253 @@
package org.onosproject.dhcprelay;
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Deactivate;
+import com.google.common.base.MoreObjects;
+import com.google.common.collect.Sets;
+import com.google.common.collect.ImmutableSet;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.onlab.packet.BasePacket;
+import org.onlab.packet.DHCP6;
+import org.onlab.packet.IPv6;
+import org.onlab.packet.Ethernet;
+import org.onlab.packet.Ip6Address;
import org.onlab.packet.IpAddress;
+import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
+import org.onlab.packet.UDP;
import org.onlab.packet.VlanId;
+import org.onlab.packet.dhcp.Dhcp6RelayOption;
+import org.onlab.packet.dhcp.Dhcp6InterfaceIdOption;
+import org.onlab.packet.dhcp.Dhcp6Option;
+import org.onlab.packet.dhcp.Dhcp6IaNaOption;
+import org.onlab.packet.dhcp.Dhcp6IaTaOption;
+import org.onlab.packet.dhcp.Dhcp6IaPdOption;
+import org.onlab.packet.dhcp.Dhcp6IaAddressOption;
+import org.onlab.packet.dhcp.Dhcp6IaPrefixOption;
+import org.onlab.util.HexString;
import org.onosproject.dhcprelay.api.DhcpHandler;
+import org.onosproject.dhcprelay.store.DhcpRelayStore;
+import org.onosproject.net.host.HostProvider;
+import org.onosproject.net.host.HostProviderRegistry;
+import org.onosproject.net.host.HostProviderService;
+import org.onosproject.net.host.HostService;
+import org.onosproject.net.host.DefaultHostDescription;
+import org.onosproject.net.host.HostDescription;
+import org.onosproject.net.host.InterfaceIpAddress;
+import org.onosproject.net.host.HostListener;
+import org.onosproject.net.host.HostEvent;
+import org.onosproject.net.intf.Interface;
+import org.onosproject.net.intf.InterfaceService;
+import org.onosproject.net.provider.ProviderId;
+import org.onosproject.routeservice.Route;
+import org.onosproject.routeservice.RouteStore;
import org.onosproject.dhcprelay.config.DhcpServerConfig;
import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.Host;
+import org.onosproject.net.HostId;
+import org.onosproject.net.HostLocation;
+import org.onosproject.net.packet.DefaultOutboundPacket;
+import org.onosproject.net.packet.OutboundPacket;
import org.onosproject.net.packet.PacketContext;
+import org.onosproject.net.packet.PacketService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.onosproject.net.flow.DefaultTrafficTreatment;
+import org.onosproject.net.flow.TrafficTreatment;
+
+import java.nio.ByteBuffer;
+import java.util.List;
import java.util.Collection;
import java.util.Optional;
+import java.util.Set;
+import java.util.ArrayList;
+
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Preconditions.checkState;
@Component
@Service
@Property(name = "version", value = "6")
-public class Dhcp6HandlerImpl implements DhcpHandler {
+public class Dhcp6HandlerImpl implements DhcpHandler, HostProvider {
+ private static Logger log = LoggerFactory.getLogger(Dhcp6HandlerImpl.class);
- @Override
- public void processDhcpPacket(PacketContext context, BasePacket dhcp6Payload) {
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected DhcpRelayStore dhcpRelayStore;
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected PacketService packetService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected RouteStore routeStore;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected InterfaceService interfaceService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected HostService hostService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected HostProviderRegistry providerRegistry;
+
+ private InternalHostListener hostListener = new InternalHostListener();
+ protected HostProviderService providerService;
+ private Ip6Address dhcpServerIp = null;
+ // dhcp server may be connected directly to the SDN network or
+ // via an external gateway. When connected directly, the dhcpConnectPoint, dhcpConnectMac,
+ // and dhcpConnectVlan refer to the server. When connected via the gateway, they refer
+ // to the gateway.
+ private ConnectPoint dhcpServerConnectPoint = null;
+ private MacAddress dhcpConnectMac = null;
+ private VlanId dhcpConnectVlan = null;
+ private Ip6Address dhcpGatewayIp = null;
+ private Ip6Address relayAgentIpFromCfg = null;
+
+ private Ip6Address indirectDhcpServerIp = null;
+ private ConnectPoint indirectDhcpServerConnectPoint = null;
+ private MacAddress indirectDhcpConnectMac = null;
+ private VlanId indirectDhcpConnectVlan = null;
+ private Ip6Address indirectDhcpGatewayIp = null;
+ private Ip6Address indirectRelayAgentIpFromCfg = null;
+
+
+ // CLIENT message types
+ public static final Set<Byte> MSG_TYPE_FROM_CLIENT =
+ ImmutableSet.of(DHCP6.MsgType.SOLICIT.value(),
+ DHCP6.MsgType.REQUEST.value(),
+ DHCP6.MsgType.REBIND.value(),
+ DHCP6.MsgType.RENEW.value(),
+ DHCP6.MsgType.RELEASE.value(),
+ DHCP6.MsgType.DECLINE.value(),
+ DHCP6.MsgType.CONFIRM.value(),
+ DHCP6.MsgType.RELAY_FORW.value());
+ // SERVER message types
+ public static final Set<Byte> MSG_TYPE_FROM_SERVER =
+ ImmutableSet.of(DHCP6.MsgType.RELAY_REPL.value());
+
+ @Activate
+ protected void activate() {
+ providerService = providerRegistry.register(this);
+ hostService.addListener(hostListener);
}
- @Override
- public Optional<IpAddress> getDhcpServerIp() {
- return null;
- }
+ @Deactivate
+ protected void deactivate() {
+ providerRegistry.unregister(this);
+ hostService.removeListener(hostListener);
+ this.dhcpConnectMac = null;
+ this.dhcpConnectVlan = null;
- @Override
- public Optional<IpAddress> getDhcpGatewayIp() {
- return null;
- }
-
- @Override
- public Optional<MacAddress> getDhcpConnectMac() {
- return null;
- }
-
- @Override
- public void setDhcpGatewayIp(IpAddress dhcpGatewayIp) {
-
- }
-
- @Override
- public void setDhcpConnectVlan(VlanId dhcpConnectVlan) {
-
- }
-
- @Override
- public void setDhcpConnectMac(MacAddress dhcpConnectMac) {
-
- }
-
- @Override
- public void setDhcpServerConnectPoint(ConnectPoint dhcpServerConnectPoint) {
-
+ if (dhcpGatewayIp != null) {
+ hostService.stopMonitoringIp(dhcpGatewayIp);
+ } else if (dhcpServerIp != null) {
+ hostService.stopMonitoringIp(dhcpServerIp);
+ }
}
@Override
public void setDhcpServerIp(IpAddress dhcpServerIp) {
+ checkNotNull(dhcpServerIp, "DHCP server IP can't be null");
+ checkState(dhcpServerIp.isIp6(), "Invalid server IP for DHCPv6 relay handler");
+ this.dhcpServerIp = dhcpServerIp.getIp6Address();
+ }
+ @Override
+ public void setDhcpServerConnectPoint(ConnectPoint dhcpServerConnectPoint) {
+ checkNotNull(dhcpServerConnectPoint, "Server connect point can't null");
+ this.dhcpServerConnectPoint = dhcpServerConnectPoint;
+ }
+
+ @Override
+ public void setDhcpConnectMac(MacAddress dhcpConnectMac) {
+ this.dhcpConnectMac = dhcpConnectMac;
+ }
+
+ @Override
+ public void setDhcpConnectVlan(VlanId dhcpConnectVlan) {
+ this.dhcpConnectVlan = dhcpConnectVlan;
+ }
+
+ @Override
+ public void setDhcpGatewayIp(IpAddress dhcpGatewayIp) {
+ if (dhcpGatewayIp != null) {
+ checkState(dhcpGatewayIp.isIp6(), "Invalid gateway IP for DHCPv6 relay handler");
+ this.dhcpGatewayIp = dhcpGatewayIp.getIp6Address();
+ } else {
+ // removes gateway config
+ this.dhcpGatewayIp = null;
+ }
+ }
+ @Override
+ public Optional<IpAddress> getDhcpServerIp() {
+ return Optional.ofNullable(dhcpServerIp);
+ }
+
+ @Override
+ public Optional<IpAddress> getDhcpGatewayIp() {
+ return Optional.ofNullable(dhcpGatewayIp);
+ }
+
+ @Override
+ public Optional<MacAddress> getDhcpConnectMac() {
+ return Optional.ofNullable(dhcpConnectMac);
+ }
+
+ // Indirect DHCP server
+
+ public void setIndirectDhcpServerIp(IpAddress dhcpServerIp) {
+ checkNotNull(dhcpServerIp, "DHCP indirect server IP can't be null");
+ checkState(dhcpServerIp.isIp6(), "Invalid indirect server IP for DHCPv6 relay handler");
+ this.indirectDhcpServerIp = dhcpServerIp.getIp6Address();
+ }
+
+
+ public void setIndirectDhcpServerConnectPoint(ConnectPoint dhcpServerConnectPoint) {
+ checkNotNull(dhcpServerConnectPoint, "Indirect Server connect point can't null");
+ this.indirectDhcpServerConnectPoint = dhcpServerConnectPoint;
+ }
+
+
+ public void setIndirectDhcpConnectMac(MacAddress dhcpConnectMac) {
+ this.indirectDhcpConnectMac = dhcpConnectMac;
+ }
+
+
+ public void setIndirectDhcpConnectVlan(VlanId dhcpConnectVlan) {
+ this.indirectDhcpConnectVlan = dhcpConnectVlan;
+ }
+
+
+ public void setIndirectDhcpGatewayIp(IpAddress dhcpGatewayIp) {
+ if (dhcpGatewayIp != null) {
+ checkState(dhcpGatewayIp.isIp6(), "Invalid indirect gateway IP for DHCPv6 relay handler");
+ this.indirectDhcpGatewayIp = dhcpGatewayIp.getIp6Address();
+ } else {
+ // removes gateway config
+ this.indirectDhcpGatewayIp = null;
+ }
+ }
+
+ public Optional<IpAddress> getIndirectDhcpServerIp() {
+ return Optional.ofNullable(indirectDhcpServerIp);
+ }
+
+
+ public Optional<IpAddress> getIndirectDhcpGatewayIp() {
+ return Optional.ofNullable(indirectDhcpGatewayIp);
+ }
+
+
+ public Optional<MacAddress> getIndirectDhcpConnectMac() {
+ return Optional.ofNullable(indirectDhcpConnectMac);
+ }
+
+
+ @Override
+ public void processDhcpPacket(PacketContext context, BasePacket payload) {
+ checkNotNull(payload, "DHCP6 payload can't be null");
+ checkState(payload instanceof DHCP6, "Payload is not a DHCP6");
+ DHCP6 dhcp6Payload = (DHCP6) payload;
+ Ethernet receivedPacket = context.inPacket().parsed();
+
+ if (!configured()) {
+ log.warn("Missing DHCP6 relay server config. Abort packet processing");
+ log.warn("dhcp6 payload {}", dhcp6Payload);
+
+ return;
+ }
+
+ byte msgType = dhcp6Payload.getMsgType();
+ log.warn("msgType is {}", msgType);
+
+ ConnectPoint inPort = context.inPacket().receivedFrom();
+ if (inPort == null) {
+ log.warn("incommin ConnectPoint is null");
+ }
+ Set<Interface> receivingInterfaces = interfaceService.getInterfacesByPort(inPort);
+ //ignore the packets if dhcp client interface is not configured on onos.
+ if (receivingInterfaces.isEmpty()) {
+ log.warn("Virtual interface is not configured on {}", inPort);
+ return;
+ }
+
+
+ if (MSG_TYPE_FROM_CLIENT.contains(msgType)) {
+
+ InternalPacket ethernetClientPacket =
+ processDhcp6PacketFromClient(context, receivedPacket, receivingInterfaces);
+ if (ethernetClientPacket != null) {
+ forwardPacket(ethernetClientPacket);
+ }
+
+ } else if (MSG_TYPE_FROM_SERVER.contains(msgType)) {
+ log.warn("calling processDhcp6PacketFromServer with RELAY_REPL", msgType);
+ InternalPacket ethernetPacketReply =
+ processDhcp6PacketFromServer(context, receivedPacket, receivingInterfaces);
+ if (ethernetPacketReply != null) {
+ forwardPacket(ethernetPacketReply);
+ }
+ } else {
+ log.warn("Not so fast, packet type {} not supported yet", msgType);
+ }
+ }
+
+
+ /**
+ * Checks if this app has been configured.
+ *
+ * @return true if all information we need have been initialized
+ */
+ public boolean configured() {
+ log.warn("dhcpServerConnectPoint {} dhcpServerIp {}",
+ this.dhcpServerConnectPoint, this.dhcpServerIp);
+ return this.dhcpServerConnectPoint != null && this.dhcpServerIp != null;
+ }
+
+ @Override
+ public ProviderId id() {
+ return DhcpRelayManager.PROVIDER_ID;
+ }
+
+ @Override
+ public void triggerProbe(Host host) {
+ // Do nothing here
+ }
+
+ // the new class the contains Ethernet packet and destination port, kind of like adding
+ // internal header to the packet
+ private class InternalPacket {
+ Ethernet packet;
+ ConnectPoint destLocation;
+ public InternalPacket(Ethernet newPacket, ConnectPoint newLocation) {
+ packet = newPacket;
+ destLocation = newLocation;
+ }
+ void setLocation(ConnectPoint newLocation) {
+ destLocation = newLocation;
+ }
+ }
+
+ //forward the packet to ConnectPoint where the DHCP server is attached.
+ private void forwardPacket(InternalPacket packet) {
+ //send Packetout to dhcp server connectpoint.
+ if (packet.destLocation != null) {
+ TrafficTreatment t = DefaultTrafficTreatment.builder()
+ .setOutput(packet.destLocation.port()).build();
+ OutboundPacket o = new DefaultOutboundPacket(
+ packet.destLocation.deviceId(), t, ByteBuffer.wrap(packet.packet.serialize()));
+ if (log.isTraceEnabled()) {
+ log.trace("Relaying packet to destination {}", packet.destLocation);
+ }
+ packetService.emit(o);
+ } // if
+ }
+
+ /**
+ * Check if the host is directly connected to the network or not.
+ *
+ * @param dhcp6Payload the dhcp6 payload
+ * @return true if the host is directly connected to the network; false otherwise
+ */
+ private boolean directlyConnected(DHCP6 dhcp6Payload) {
+ log.debug("directlyConnected enters");
+
+ if (dhcp6Payload.getMsgType() != DHCP6.MsgType.RELAY_FORW.value() &&
+ dhcp6Payload.getMsgType() != DHCP6.MsgType.RELAY_REPL.value()) {
+ log.debug("directlyConnected true. MsgType {}", dhcp6Payload.getMsgType());
+
+ return true;
+ }
+
+ // Regardless of relay-forward or relay-replay, check if we see another relay message
+ DHCP6 dhcp6Payload2 = dhcp6PacketFromRelayPacket(dhcp6Payload);
+ if (dhcp6Payload2 != null) {
+ if (dhcp6Payload.getMsgType() == DHCP6.MsgType.RELAY_FORW.value()) {
+ log.debug("directlyConnected false. 1st realy-foward, 2nd MsgType {}", dhcp6Payload2.getMsgType());
+ return false;
+ } else {
+ // relay-reply
+ if (dhcp6Payload2.getMsgType() != DHCP6.MsgType.RELAY_REPL.value()) {
+ log.debug("directlyConnected true. 2nd MsgType {}", dhcp6Payload2.getMsgType());
+ return true; // must be directly connected
+ } else {
+ log.debug("directlyConnected false. 1st relay-reply, 2nd relay-reply MsgType {}",
+ dhcp6Payload2.getMsgType());
+ return false; // must be indirectly connected
+ }
+ }
+ } else {
+ log.warn("directlyConnected true.");
+ return true;
+ }
+ }
+
+ /**
+ * extract DHCP6 payload from dhcp6 relay message within relay-forwrd/reply.
+ *
+ * @param dhcp6 dhcp6 relay-reply or relay-foward
+ * @return dhcp6Packet dhcp6 packet extracted from relay-message
+ */
+ private DHCP6 dhcp6PacketFromRelayPacket(DHCP6 dhcp6) {
+ log.debug("dhcp6PacketFromRelayPacket enters. dhcp6 {}", dhcp6);
+
+ // extract the relay message if exist
+ DHCP6 dhcp6Payload = dhcp6.getOptions().stream()
+ .filter(opt -> opt instanceof Dhcp6RelayOption)
+ .map(BasePacket::getPayload)
+ .map(pld -> (DHCP6) pld)
+ .findFirst()
+ .orElse(null);
+
+
+ if (dhcp6Payload == null) {
+ // Can't find dhcp payload
+ log.debug("Can't find dhcp6 payload from relay message");
+ } else {
+ log.debug("dhcp6 payload found from relay message {}", dhcp6Payload);
+ }
+
+ return dhcp6Payload;
+ }
+
+ /**
+ * find the leaf DHCP6 packet from multi-level relay packet.
+ *
+ * @param relayPacket dhcp6 relay packet
+ * @return leafPacket non-relay dhcp6 packet
+ */
+ private DHCP6 getDhcp6Leaf(DHCP6 relayPacket) {
+ DHCP6 dhcp6Parent = relayPacket;
+ DHCP6 dhcp6Child = null;
+
+ log.debug("getDhcp6Leaf entered.");
+ while (dhcp6Parent != null) {
+ dhcp6Child = dhcp6PacketFromRelayPacket(dhcp6Parent);
+
+ if (dhcp6Child != null) {
+ if (dhcp6Child.getMsgType() != DHCP6.MsgType.RELAY_FORW.value() &&
+ dhcp6Child.getMsgType() != DHCP6.MsgType.RELAY_REPL.value()) {
+ log.debug("leaf dhcp6 packet found.");
+ break;
+ } else {
+ // found another relay
+ // go for another loop
+ dhcp6Parent = dhcp6Child;
+ }
+ } else {
+ log.warn("malformed pkt! Expected dhcp6 within relay pkt, but no dhcp6 leaf found.");
+ break;
+ }
+ }
+ return dhcp6Child;
+ }
+
+ /**
+ * check if DHCP6 relay-reply is reply.
+ *
+ * @param relayPacket dhcp6 relay-reply
+ * @return boolean relay-reply contains ack
+ */
+ private boolean isDhcp6Reply(DHCP6 relayPacket) {
+ log.debug("isDhcp6Reply entered.");
+
+ DHCP6 leafDhcp6 = getDhcp6Leaf(relayPacket);
+
+ if (leafDhcp6 != null) {
+ if (leafDhcp6.getMsgType() == DHCP6.MsgType.REPLY.value()) {
+ log.debug("isDhcp6Reply true.");
+ return true; // must be directly connected
+ } else {
+ log.debug("isDhcp6Reply false. leaf dhcp6 is not replay. MsgType {}", leafDhcp6.getMsgType());
+ }
+ } else {
+ log.debug("isDhcp6Reply false. Expected dhcp6 within relay pkt but not found.");
+ }
+ log.debug("isDhcp6Reply false.");
+ return false;
+ }
+
+ /**
+ * check if DHCP6 is release or relay-forward contains release.
+ *
+ * @param dhcp6Payload dhcp6 packet
+ * @return boolean dhcp6 contains release
+ */
+ private boolean isDhcp6Release(DHCP6 dhcp6Payload) {
+
+ log.debug("isDhcp6Release entered.");
+
+ if (dhcp6Payload.getMsgType() == DHCP6.MsgType.RELEASE.value()) {
+ log.debug("isDhcp6Release true.");
+ return true; // must be directly connected
+ } else {
+ DHCP6 dhcp6Leaf = getDhcp6Leaf(dhcp6Payload);
+ if (dhcp6Leaf != null) {
+ if (dhcp6Leaf.getMsgType() == DHCP6.MsgType.RELEASE.value()) {
+ log.debug("isDhcp6Release true. indirectlry connected");
+ return true;
+ } else {
+ log.debug("leaf dhcp6 is not release. MsgType {}", dhcp6Leaf.getMsgType());
+ return false;
+ }
+ } else {
+ log.debug("isDhcp6Release false. dhcp6 is niether relay nor release.");
+ return false;
+ }
+ }
+ }
+
+ /**
+ * extract from dhcp6 packet client ipv6 address of given by dhcp server.
+ *
+ * @param dhcp6 the dhcp6 packet
+ * @return Ip6Address Ip6Address given by dhcp server, or null if not exists
+ */
+ private Ip6Address extractIpAddress(DHCP6 dhcp6) {
+ Ip6Address ip = null;
+
+ log.debug("extractIpAddress enters dhcp6 {}.", dhcp6);
+ // Extract IPv6 address from IA NA ot IA TA option
+ Optional<Dhcp6IaNaOption> iaNaOption = dhcp6.getOptions()
+ .stream()
+ .filter(opt -> opt instanceof Dhcp6IaNaOption)
+ .map(opt -> (Dhcp6IaNaOption) opt)
+ .findFirst();
+ Optional<Dhcp6IaTaOption> iaTaOption = dhcp6.getOptions()
+ .stream()
+ .filter(opt -> opt instanceof Dhcp6IaTaOption)
+ .map(opt -> (Dhcp6IaTaOption) opt)
+ .findFirst();
+ Optional<Dhcp6IaAddressOption> iaAddressOption;
+ if (iaNaOption.isPresent()) {
+ log.debug("Found IPv6 address from iaNaOption {}", iaNaOption);
+
+ iaAddressOption = iaNaOption.get().getOptions().stream()
+ .filter(opt -> opt instanceof Dhcp6IaAddressOption)
+ .map(opt -> (Dhcp6IaAddressOption) opt)
+ .findFirst();
+ } else if (iaTaOption.isPresent()) {
+ log.debug("Found IPv6 address from iaTaOption {}", iaTaOption);
+
+ iaAddressOption = iaTaOption.get().getOptions().stream()
+ .filter(opt -> opt instanceof Dhcp6IaAddressOption)
+ .map(opt -> (Dhcp6IaAddressOption) opt)
+ .findFirst();
+ } else {
+ iaAddressOption = Optional.empty();
+ }
+ if (iaAddressOption.isPresent()) {
+ ip = iaAddressOption.get().getIp6Address();
+ log.debug("Found IPv6 address from iaAddressOption {}", iaAddressOption);
+
+
+ } else {
+ log.debug("Can't find IPv6 address from DHCPv6 {}", dhcp6);
+ }
+
+ return ip;
+ }
+ /**
+ * extract from dhcp6 packet Prefix prefix provided by dhcp server.
+ *
+ * @param dhcp6 the dhcp6 payload
+ * @return IpPrefix Prefix Delegation prefix, or null if not exists.
+ */
+ private IpPrefix extractPrefix(DHCP6 dhcp6) {
+ log.warn("extractPrefix enters {}", dhcp6);
+
+ // extract prefix
+ IpPrefix prefixPrefix = null;
+
+ Ip6Address prefixAddress = null;
+
+ // Extract IPv6 prefix from IA PD option
+ Optional<Dhcp6IaPdOption> iaPdOption = dhcp6.getOptions()
+ .stream()
+ .filter(opt -> opt instanceof Dhcp6IaPdOption)
+ .map(opt -> (Dhcp6IaPdOption) opt)
+ .findFirst();
+
+ Optional<Dhcp6IaPrefixOption> iaPrefixOption;
+ if (iaPdOption.isPresent()) {
+ log.warn("IA_PD option found {}", iaPdOption);
+
+ iaPrefixOption = iaPdOption.get().getOptions().stream()
+ .filter(opt -> opt instanceof Dhcp6IaPrefixOption)
+ .map(opt -> (Dhcp6IaPrefixOption) opt)
+ .findFirst();
+ } else {
+ log.warn("IA_PD option NOT found");
+
+ iaPrefixOption = Optional.empty();
+ }
+ if (iaPrefixOption.isPresent()) {
+ log.warn("IAPrefix Option within IA_PD option found {}", iaPrefixOption);
+
+ prefixAddress = iaPrefixOption.get().getIp6Prefix();
+ int prefixLen = (int) iaPrefixOption.get().getPrefixLength();
+ log.warn("Prefix length is {} bits", prefixLen);
+ prefixPrefix = IpPrefix.valueOf(prefixAddress, prefixLen);
+
+ } else {
+ log.warn("Can't find IPv6 prefix from DHCPv6 {}", dhcp6);
+ }
+
+ return prefixPrefix;
+ }
+
+ /**
+ * remove host or route.
+ *
+ * @param directConnFlag flag to show that packet is from directly connected client
+ * @param dhcp6Packet the dhcp6 payload
+ * @param clientPacket client's ethernet packet
+ * @param clientIpv6 client's Ipv6 packet
+ * @param clientInterfaces set of client interfaces
+ */
+ private void removeHostOrRoute(boolean directConnFlag, DHCP6 dhcp6Packet,
+ Ethernet clientPacket, IPv6 clientIpv6,
+ Set<Interface> clientInterfaces) {
+ log.debug("extractPrefix enters {}", dhcp6Packet);
+ // add host or route
+ if (isDhcp6Release(dhcp6Packet)) {
+ IpAddress ip = null;
+ if (directConnFlag) {
+ // Add to host store if it is connected to network directly
+ ip = extractIpAddress(dhcp6Packet);
+ if (ip != null) {
+ VlanId vlanId = clientInterfaces.iterator().next().vlan();
+ MacAddress clientMac = clientPacket.getSourceMAC();
+ HostId hostId = HostId.hostId(clientMac, vlanId);
+ log.debug("remove Host {} ip for directly connected.", hostId.toString());
+
+ log.debug("client mac {} client vlan {}", HexString.toHexString(clientMac.toBytes(), ":"), vlanId);
+
+ // Remove host's ip of when dhcp release msg is received
+ providerService.removeIpFromHost(hostId, ip);
+ } else {
+ log.debug("ipAddress not found. Do not add Host for directly connected.");
+ }
+ } else {
+ // Remove from route store if it is not connected to network directly
+ IpAddress nextHopIp = IpAddress.valueOf(IpAddress.Version.INET6, clientIpv6.getSourceAddress());
+
+ DHCP6 leafDhcp = getDhcp6Leaf(dhcp6Packet);
+ ip = extractIpAddress(leafDhcp);
+ if (ip == null) {
+ log.debug("ip is null");
+ } else {
+ Route routeForIP = new Route(Route.Source.STATIC, ip.toIpPrefix(), nextHopIp);
+ log.debug("removing route of 128 address for indirectly connected.");
+ log.debug("128 ip {}, nexthop {}", HexString.toHexString(ip.toOctets(), ":"),
+ HexString.toHexString(nextHopIp.toOctets(), ":"));
+ routeStore.removeRoute(routeForIP);
+ }
+
+ IpPrefix ipPrefix = extractPrefix(leafDhcp);
+ if (ipPrefix == null) {
+ log.debug("ipPrefix is null ");
+ } else {
+ Route routeForPrefix = new Route(Route.Source.STATIC, ipPrefix, nextHopIp);
+ log.debug("removing route of PD for indirectly connected.");
+ log.debug("pd ip {}, nexthop {}", HexString.toHexString(ipPrefix.address().toOctets(), ":"),
+ HexString.toHexString(nextHopIp.toOctets(), ":"));
+
+ routeStore.removeRoute(routeForPrefix);
+ }
+ }
+ }
+ }
+
+ /**
+ * add host or route.
+ *
+ * @param directConnFlag flag to show that packet is from directly connected client
+ * @param dhcp6Relay the dhcp6 payload
+ * @param embeddedDhcp6 client's ethernet packetthe dhcp6 payload within relay
+ * @param clientMac client macAddress
+ * @param clientInterfaces set of client interfaces
+ */
+ private void addHostOrRoute(boolean directConnFlag, DHCP6 dhcp6Relay,
+ DHCP6 embeddedDhcp6,
+ MacAddress clientMac,
+ Set<Interface> clientInterfaces) {
+ log.debug("addHostOrRoute entered.");
+ // add host or route
+ if (isDhcp6Reply(dhcp6Relay)) {
+ IpAddress ip = null;
+ if (directConnFlag) {
+ // Add to host store if it connect to network directly
+ ip = extractIpAddress(embeddedDhcp6);
+ if (ip != null) {
+ Set<IpAddress> ips = Sets.newHashSet(ip);
+
+ // FIXME: we should use vlan id from original packet (solicit, request)
+ VlanId vlanId = clientInterfaces.iterator().next().vlan();
+ HostId hostId = HostId.hostId(clientMac, vlanId);
+ Host host = hostService.getHost(hostId);
+ HostLocation hostLocation = new HostLocation(clientInterfaces.iterator().next().connectPoint(),
+ System.currentTimeMillis());
+ Set<HostLocation> hostLocations = Sets.newHashSet(hostLocation);
+
+ if (host != null) {
+ // Dual homing support:
+ // if host exists, use old locations and new location
+ hostLocations.addAll(host.locations());
+ }
+ HostDescription desc = new DefaultHostDescription(clientMac, vlanId,
+ hostLocations, ips,
+ false);
+ log.debug("adding Host for directly connected.");
+ log.debug("client mac {} client vlan {} hostlocation {}",
+ HexString.toHexString(clientMac.toBytes(), ":"),
+ vlanId, hostLocation.toString());
+
+ // Replace the ip when dhcp server give the host new ip address
+ providerService.hostDetected(hostId, desc, false);
+ } else {
+ log.warn("ipAddress not found. Do not add Host for directly connected.");
+ }
+ } else {
+ // Add to route store if it does not connect to network directly
+ IpAddress nextHopIp = IpAddress.valueOf(IpAddress.Version.INET6, dhcp6Relay.getPeerAddress());
+
+ DHCP6 leafDhcp = getDhcp6Leaf(embeddedDhcp6);
+ ip = extractIpAddress(leafDhcp);
+ if (ip == null) {
+ log.warn("ip is null");
+ } else {
+ Route routeForIP = new Route(Route.Source.STATIC, ip.toIpPrefix(), nextHopIp);
+ log.warn("adding Route of 128 address for indirectly connected.");
+ routeStore.updateRoute(routeForIP);
+ }
+
+ IpPrefix ipPrefix = extractPrefix(leafDhcp);
+ if (ipPrefix == null) {
+ log.warn("ipPrefix is null ");
+ } else {
+ Route routeForPrefix = new Route(Route.Source.STATIC, ipPrefix, nextHopIp);
+ log.warn("adding Route of PD for indirectly connected.");
+ routeStore.updateRoute(routeForPrefix);
+ }
+ }
+ }
+ }
+
+ /**
+ *
+ * build the DHCP6 solicit/request packet with gatewayip.
+ *
+ * @param context packet context
+ * @param clientPacket client ethernet packet
+ * @param clientInterfaces set of client side interfaces
+ */
+ private InternalPacket processDhcp6PacketFromClient(PacketContext context,
+ Ethernet clientPacket, Set<Interface> clientInterfaces) {
+ Ip6Address relayAgentIp = getRelayAgentIPv6Address(clientInterfaces);
+ MacAddress relayAgentMac = clientInterfaces.iterator().next().mac();
+ if (relayAgentIp == null || relayAgentMac == null) {
+ log.warn("Missing DHCP relay agent interface Ipv6 addr config for "
+ + "packet from client on port: {}. Aborting packet processing",
+ clientInterfaces.iterator().next().connectPoint());
+ return null;
+ }
+
+ // get dhcp6 header.
+
+ IPv6 clientIpv6 = (IPv6) clientPacket.getPayload();
+ UDP clientUdp = (UDP) clientIpv6.getPayload();
+ DHCP6 clientDhcp6 = (DHCP6) clientUdp.getPayload();
+
+ boolean directConnFlag = directlyConnected(clientDhcp6);
+
+ Ethernet etherReply = (Ethernet) clientPacket.clone();
+ etherReply.setSourceMACAddress(relayAgentMac);
+
+ if (directConnFlag && this.dhcpConnectMac == null) {
+ log.warn("DHCP6 {} not yet resolved .. Aborting DHCP "
+ + "packet processing from client on port: {}",
+ (this.dhcpGatewayIp == null) ? "server IP " + this.dhcpServerIp
+ : "gateway IP " + this.dhcpGatewayIp,
+ clientInterfaces.iterator().next().connectPoint());
+
+ return null;
+ }
+
+ if (!directConnFlag && this.indirectDhcpConnectMac == null) {
+ log.warn("DHCP6 {} not yet resolved .. Aborting DHCP "
+ + "packet processing from client on port: {}",
+ (this.indirectDhcpGatewayIp == null) ? "server IP " + this.indirectDhcpServerIp
+ : "gateway IP " + this.indirectDhcpGatewayIp,
+ clientInterfaces.iterator().next().connectPoint());
+
+ return null;
+
+ }
+
+ if (this.dhcpServerConnectPoint == null) {
+ log.warn("DHCP6 server connection point is not set up yet");
+ return null;
+ }
+
+ etherReply.setDestinationMACAddress(directConnFlag ? this.dhcpConnectMac : this.indirectDhcpConnectMac);
+ etherReply.setVlanID(directConnFlag ? this.dhcpConnectVlan.toShort() : this.indirectDhcpConnectVlan.toShort());
+
+ IPv6 ipv6Packet = (IPv6) etherReply.getPayload();
+ byte[] peerAddress = clientIpv6.getSourceAddress();
+ ipv6Packet.setSourceAddress(relayAgentIp.toOctets());
+ ipv6Packet.setDestinationAddress(directConnFlag ? this.dhcpServerIp.toOctets() :
+ this.indirectDhcpServerIp.toOctets());
+
+ UDP udpPacket = (UDP) ipv6Packet.getPayload();
+ udpPacket.setSourcePort(UDP.DHCP_V6_SERVER_PORT);
+ DHCP6 dhcp6Packet = (DHCP6) udpPacket.getPayload();
+ byte[] dhcp6PacketByte = dhcp6Packet.serialize();
+
+ // notify onos and quagga to release PD
+ //releasePD(dhcp6Packet);
+
+ removeHostOrRoute(directConnFlag, dhcp6Packet, clientPacket, clientIpv6, clientInterfaces);
+
+ DHCP6 dhcp6Relay = new DHCP6();
+ dhcp6Relay.setMsgType(DHCP6.MsgType.RELAY_FORW.value());
+ // link address: server uses the address to identify the link on which the client
+ // is located.
+ if (directConnFlag) {
+ dhcp6Relay.setLinkAddress(relayAgentIp.toOctets());
+ log.debug("direct connection: relayAgentIp obtained dynamically {}",
+ HexString.toHexString(relayAgentIp.toOctets(), ":"));
+
+ } else {
+ if (this.indirectRelayAgentIpFromCfg == null) {
+ dhcp6Relay.setLinkAddress(relayAgentIp.toOctets());
+ log.warn("indirect connection: relayAgentIp NOT availale from config file! {}",
+ HexString.toHexString(relayAgentIp.toOctets(), ":"));
+
+ } else {
+ dhcp6Relay.setLinkAddress(this.indirectRelayAgentIpFromCfg.toOctets());
+ log.debug("indirect connection: relayAgentIp from config file is available! {}",
+ HexString.toHexString(this.indirectRelayAgentIpFromCfg.toOctets(), ":"));
+ }
+ }
+
+ // peer address: address of the client or relay agent from which
+ // the message to be relayed was received.
+ dhcp6Relay.setPeerAddress(peerAddress);
+ List<Dhcp6Option> options = new ArrayList<Dhcp6Option>();
+
+ // directly connected case, hop count is zero
+ // otherwise, hop count + 1
+ if (directConnFlag) {
+ dhcp6Relay.setHopCount((byte) 0);
+ } else {
+ dhcp6Relay.setHopCount((byte) (dhcp6Packet.getHopCount() + 1));
+ }
+
+ // create relay message option
+ Dhcp6Option relayMessage = new Dhcp6Option();
+ relayMessage.setCode(DHCP6.OptionCode.RELAY_MSG.value());
+ relayMessage.setLength((short) dhcp6PacketByte.length);
+ relayMessage.setData(dhcp6PacketByte);
+ options.add(relayMessage);
+
+ // create interfaceId option
+ String inPortString = "-" + context.inPacket().receivedFrom().toString();
+ Dhcp6Option interfaceId = new Dhcp6Option();
+ interfaceId.setCode(DHCP6.OptionCode.INTERFACE_ID.value());
+ byte[] clientSoureMacBytes = clientPacket.getSourceMACAddress();
+ byte[] inPortStringBytes = inPortString.getBytes();
+ byte[] interfaceIdBytes = new byte[clientSoureMacBytes.length + inPortStringBytes.length];
+ log.debug("Length: interfaceIdBytes {} clientSoureMacBytes {} inPortStringBytes {} ",
+ interfaceIdBytes.length, clientSoureMacBytes.length, inPortStringBytes.length);
+
+ System.arraycopy(clientSoureMacBytes, 0, interfaceIdBytes, 0, clientSoureMacBytes.length);
+ System.arraycopy(inPortStringBytes, 0, interfaceIdBytes, clientSoureMacBytes.length, inPortStringBytes.length);
+
+ interfaceId.setData(interfaceIdBytes);
+ interfaceId.setLength((short) interfaceIdBytes.length);
+
+ options.add(interfaceId);
+
+ log.debug("interfaceId write srcMac {} portString {}",
+ HexString.toHexString(clientSoureMacBytes, ":"), inPortString);
+ dhcp6Relay.setOptions(options);
+ //dhcp6Packet.setPayload(dhcp6Relay);
+ //udpPacket.setPayload(dhcp6Packet);
+ udpPacket.setPayload(dhcp6Relay);
+ udpPacket.resetChecksum();
+ ipv6Packet.setPayload(udpPacket);
+ etherReply.setPayload(ipv6Packet);
+
+
+ return new InternalPacket(etherReply, this.dhcpServerConnectPoint);
+ }
+
+ /**
+ *
+ * process the DHCP6 relay-reply packet from dhcp server.
+ *
+ * @param context packet context
+ * @param receivedPacket server ethernet packet
+ * @param recevingInterfaces set of server side interfaces
+ */
+ private InternalPacket processDhcp6PacketFromServer(PacketContext context,
+ Ethernet receivedPacket, Set<Interface> recevingInterfaces) {
+ ConnectPoint inPort = context.inPacket().receivedFrom();
+ if (!inPort.equals(this.dhcpServerConnectPoint)) {
+ log.warn("Receiving port {} is not the same as server port {}",
+ inPort, this.dhcpServerConnectPoint);
+ return null;
+ }
+ // get dhcp6 header.
+ Ethernet etherReply = (Ethernet) receivedPacket.clone();
+ IPv6 ipv6Packet = (IPv6) etherReply.getPayload();
+ UDP udpPacket = (UDP) ipv6Packet.getPayload();
+ DHCP6 dhcp6Relay = (DHCP6) udpPacket.getPayload();
+
+ Boolean directConnFlag = directlyConnected(dhcp6Relay);
+
+ Dhcp6InterfaceIdOption interfaceIdOption = dhcp6Relay.getOptions().stream()
+ .filter(opt -> opt instanceof Dhcp6InterfaceIdOption)
+ .map(opt -> (Dhcp6InterfaceIdOption) opt)
+ .findFirst()
+ .orElse(null);
+
+ if (interfaceIdOption == null) {
+ log.warn("Interface Id option is not present, abort packet...");
+ return null;
+ }
+
+ MacAddress peerMac = interfaceIdOption.getMacAddress();
+ String clientConnectionPointStr = new String(interfaceIdOption.getInPort());
+
+ ConnectPoint clientConnectionPoint = ConnectPoint.deviceConnectPoint(clientConnectionPointStr);
+
+ Set<Interface> clientInterfaces = interfaceService.getInterfacesByPort(clientConnectionPoint);
+ if (clientInterfaces.isEmpty()) {
+ log.warn("Can not get client interface from packet, abort..");
+ return null;
+ }
+ MacAddress relayAgentMac = clientInterfaces.iterator().next().mac();
+ if (relayAgentMac == null) {
+ log.warn("Can not get interface mac, abort packet..");
+ return null;
+ }
+ etherReply.setSourceMACAddress(relayAgentMac);
+
+ // find destMac
+ MacAddress clientMac = null;
+ Ip6Address peerAddress = Ip6Address.valueOf(dhcp6Relay.getPeerAddress());
+ Set<Host> clients = hostService.getHostsByIp(peerAddress);
+ if (clients.isEmpty()) {
+ log.warn("There's no host found for this address {}",
+ HexString.toHexString(dhcp6Relay.getPeerAddress(), ":"));
+ log.warn("Let's look up interfaceId {}", HexString.toHexString(peerMac.toBytes(), ":"));
+ clientMac = peerMac;
+ } else {
+ clientMac = clients.iterator().next().mac();
+ if (clientMac == null) {
+ log.warn("No client mac address found, abort packet...");
+ return null;
+ }
+ log.warn("Client mac address found from getHostByIp");
+
+ }
+ etherReply.setDestinationMACAddress(clientMac);
+
+ // ip header
+ ipv6Packet.setSourceAddress(dhcp6Relay.getLinkAddress());
+ ipv6Packet.setDestinationAddress(dhcp6Relay.getPeerAddress());
+ // udp header
+ udpPacket.setSourcePort(UDP.DHCP_V6_SERVER_PORT);
+ if (directConnFlag) {
+ udpPacket.setDestinationPort(UDP.DHCP_V6_CLIENT_PORT);
+ } else {
+ udpPacket.setDestinationPort(UDP.DHCP_V6_SERVER_PORT);
+ }
+
+ DHCP6 embeddedDhcp6 = dhcp6Relay.getOptions().stream()
+ .filter(opt -> opt instanceof Dhcp6RelayOption)
+ .map(BasePacket::getPayload)
+ .map(pld -> (DHCP6) pld)
+ .findFirst()
+ .orElse(null);
+
+
+ // add host or route
+ addHostOrRoute(directConnFlag, dhcp6Relay, embeddedDhcp6, clientMac, clientInterfaces);
+
+ udpPacket.setPayload(embeddedDhcp6);
+ udpPacket.resetChecksum();
+ ipv6Packet.setPayload(udpPacket);
+ etherReply.setPayload(ipv6Packet);
+
+ return new InternalPacket(etherReply, clientConnectionPoint);
+ }
+
+ // Returns the first v4 interface ip out of a set of interfaces or null.
+ // Checks all interfaces, and ignores v6 interface ips
+ private Ip6Address getRelayAgentIPv6Address(Set<Interface> intfs) {
+ for (Interface intf : intfs) {
+ for (InterfaceIpAddress ip : intf.ipAddressesList()) {
+ Ip6Address relayAgentIp = ip.ipAddress().getIp6Address();
+ if (relayAgentIp != null) {
+ return relayAgentIp;
+ }
+ }
+ }
+ return null;
}
@Override
public void setDefaultDhcpServerConfigs(Collection<DhcpServerConfig> configs) {
+ if (configs.size() == 0) {
+ // no config to update
+ return;
+ }
+
+ // TODO: currently we pick up first DHCP server config.
+ // Will use other server configs in the future for HA.
+ DhcpServerConfig serverConfig = configs.iterator().next();
+ if (!serverConfig.getDhcpServerConnectPoint().isPresent()) {
+ log.warn("Connect point not exists");
+ return;
+ }
+ if (!serverConfig.getDhcpServerIp6().isPresent()) {
+ log.warn("IP of DHCP6 server not exists");
+ return;
+ }
+ Ip6Address oldServerIp = this.dhcpServerIp;
+ Ip6Address oldGatewayIp = this.dhcpGatewayIp;
+
+ // stop monitoring gateway or server
+ if (oldGatewayIp != null) {
+ hostService.stopMonitoringIp(oldGatewayIp);
+ } else if (oldServerIp != null) {
+ hostService.stopMonitoringIp(oldServerIp);
+ }
+
+ this.dhcpServerConnectPoint = serverConfig.getDhcpServerConnectPoint().get();
+ this.dhcpServerIp = serverConfig.getDhcpServerIp6().get();
+ this.dhcpGatewayIp = serverConfig.getDhcpGatewayIp6().orElse(null);
+ this.relayAgentIpFromCfg = serverConfig.getRelayAgentIp6().orElse(null);
+
+
+ // reset server mac and vlan
+ this.dhcpConnectMac = null;
+ this.dhcpConnectVlan = null;
+
+ log.info("DHCP6 server connect point: " + this.dhcpServerConnectPoint);
+ log.info("DHCP6 server IP: " + this.dhcpServerIp);
+
+ IpAddress ipToProbe = MoreObjects.firstNonNull(this.dhcpGatewayIp, this.dhcpServerIp);
+ String hostToProbe = this.dhcpGatewayIp != null ? "gateway" : "DHCP6 server";
+
+ if (ipToProbe == null) {
+ log.warn("Server IP6 not set, can't probe it");
+ return;
+ }
+
+ log.info("Probing to resolve {} IP6 {}", hostToProbe, ipToProbe);
+ hostService.startMonitoringIp(ipToProbe);
+
+ Set<Host> hosts = hostService.getHostsByIp(ipToProbe);
+ if (!hosts.isEmpty()) {
+ Host host = hosts.iterator().next();
+ this.dhcpConnectVlan = host.vlan();
+ this.dhcpConnectMac = host.mac();
+ }
}
@Override
public void setIndirectDhcpServerConfigs(Collection<DhcpServerConfig> configs) {
+ if (configs.size() == 0) {
+ // no config to update
+ return;
+ }
+ // TODO: currently we pick up Second DHCP server config for indirect.
+ // Will use other server configs in the future for HA.
+ DhcpServerConfig serverConfig = configs.iterator().next();
+ checkState(serverConfig.getDhcpServerConnectPoint().isPresent(),
+ "Connect point not exists");
+ checkState(serverConfig.getDhcpServerIp6().isPresent(),
+ "IP of DHCP6 server not exists");
+ Ip6Address oldServerIp = this.indirectDhcpServerIp;
+ Ip6Address oldGatewayIp = this.indirectDhcpGatewayIp;
+
+ // stop monitoring gateway or server
+ if (oldGatewayIp != null) {
+ hostService.stopMonitoringIp(oldGatewayIp);
+ } else if (oldServerIp != null) {
+ hostService.stopMonitoringIp(oldServerIp);
+ }
+
+ this.indirectDhcpServerConnectPoint = serverConfig.getDhcpServerConnectPoint().get();
+ this.indirectDhcpServerIp = serverConfig.getDhcpServerIp6().get();
+ this.indirectDhcpGatewayIp = serverConfig.getDhcpGatewayIp6().orElse(null);
+ this.indirectRelayAgentIpFromCfg = serverConfig.getRelayAgentIp6().orElse(null);
+
+
+ // reset server mac and vlan
+ this.indirectDhcpConnectMac = null;
+ this.indirectDhcpConnectVlan = null;
+
+ log.info("DHCP6 server connect point: " + this.indirectDhcpServerConnectPoint);
+ log.info("DHCP6 server IP: " + this.indirectDhcpServerIp);
+
+ IpAddress ipToProbe = MoreObjects.firstNonNull(this.indirectDhcpGatewayIp, this.indirectDhcpServerIp);
+ String hostToProbe = this.indirectDhcpGatewayIp != null ? "gateway" : "DHCP6 server";
+
+ if (ipToProbe == null) {
+ log.warn("Server IP6 not set, can't probe it");
+ return;
+ }
+
+ log.info("Probing to resolve {} IP6 {}", hostToProbe, ipToProbe);
+ hostService.startMonitoringIp(ipToProbe);
+
+ Set<Host> hosts = hostService.getHostsByIp(ipToProbe);
+ if (!hosts.isEmpty()) {
+ Host host = hosts.iterator().next();
+ this.indirectDhcpConnectVlan = host.vlan();
+ this.indirectDhcpConnectMac = host.mac();
+ }
+ }
+
+ class InternalHostListener implements HostListener {
+ @Override
+ public void event(HostEvent event) {
+ switch (event.type()) {
+ case HOST_ADDED:
+ case HOST_UPDATED:
+ hostUpdated(event.subject());
+ break;
+ case HOST_REMOVED:
+ hostRemoved(event.subject());
+ break;
+ case HOST_MOVED:
+ hostMoved(event.subject());
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+ /**
+ * Handle host move.
+ * If the host DHCP server or gateway and it moved to the location different
+ * to user configured, unsets the connect mac and vlan
+ *
+ * @param host the host
+ */
+ private void hostMoved(Host host) {
+ if (this.dhcpServerConnectPoint == null && this.indirectDhcpServerConnectPoint == null) {
+ return;
+ }
+ if (this.dhcpGatewayIp != null) {
+ if (host.ipAddresses().contains(this.dhcpGatewayIp) &&
+ !host.locations().contains(this.dhcpServerConnectPoint)) {
+ this.dhcpConnectMac = null;
+ this.dhcpConnectVlan = null;
+ }
+ }
+ if (this.dhcpServerIp != null) {
+ if (host.ipAddresses().contains(this.dhcpServerIp) &&
+ !host.locations().contains(this.dhcpServerConnectPoint)) {
+ this.dhcpConnectMac = null;
+ this.dhcpConnectVlan = null;
+ }
+ }
+ if (this.indirectDhcpGatewayIp != null) {
+ if (host.ipAddresses().contains(this.indirectDhcpGatewayIp) &&
+ !host.locations().contains(this.indirectDhcpServerConnectPoint)) {
+ this.indirectDhcpConnectMac = null;
+ this.indirectDhcpConnectVlan = null;
+ }
+ }
+ if (this.indirectDhcpServerIp != null) {
+ if (host.ipAddresses().contains(this.indirectDhcpServerIp) &&
+ !host.locations().contains(this.indirectDhcpServerConnectPoint)) {
+ this.indirectDhcpConnectMac = null;
+ this.indirectDhcpConnectVlan = null;
+ }
+ }
+ }
+
+ /**
+ * Handle host updated.
+ * If the host is DHCP server or gateway, update connect mac and vlan.
+ *
+ * @param host the host
+ */
+ private void hostUpdated(Host host) {
+ if (this.dhcpGatewayIp != null) {
+ if (host.ipAddresses().contains(this.dhcpGatewayIp)) {
+ this.dhcpConnectMac = host.mac();
+ this.dhcpConnectVlan = host.vlan();
+ }
+ }
+ if (this.dhcpServerIp != null) {
+ if (host.ipAddresses().contains(this.dhcpServerIp)) {
+ this.dhcpConnectMac = host.mac();
+ this.dhcpConnectVlan = host.vlan();
+ }
+ }
+ if (this.indirectDhcpGatewayIp != null) {
+ if (host.ipAddresses().contains(this.indirectDhcpGatewayIp)) {
+ this.indirectDhcpConnectMac = host.mac();
+ this.indirectDhcpConnectVlan = host.vlan();
+ }
+ }
+ if (this.indirectDhcpServerIp != null) {
+ if (host.ipAddresses().contains(this.indirectDhcpServerIp)) {
+ this.indirectDhcpConnectMac = host.mac();
+ this.indirectDhcpConnectVlan = host.vlan();
+ }
+ }
+ }
+
+ /**
+ * Handle host removed.
+ * If the host is DHCP server or gateway, unset connect mac and vlan.
+ *
+ * @param host the host
+ */
+ private void hostRemoved(Host host) {
+ if (this.dhcpGatewayIp != null) {
+ if (host.ipAddresses().contains(this.dhcpGatewayIp)) {
+ this.dhcpConnectMac = null;
+ this.dhcpConnectVlan = null;
+ }
+ //return;
+ }
+ if (this.dhcpServerIp != null) {
+ if (host.ipAddresses().contains(this.dhcpServerIp)) {
+ this.dhcpConnectMac = null;
+ this.dhcpConnectVlan = null;
+ }
+ }
+ if (this.indirectDhcpGatewayIp != null) {
+ if (host.ipAddresses().contains(this.indirectDhcpGatewayIp)) {
+ this.indirectDhcpConnectMac = null;
+ this.indirectDhcpConnectVlan = null;
+ }
+ //return;
+ }
+ if (this.indirectDhcpServerIp != null) {
+ if (host.ipAddresses().contains(this.indirectDhcpServerIp)) {
+ this.indirectDhcpConnectMac = null;
+ this.indirectDhcpConnectVlan = null;
+ }
+ }
}
}
diff --git a/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/DhcpRelayManager.java b/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/DhcpRelayManager.java
index 1b50297..97b19e7 100644
--- a/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/DhcpRelayManager.java
+++ b/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/DhcpRelayManager.java
@@ -23,6 +23,7 @@
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Stream;
import com.google.common.collect.HashMultimap;
@@ -59,10 +60,15 @@
import org.onosproject.dhcprelay.config.IndirectDhcpRelayConfig;
import org.onosproject.dhcprelay.store.DhcpRecord;
import org.onosproject.dhcprelay.store.DhcpRelayStore;
+import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
import org.onosproject.dhcprelay.config.DhcpServerConfig;
import org.onosproject.net.Host;
+import org.onosproject.net.behaviour.Pipeliner;
import org.onosproject.net.config.Config;
+import org.onosproject.net.device.DeviceEvent;
+import org.onosproject.net.device.DeviceListener;
+import org.onosproject.net.device.DeviceService;
import org.onosproject.net.flow.criteria.Criterion;
import org.onosproject.net.flow.criteria.UdpPortCriterion;
import org.onosproject.net.flowobjective.DefaultForwardingObjective;
@@ -98,6 +104,9 @@
import com.google.common.collect.ImmutableSet;
import static org.onosproject.net.config.basics.SubjectFactories.APP_SUBJECT_FACTORY;
+import static org.onosproject.net.flowobjective.Objective.Operation.ADD;
+import static org.onosproject.net.flowobjective.Objective.Operation.REMOVE;
+
/**
* DHCP Relay Agent Application Component.
*/
@@ -106,8 +115,6 @@
public class DhcpRelayManager implements DhcpRelayService {
public static final String DHCP_RELAY_APP = "org.onosproject.dhcprelay";
public static final ProviderId PROVIDER_ID = new ProviderId("host", DHCP_RELAY_APP);
- public static final String HOST_LOCATION_PROVIDER =
- "org.onosproject.provider.host.impl.HostLocationProvider";
public static final String ROUTE_STORE_IMPL =
"org.onosproject.routeservice.store.RouteStoreImpl";
private static final TrafficSelector DHCP_SERVER_SELECTOR = DefaultTrafficSelector.builder()
@@ -197,19 +204,23 @@
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected FlowObjectiveService flowObjectiveService;
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected DeviceService deviceService;
+
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY,
- target = "(version=4)")
+ target = "(version=4)")
protected DhcpHandler v4Handler;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY,
- target = "(version=6)")
+ target = "(version=6)")
protected DhcpHandler v6Handler;
@Property(name = "arpEnabled", boolValue = true,
- label = "Enable Address resolution protocol")
+ label = "Enable Address resolution protocol")
protected boolean arpEnabled = true;
protected Multimap<DeviceId, VlanId> ignoredVlans = HashMultimap.create();
+ protected DeviceListener deviceListener = new InternalDeviceListener();
private DhcpRelayPacketProcessor dhcpRelayPacketProcessor = new DhcpRelayPacketProcessor();
private ApplicationId appId;
@@ -230,13 +241,12 @@
requestDhcpPackets();
modified(context);
- // disable dhcp from host location provider
- compCfgService.preSetProperty(HOST_LOCATION_PROVIDER,
- "useDhcp", Boolean.FALSE.toString());
// Enable distribute route store
compCfgService.preSetProperty(ROUTE_STORE_IMPL,
"distributed", Boolean.TRUE.toString());
compCfgService.registerProperties(getClass());
+
+ deviceService.addListener(deviceListener);
log.info("DHCP-RELAY Started");
}
@@ -247,8 +257,8 @@
packetService.removeProcessor(dhcpRelayPacketProcessor);
cancelDhcpPackets();
cancelArpPackets();
-
compCfgService.unregisterProperties(getClass(), false);
+ deviceService.removeListener(deviceListener);
log.info("DHCP-RELAY Stopped");
}
@@ -309,7 +319,7 @@
v6Handler.setDefaultDhcpServerConfigs(defaultConfig.dhcpServerConfigs());
}
if (config instanceof IgnoreDhcpConfig) {
- addIgnoreVlanRules((IgnoreDhcpConfig) config);
+ updateIgnoreVlanRules((IgnoreDhcpConfig) config);
}
}
@@ -322,93 +332,103 @@
v6Handler.setDefaultDhcpServerConfigs(Collections.emptyList());
}
if (config instanceof IgnoreDhcpConfig) {
- ignoredVlans.forEach(this::removeIgnoreVlanRule);
- ignoredVlans.clear();
+ ignoredVlans.forEach(((deviceId, vlanId) -> {
+ processIgnoreVlanRule(deviceId, vlanId, REMOVE);
+ }));
}
}
- private void addIgnoreVlanRules(IgnoreDhcpConfig config) {
+ private void updateIgnoreVlanRules(IgnoreDhcpConfig config) {
config.ignoredVlans().forEach((deviceId, vlanId) -> {
if (ignoredVlans.get(deviceId).contains(vlanId)) {
// don't need to process if it already ignored
return;
}
- installIgnoreVlanRule(deviceId, vlanId);
- ignoredVlans.put(deviceId, vlanId);
+ processIgnoreVlanRule(deviceId, vlanId, ADD);
});
- Multimap<DeviceId, VlanId> removedVlans = HashMultimap.create();
ignoredVlans.forEach((deviceId, vlanId) -> {
if (!config.ignoredVlans().get(deviceId).contains(vlanId)) {
// not contains in new config, remove it
- removeIgnoreVlanRule(deviceId, vlanId);
- removedVlans.put(deviceId, vlanId);
-
+ processIgnoreVlanRule(deviceId, vlanId, REMOVE);
}
});
- removedVlans.forEach(ignoredVlans::remove);
}
- private void installIgnoreVlanRule(DeviceId deviceId, VlanId vlanId) {
+ /**
+ * Process the ignore rules.
+ *
+ * @param deviceId the device id
+ * @param vlanId the vlan to be ignored
+ * @param op the operation, ADD to install; REMOVE to uninstall rules
+ */
+ private void processIgnoreVlanRule(DeviceId deviceId, VlanId vlanId, Objective.Operation op) {
TrafficTreatment dropTreatment = DefaultTrafficTreatment.emptyTreatment();
dropTreatment.clearedDeferred();
+ AtomicInteger installedCount = new AtomicInteger(DHCP_SELECTORS.size());
DHCP_SELECTORS.forEach(trafficSelector -> {
UdpPortCriterion udpDst = (UdpPortCriterion) trafficSelector.getCriterion(Criterion.Type.UDP_DST);
+ int udpDstPort = udpDst.udpPort().toInt();
TrafficSelector selector = DefaultTrafficSelector.builder(trafficSelector)
.matchVlanId(vlanId)
.build();
- ForwardingObjective fwd = DefaultForwardingObjective.builder()
+ ForwardingObjective.Builder builder = DefaultForwardingObjective.builder()
.withFlag(ForwardingObjective.Flag.VERSATILE)
.withSelector(selector)
.withPriority(IGNORE_CONTROL_PRIORITY)
.withTreatment(dropTreatment)
- .fromApp(appId)
- .add(new ObjectiveContext() {
- @Override
- public void onSuccess(Objective objective) {
- log.info("Vlan id {} from device {} ignored (UDP port {})",
- vlanId, deviceId, udpDst.udpPort().toInt());
- }
+ .fromApp(appId);
- @Override
- public void onError(Objective objective, ObjectiveError error) {
- log.warn("Can't ignore vlan id {} from device {} due to {}",
- vlanId, deviceId, error);
- }
- });
- flowObjectiveService.apply(deviceId, fwd);
- });
- }
- private void removeIgnoreVlanRule(DeviceId deviceId, VlanId vlanId) {
- TrafficTreatment dropTreatment = DefaultTrafficTreatment.emptyTreatment();
- dropTreatment.clearedDeferred();
- DHCP_SELECTORS.forEach(trafficSelector -> {
- UdpPortCriterion udpDst = (UdpPortCriterion) trafficSelector.getCriterion(Criterion.Type.UDP_DST);
- TrafficSelector selector = DefaultTrafficSelector.builder(trafficSelector)
- .matchVlanId(vlanId)
- .build();
+ ObjectiveContext objectiveContext = new ObjectiveContext() {
+ @Override
+ public void onSuccess(Objective objective) {
+ log.info("Ignore rule {} (Vlan id {}, device {}, UDP dst {})",
+ op, vlanId, deviceId, udpDstPort);
+ int countDown = installedCount.decrementAndGet();
+ if (countDown != 0) {
+ return;
+ }
+ switch (op) {
+ case ADD:
- ForwardingObjective fwd = DefaultForwardingObjective.builder()
- .withFlag(ForwardingObjective.Flag.VERSATILE)
- .withSelector(selector)
- .withPriority(IGNORE_CONTROL_PRIORITY)
- .withTreatment(dropTreatment)
- .fromApp(appId)
- .remove(new ObjectiveContext() {
- @Override
- public void onSuccess(Objective objective) {
- log.info("Vlan id {} from device {} ignore rule removed (UDP port {})",
- vlanId, deviceId, udpDst.udpPort().toInt());
- }
+ ignoredVlans.put(deviceId, vlanId);
+ break;
+ case REMOVE:
+ ignoredVlans.remove(deviceId, vlanId);
+ break;
+ default:
+ log.warn("Unsupported objective operation {}", op);
+ break;
+ }
+ }
- @Override
- public void onError(Objective objective, ObjectiveError error) {
- log.warn("Can't remove ignore rule of vlan id {} from device {} due to {}",
- vlanId, deviceId, error);
- }
- });
+ @Override
+ public void onError(Objective objective, ObjectiveError error) {
+ log.warn("Can't {} ignore rule (vlan id {}, udp dst {}, device {}) due to {}",
+ op, vlanId, udpDstPort, deviceId, error);
+ }
+ };
+
+ ForwardingObjective fwd;
+ switch (op) {
+ case ADD:
+ fwd = builder.add(objectiveContext);
+ break;
+ case REMOVE:
+ fwd = builder.remove(objectiveContext);
+ break;
+ default:
+ log.warn("Unsupported objective operation {}", op);
+ return;
+ }
+
+ Device device = deviceService.getDevice(deviceId);
+ if (device == null || !device.is(Pipeliner.class)) {
+ log.warn("Device {} is not available now, wait until device is available", deviceId);
+ return;
+ }
flowObjectiveService.apply(deviceId, fwd);
});
}
@@ -620,4 +640,41 @@
}
}
+
+ private class InternalDeviceListener implements DeviceListener {
+
+ @Override
+ public void event(DeviceEvent event) {
+ Device device = event.subject();
+ switch (event.type()) {
+ case DEVICE_ADDED:
+ deviceAdd(device.id());
+ break;
+ case DEVICE_REMOVED:
+ ignoredVlans.removeAll(device.id());
+ break;
+ case DEVICE_AVAILABILITY_CHANGED:
+ deviceAvailabilityChanged(device);
+
+ default:
+ break;
+ }
+ }
+
+ private void deviceAvailabilityChanged(Device device) {
+ if (deviceService.isAvailable(device.id())) {
+ deviceAdd(device.id());
+ } else {
+ ignoredVlans.removeAll(device.id());
+ }
+ }
+
+ private void deviceAdd(DeviceId deviceId) {
+ IgnoreDhcpConfig config = cfgService.getConfig(appId, IgnoreDhcpConfig.class);
+ Collection<VlanId> vlanIds = config.ignoredVlans().get(deviceId);
+ vlanIds.forEach(vlanId -> {
+ processIgnoreVlanRule(deviceId, vlanId, ADD);
+ });
+ }
+ }
}
diff --git a/apps/dhcprelay/src/test/java/org/onosproject/dhcprelay/DhcpRelayManagerTest.java b/apps/dhcprelay/src/test/java/org/onosproject/dhcprelay/DhcpRelayManagerTest.java
index 4494ddb..f45555d 100644
--- a/apps/dhcprelay/src/test/java/org/onosproject/dhcprelay/DhcpRelayManagerTest.java
+++ b/apps/dhcprelay/src/test/java/org/onosproject/dhcprelay/DhcpRelayManagerTest.java
@@ -36,6 +36,8 @@
import org.onlab.packet.Ethernet;
import org.onlab.packet.IPv4;
import org.onlab.packet.Ip4Address;
+import org.onlab.packet.Ip6Address;
+import org.onlab.packet.IpPrefix;
import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
import org.onlab.packet.UDP;
@@ -43,11 +45,18 @@
import org.onlab.packet.dhcp.CircuitId;
import org.onlab.packet.dhcp.DhcpOption;
import org.onlab.packet.dhcp.DhcpRelayAgentOption;
+import org.onlab.packet.dhcp.Dhcp6InterfaceIdOption;
+import org.onlab.packet.dhcp.Dhcp6RelayOption;
+import org.onlab.packet.dhcp.Dhcp6IaNaOption;
+import org.onlab.packet.dhcp.Dhcp6IaPdOption;
+import org.onlab.packet.dhcp.Dhcp6IaAddressOption;
+import org.onlab.packet.dhcp.Dhcp6IaPrefixOption;
+import org.onlab.packet.dhcp.Dhcp6Option;
+import org.onosproject.net.ConnectPoint;
import org.onosproject.TestApplicationId;
import org.onosproject.cfg.ComponentConfigService;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
-import org.onosproject.dhcprelay.api.DhcpHandler;
import org.onosproject.dhcprelay.config.DefaultDhcpRelayConfig;
import org.onosproject.dhcprelay.config.DhcpServerConfig;
import org.onosproject.dhcprelay.config.IgnoreDhcpConfig;
@@ -55,7 +64,11 @@
import org.onosproject.dhcprelay.store.DhcpRecord;
import org.onosproject.dhcprelay.store.DhcpRelayStore;
import org.onosproject.dhcprelay.store.DhcpRelayStoreEvent;
+import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
+import org.onosproject.net.behaviour.Pipeliner;
+import org.onosproject.net.device.DeviceEvent;
+import org.onosproject.net.device.DeviceService;
import org.onosproject.net.flow.DefaultTrafficSelector;
import org.onosproject.net.flow.DefaultTrafficTreatment;
import org.onosproject.net.flow.TrafficSelector;
@@ -63,21 +76,19 @@
import org.onosproject.net.flowobjective.FlowObjectiveService;
import org.onosproject.net.flowobjective.ForwardingObjective;
import org.onosproject.net.flowobjective.Objective;
+import org.onosproject.net.host.HostProviderService;
import org.onosproject.net.intf.Interface;
import org.onosproject.net.intf.InterfaceServiceAdapter;
import org.onosproject.net.packet.PacketPriority;
import org.onosproject.routeservice.Route;
import org.onosproject.routeservice.RouteStoreAdapter;
-import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DefaultHost;
import org.onosproject.net.Host;
import org.onosproject.net.HostId;
import org.onosproject.net.HostLocation;
import org.onosproject.net.config.NetworkConfigRegistry;
import org.onosproject.net.host.HostDescription;
-import org.onosproject.net.host.HostEvent;
import org.onosproject.net.host.HostService;
-import org.onosproject.net.host.HostStoreAdapter;
import org.onosproject.net.host.InterfaceIpAddress;
import org.onosproject.net.packet.DefaultInboundPacket;
import org.onosproject.net.packet.InboundPacket;
@@ -86,14 +97,17 @@
import org.onosproject.net.packet.PacketContextAdapter;
import org.onosproject.net.packet.PacketProcessor;
import org.onosproject.net.packet.PacketServiceAdapter;
-import org.onosproject.net.provider.ProviderId;
import org.onosproject.store.StoreDelegate;
import org.osgi.service.component.ComponentContext;
+import org.onlab.packet.DHCP6;
+import org.onlab.packet.IPv6;
+import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.Collection;
import java.util.Dictionary;
import java.util.List;
+import java.util.ArrayList;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
@@ -102,6 +116,7 @@
import static org.easymock.EasyMock.*;
import static org.junit.Assert.*;
import static org.onosproject.dhcprelay.DhcpRelayManager.DHCP_RELAY_APP;
+import static org.onosproject.dhcprelay.DhcpRelayManager.DHCP_SELECTORS;
public class DhcpRelayManagerTest {
private static final String CONFIG_FILE_PATH = "dhcp-relay.json";
@@ -109,20 +124,40 @@
private static final DeviceId DEV_2_ID = DeviceId.deviceId("of:0000000000000002");
// Ip address for interfaces
private static final InterfaceIpAddress INTERFACE_IP = InterfaceIpAddress.valueOf("10.0.3.254/32");
- private static final List<InterfaceIpAddress> INTERFACE_IPS = ImmutableList.of(INTERFACE_IP);
+ private static final InterfaceIpAddress INTERFACE_IP_V6 = InterfaceIpAddress.valueOf("2001:db8:1::254/128");
+ private static final List<InterfaceIpAddress> INTERFACE_IPS = ImmutableList.of(INTERFACE_IP, INTERFACE_IP_V6);
// DHCP client (will send without option 82)
private static final Ip4Address IP_FOR_CLIENT = Ip4Address.valueOf("10.0.0.1");
+ private static final Ip6Address IP_FOR_CLIENT_V6 = Ip6Address.valueOf("2001:db8:1::110");
+ private static final IpPrefix PREFIX_FOR_CLIENT_V6 = IpPrefix.valueOf("2001:db8:10::/56");
+ private static final IpPrefix PREFIX_FOR_ZERO = IpPrefix.valueOf("::/0");
private static final MacAddress CLIENT_MAC = MacAddress.valueOf("00:00:00:00:00:01");
private static final VlanId CLIENT_VLAN = VlanId.vlanId("100");
private static final ConnectPoint CLIENT_CP = ConnectPoint.deviceConnectPoint("of:0000000000000001/1");
private static final MacAddress CLIENT_IFACE_MAC = MacAddress.valueOf("00:00:00:00:11:01");
+ private static final HostLocation CLIENT_LOCATION = new HostLocation(CLIENT_CP, 0);
+ private static final HostId CLIENT_HOST_ID = HostId.hostId(CLIENT_MAC, CLIENT_VLAN);
+ private static final Ip6Address CLIENT_LL_IP_V6 = Ip6Address.valueOf("fe80::200:00ff:fe00:0001");
+ private static final Host EXISTS_HOST = new DefaultHost(DhcpRelayManager.PROVIDER_ID,
+ CLIENT_HOST_ID, CLIENT_MAC, CLIENT_VLAN,
+ CLIENT_LOCATION, ImmutableSet.of(CLIENT_LL_IP_V6));
private static final Interface CLIENT_INTERFACE = new Interface("C1",
CLIENT_CP,
INTERFACE_IPS,
CLIENT_IFACE_MAC,
CLIENT_VLAN);
+ // Dual homing test
+ private static final ConnectPoint CLIENT_DH_CP = ConnectPoint.deviceConnectPoint("of:0000000000000001/3");
+ private static final HostLocation CLIENT_DH_LOCATION = new HostLocation(CLIENT_DH_CP, 0);
+ private static final Interface CLIENT_DH_INTERFACE = new Interface("C1-DH",
+ CLIENT_DH_CP,
+ INTERFACE_IPS,
+ CLIENT_IFACE_MAC,
+ CLIENT_VLAN);
+
+
// DHCP client 2 (will send with option 82, so the vlan should equals to vlan from server)
private static final MacAddress CLIENT2_MAC = MacAddress.valueOf("00:00:00:00:00:01");
private static final VlanId CLIENT2_VLAN = VlanId.NONE;
@@ -136,7 +171,8 @@
// Outer relay information
private static final Ip4Address OUTER_RELAY_IP = Ip4Address.valueOf("10.0.5.253");
- private static final Set<IpAddress> OUTER_RELAY_IPS = ImmutableSet.of(OUTER_RELAY_IP);
+ private static final Ip6Address OUTER_RELAY_IP_V6 = Ip6Address.valueOf("2001:db8:1::4");
+ private static final Set<IpAddress> OUTER_RELAY_IPS = ImmutableSet.of(OUTER_RELAY_IP, OUTER_RELAY_IP_V6);
private static final MacAddress OUTER_RELAY_MAC = MacAddress.valueOf("00:01:02:03:04:05");
private static final VlanId OUTER_RELAY_VLAN = VlanId.NONE;
private static final ConnectPoint OUTER_RELAY_CP = ConnectPoint.deviceConnectPoint("of:0000000000000001/2");
@@ -156,8 +192,12 @@
ConnectPoint.deviceConnectPoint("of:0000000000000001/5");
private static final HostLocation SERVER_LOCATION =
new HostLocation(SERVER_CONNECT_POINT, 0);
+ private static final Ip4Address GATEWAY_IP = Ip4Address.valueOf("10.0.5.253");
+ private static final Ip6Address GATEWAY_IP_V6 = Ip6Address.valueOf("2000::105:253");
private static final Ip4Address SERVER_IP = Ip4Address.valueOf("10.0.3.253");
- private static final Set<IpAddress> DHCP_SERVER_IPS = ImmutableSet.of(SERVER_IP);
+ private static final Ip6Address SERVER_IP_V6 = Ip6Address.valueOf("2000::103:253");
+ private static final Ip6Address SERVER_IP_V6_MCAST = Ip6Address.valueOf("ff02::1:2");
+ private static final Set<IpAddress> DHCP_SERVER_IPS = ImmutableSet.of(SERVER_IP, SERVER_IP_V6);
private static final HostId SERVER_HOST_ID = HostId.hostId(SERVER_MAC, SERVER_VLAN);
private static final Host SERVER_HOST = new DefaultHost(DhcpRelayManager.PROVIDER_ID,
SERVER_HOST_ID,
@@ -178,10 +218,12 @@
// Components
private static final ApplicationId APP_ID = TestApplicationId.create(DhcpRelayManager.DHCP_RELAY_APP);
private static final DefaultDhcpRelayConfig CONFIG = new MockDefaultDhcpRelayConfig();
+ private static final IndirectDhcpRelayConfig CONFIG_INDIRECT = new MockIndirectDhcpRelayConfig();
private static final Set<Interface> INTERFACES = ImmutableSet.of(
CLIENT_INTERFACE,
CLIENT2_INTERFACE,
- SERVER_INTERFACE
+ SERVER_INTERFACE,
+ CLIENT_DH_INTERFACE
);
private static final String NON_ONOS_CID = "Non-ONOS circuit ID";
private static final VlanId IGNORED_VLAN = VlanId.vlanId("100");
@@ -189,9 +231,9 @@
private DhcpRelayManager manager;
private MockPacketService packetService;
- private MockHostStore mockHostStore;
private MockRouteStore mockRouteStore;
private MockDhcpRelayStore mockDhcpRelayStore;
+ private HostProviderService mockHostProviderService;
@Before
public void setup() {
@@ -204,7 +246,7 @@
// TODO: add indirect test
expect(manager.cfgService.getConfig(APP_ID, IndirectDhcpRelayConfig.class))
- .andReturn(null)
+ .andReturn(CONFIG_INDIRECT)
.anyTimes();
manager.coreService = createNiceMock(CoreService.class);
@@ -218,26 +260,40 @@
packetService = new MockPacketService();
manager.packetService = packetService;
manager.compCfgService = createNiceMock(ComponentConfigService.class);
+ manager.deviceService = createNiceMock(DeviceService.class);
- mockHostStore = new MockHostStore();
+ Device device = createNiceMock(Device.class);
+ expect(device.is(Pipeliner.class)).andReturn(true).anyTimes();
+
+ expect(manager.deviceService.getDevice(DEV_1_ID)).andReturn(device).anyTimes();
+ expect(manager.deviceService.getDevice(DEV_2_ID)).andReturn(device).anyTimes();
+ replay(manager.deviceService, device);
+
mockRouteStore = new MockRouteStore();
mockDhcpRelayStore = new MockDhcpRelayStore();
manager.dhcpRelayStore = mockDhcpRelayStore;
manager.interfaceService = new MockInterfaceService();
manager.flowObjectiveService = EasyMock.niceMock(FlowObjectiveService.class);
-
+ mockHostProviderService = createNiceMock(HostProviderService.class);
Dhcp4HandlerImpl v4Handler = new Dhcp4HandlerImpl();
+ v4Handler.providerService = mockHostProviderService;
v4Handler.dhcpRelayStore = mockDhcpRelayStore;
v4Handler.hostService = manager.hostService;
- v4Handler.hostStore = mockHostStore;
v4Handler.interfaceService = manager.interfaceService;
v4Handler.packetService = manager.packetService;
v4Handler.routeStore = mockRouteStore;
manager.v4Handler = v4Handler;
// TODO: initialize v6 handler.
- DhcpHandler v6Handler = createNiceMock(DhcpHandler.class);
+ //DhcpHandler v6Handler = createNiceMock(DhcpHandler.class);
+ Dhcp6HandlerImpl v6Handler = new Dhcp6HandlerImpl();
+ v6Handler.dhcpRelayStore = mockDhcpRelayStore;
+ v6Handler.hostService = manager.hostService;
+ v6Handler.interfaceService = manager.interfaceService;
+ v6Handler.packetService = manager.packetService;
+ v6Handler.routeStore = mockRouteStore;
+ v6Handler.providerService = mockHostProviderService;
manager.v6Handler = v6Handler;
// properties
@@ -262,33 +318,36 @@
*/
@Test
public void relayDhcpWithoutAgentInfo() {
+ replay(mockHostProviderService);
// send request
packetService.processPacket(new TestDhcpRequestPacketContext(CLIENT_MAC,
CLIENT_VLAN,
CLIENT_CP,
INTERFACE_IP.ipAddress().getIp4Address(),
false));
+ // won't trigger the host provider service
+ verify(mockHostProviderService);
+ reset(mockHostProviderService);
- Set<Host> hosts = ImmutableSet.copyOf(mockHostStore.getHosts());
- assertEquals(0, hosts.size());
assertEquals(0, mockRouteStore.routes.size());
+ HostId expectHostId = HostId.hostId(CLIENT_MAC, CLIENT_VLAN);
+ Capture<HostDescription> capturedHostDesc = newCapture();
+ mockHostProviderService.hostDetected(eq(expectHostId), capture(capturedHostDesc), eq(false));
+ replay(mockHostProviderService);
// send ack
packetService.processPacket(new TestDhcpAckPacketContext(CLIENT_CP, CLIENT_MAC,
CLIENT_VLAN, INTERFACE_IP.ipAddress().getIp4Address(),
false));
- hosts = ImmutableSet.copyOf(mockHostStore.getHosts());
- assertEquals(1, hosts.size());
+ verify(mockHostProviderService);
assertEquals(0, mockRouteStore.routes.size());
- Host host = hosts.iterator().next();
- assertEquals(CLIENT_MAC, host.mac());
- assertEquals(CLIENT_VLAN, host.vlan());
+ HostDescription host = capturedHostDesc.getValue();
+ assertEquals(false, host.configured());
assertEquals(CLIENT_CP.deviceId(), host.location().elementId());
assertEquals(CLIENT_CP.port(), host.location().port());
- assertEquals(1, host.ipAddresses().size());
- assertEquals(IP_FOR_CLIENT, host.ipAddresses().iterator().next());
- assertEquals(HostId.hostId(CLIENT_MAC, CLIENT_VLAN), host.id());
+ assertEquals(1, host.ipAddress().size());
+ assertEquals(IP_FOR_CLIENT, host.ipAddress().iterator().next());
}
/**
@@ -296,6 +355,7 @@
*/
@Test
public void relayDhcpWithAgentInfo() {
+ replay(mockHostProviderService);
// Assume outer dhcp relay agent exists in store already
// send request
packetService.processPacket(new TestDhcpRequestPacketContext(CLIENT2_MAC,
@@ -303,11 +363,8 @@
CLIENT2_CP,
INTERFACE_IP.ipAddress().getIp4Address(),
true));
-
- Set<Host> hosts = ImmutableSet.copyOf(mockHostStore.getHosts());
- assertEquals(0, hosts.size());
+ // No routes
assertEquals(0, mockRouteStore.routes.size());
-
// send ack
packetService.processPacket(new TestDhcpAckPacketContext(CLIENT2_CP,
CLIENT2_MAC,
@@ -315,8 +372,10 @@
INTERFACE_IP.ipAddress().getIp4Address(),
true));
- hosts = ImmutableSet.copyOf(mockHostStore.getHosts());
- assertEquals(0, hosts.size());
+ // won't trigger the host provider service
+ verify(mockHostProviderService);
+ reset(mockHostProviderService);
+
assertEquals(1, mockRouteStore.routes.size());
Route route = mockRouteStore.routes.get(0);
@@ -372,10 +431,10 @@
Capture<Objective> capturedFromDev1 = newCapture(CaptureType.ALL);
manager.flowObjectiveService.apply(eq(DEV_1_ID), capture(capturedFromDev1));
- expectLastCall().times(2);
+ expectLastCall().times(DHCP_SELECTORS.size());
Capture<Objective> capturedFromDev2 = newCapture(CaptureType.ALL);
manager.flowObjectiveService.apply(eq(DEV_2_ID), capture(capturedFromDev2));
- expectLastCall().times(2);
+ expectLastCall().times(DHCP_SELECTORS.size());
replay(manager.flowObjectiveService);
manager.updateConfig(config);
verify(manager.flowObjectiveService);
@@ -399,8 +458,11 @@
assertEquals(IGNORE_CONTROL_PRIORITY, fwd.priority());
assertEquals(ForwardingObjective.Flag.VERSATILE, fwd.flag());
assertEquals(Objective.Operation.ADD, fwd.op());
+ fwd.context().ifPresent(ctx -> {
+ ctx.onSuccess(fwd);
+ });
}
-
+ objectivesFromDev2.forEach(obj -> obj.context().ifPresent(ctx -> ctx.onSuccess(obj)));
assertEquals(2, manager.ignoredVlans.size());
}
@@ -415,10 +477,10 @@
Capture<Objective> capturedFromDev1 = newCapture(CaptureType.ALL);
manager.flowObjectiveService.apply(eq(DEV_1_ID), capture(capturedFromDev1));
- expectLastCall().times(2);
+ expectLastCall().times(DHCP_SELECTORS.size());
Capture<Objective> capturedFromDev2 = newCapture(CaptureType.ALL);
manager.flowObjectiveService.apply(eq(DEV_2_ID), capture(capturedFromDev2));
- expectLastCall().times(2);
+ expectLastCall().times(DHCP_SELECTORS.size());
replay(manager.flowObjectiveService);
manager.removeConfig(config);
verify(manager.flowObjectiveService);
@@ -442,10 +504,202 @@
assertEquals(IGNORE_CONTROL_PRIORITY, fwd.priority());
assertEquals(ForwardingObjective.Flag.VERSATILE, fwd.flag());
assertEquals(Objective.Operation.REMOVE, fwd.op());
+ fwd.context().ifPresent(ctx -> {
+ ctx.onSuccess(fwd);
+ });
}
+ objectivesFromDev2.forEach(obj -> obj.context().ifPresent(ctx -> ctx.onSuccess(obj)));
assertEquals(0, manager.ignoredVlans.size());
}
+ /**
+ * Should ignore ignore rules installation when device not available.
+ */
+ @Test
+ public void testIgnoreUnknownDevice() throws IOException {
+ reset(manager.deviceService);
+ Device device = createNiceMock(Device.class);
+ expect(device.is(Pipeliner.class)).andReturn(true).anyTimes();
+
+ expect(manager.deviceService.getDevice(DEV_1_ID)).andReturn(device).anyTimes();
+ expect(manager.deviceService.getDevice(DEV_2_ID)).andReturn(null).anyTimes();
+
+ ObjectMapper om = new ObjectMapper();
+ JsonNode json = om.readTree(Resources.getResource(CONFIG_FILE_PATH));
+ IgnoreDhcpConfig config = new IgnoreDhcpConfig();
+ json = json.path("apps").path(DHCP_RELAY_APP).path(IgnoreDhcpConfig.KEY);
+ config.init(APP_ID, IgnoreDhcpConfig.KEY, json, om, null);
+
+ Capture<Objective> capturedFromDev1 = newCapture(CaptureType.ALL);
+ manager.flowObjectiveService.apply(eq(DEV_1_ID), capture(capturedFromDev1));
+ expectLastCall().times(DHCP_SELECTORS.size());
+ replay(manager.flowObjectiveService, manager.deviceService, device);
+
+ manager.updateConfig(config);
+ capturedFromDev1.getValues().forEach(obj -> obj.context().ifPresent(ctx -> ctx.onSuccess(obj)));
+
+ assertEquals(1, manager.ignoredVlans.size());
+ }
+
+ /**
+ * Should try install ignore rules when device comes up.
+ */
+ @Test
+ public void testInstallIgnoreRuleWhenDeviceComesUp() throws IOException {
+ ObjectMapper om = new ObjectMapper();
+ JsonNode json = om.readTree(Resources.getResource(CONFIG_FILE_PATH));
+ IgnoreDhcpConfig config = new IgnoreDhcpConfig();
+ json = json.path("apps").path(DHCP_RELAY_APP).path(IgnoreDhcpConfig.KEY);
+ config.init(APP_ID, IgnoreDhcpConfig.KEY, json, om, null);
+
+ reset(manager.cfgService, manager.flowObjectiveService, manager.deviceService);
+ expect(manager.cfgService.getConfig(APP_ID, IgnoreDhcpConfig.class))
+ .andReturn(config).anyTimes();
+
+ Device device = createNiceMock(Device.class);
+ expect(device.is(Pipeliner.class)).andReturn(true).anyTimes();
+ expect(device.id()).andReturn(DEV_1_ID).anyTimes();
+ expect(manager.deviceService.getDevice(DEV_1_ID)).andReturn(device).anyTimes();
+ DeviceEvent event = new DeviceEvent(DeviceEvent.Type.DEVICE_ADDED, device);
+ Capture<Objective> capturedFromDev1 = newCapture(CaptureType.ALL);
+ manager.flowObjectiveService.apply(eq(DEV_1_ID), capture(capturedFromDev1));
+ expectLastCall().times(DHCP_SELECTORS.size());
+ replay(manager.cfgService, manager.flowObjectiveService, manager.deviceService, device);
+ assertEquals(0, manager.ignoredVlans.size());
+ manager.deviceListener.event(event);
+ capturedFromDev1.getValues().forEach(obj -> obj.context().ifPresent(ctx -> ctx.onSuccess(obj)));
+ assertEquals(1, manager.ignoredVlans.size());
+ }
+
+ /**
+ * Relay a DHCP6 packet without relay option
+ * Note: Should add new host to host store after dhcp ack.
+ */
+ @Test
+ public void relayDhcp6WithoutAgentInfo() {
+ replay(mockHostProviderService);
+ // send request
+ packetService.processPacket(new TestDhcp6RequestPacketContext(CLIENT_MAC,
+ VlanId.NONE,
+ CLIENT_CP,
+ INTERFACE_IP_V6.ipAddress().getIp6Address(),
+ 0));
+
+ verify(mockHostProviderService);
+ reset(mockHostProviderService);
+ assertEquals(0, mockRouteStore.routes.size());
+
+ Capture<HostDescription> capturedHostDesc = newCapture();
+ mockHostProviderService.hostDetected(eq(HostId.hostId(CLIENT_MAC, CLIENT_VLAN)),
+ capture(capturedHostDesc), eq(false));
+ replay(mockHostProviderService);
+ // send reply
+ packetService.processPacket(new TestDhcp6ReplyPacketContext(CLIENT_CP, CLIENT_MAC,
+ CLIENT_VLAN,
+ INTERFACE_IP_V6.ipAddress().getIp6Address(),
+ 0));
+ verify(mockHostProviderService);
+ assertEquals(0, mockRouteStore.routes.size());
+
+ HostDescription host = capturedHostDesc.getValue();
+ assertEquals(CLIENT_VLAN, host.vlan());
+ assertEquals(CLIENT_CP.deviceId(), host.location().elementId());
+ assertEquals(CLIENT_CP.port(), host.location().port());
+ assertEquals(1, host.ipAddress().size());
+ assertEquals(IP_FOR_CLIENT_V6, host.ipAddress().iterator().next());
+ }
+
+ /**
+ * Relay a DHCP6 packet with Relay Message opion (Indirectly connected host).
+ */
+ @Test
+ public void relayDhcp6WithAgentInfo() {
+ replay(mockHostProviderService);
+ // Assume outer dhcp6 relay agent exists in store already
+ // send request
+ packetService.processPacket(new TestDhcp6RequestPacketContext(CLIENT2_MAC,
+ CLIENT2_VLAN,
+ CLIENT2_CP,
+ INTERFACE_IP_V6.ipAddress().getIp6Address(),
+ 1));
+
+ assertEquals(0, mockRouteStore.routes.size());
+
+ // send reply
+ packetService.processPacket(new TestDhcp6ReplyPacketContext(CLIENT2_CP,
+ CLIENT2_MAC,
+ CLIENT2_VLAN,
+ INTERFACE_IP_V6.ipAddress().getIp6Address(),
+ 1));
+
+ // won't trigger the host provider service
+ verify(mockHostProviderService);
+ reset(mockHostProviderService);
+ assertEquals(2, mockRouteStore.routes.size()); // ipAddress and prefix
+
+ Route route = mockRouteStore.routes.get(0);
+ assertEquals(OUTER_RELAY_IP_V6, route.nextHop());
+ assertEquals(IP_FOR_CLIENT_V6.toIpPrefix(), route.prefix());
+ assertEquals(Route.Source.STATIC, route.source());
+ }
+
+ @Test
+ public void testDhcp4DualHome() {
+ PacketContext packetContext =
+ new TestDhcpAckPacketContext(CLIENT_DH_CP, CLIENT_MAC, CLIENT_VLAN,
+ INTERFACE_IP.ipAddress().getIp4Address(),
+ false);
+ reset(manager.hostService);
+ expect(manager.hostService.getHost(CLIENT_HOST_ID)).andReturn(EXISTS_HOST).anyTimes();
+ Capture<HostDescription> capturedHostDesc = newCapture();
+ mockHostProviderService.hostDetected(eq(CLIENT_HOST_ID), capture(capturedHostDesc), eq(false));
+ replay(mockHostProviderService, manager.hostService);
+ packetService.processPacket(packetContext);
+ verify(mockHostProviderService);
+
+ HostDescription hostDesc = capturedHostDesc.getValue();
+ Set<HostLocation> hostLocations = hostDesc.locations();
+ assertEquals(2, hostLocations.size());
+ assertTrue(hostLocations.contains(CLIENT_LOCATION));
+ assertTrue(hostLocations.contains(CLIENT_DH_LOCATION));
+ }
+
+ @Test
+ public void testDhcp6DualHome() {
+ PacketContext packetContext =
+ new TestDhcp6ReplyPacketContext(CLIENT_DH_CP, CLIENT_MAC, CLIENT_VLAN,
+ INTERFACE_IP_V6.ipAddress().getIp6Address(),
+ 0);
+ reset(manager.hostService);
+ expect(manager.hostService.getHostsByIp(CLIENT_LL_IP_V6)).andReturn(ImmutableSet.of(EXISTS_HOST)).anyTimes();
+
+ // FIXME: currently DHCPv6 has a bug, we can't get correct vlan of client......
+ // XXX: The vlan relied from DHCP6 handler might be wrong, do hack here
+ HostId hostId = HostId.hostId(CLIENT_MAC, VlanId.NONE);
+ expect(manager.hostService.getHost(hostId)).andReturn(EXISTS_HOST).anyTimes();
+
+ // XXX: sometimes this will work, sometimes not
+ expect(manager.hostService.getHost(CLIENT_HOST_ID)).andReturn(EXISTS_HOST).anyTimes();
+
+ Capture<HostDescription> capturedHostDesc = newCapture();
+
+ // XXX: also a hack here
+ mockHostProviderService.hostDetected(eq(hostId), capture(capturedHostDesc), eq(false));
+ expectLastCall().anyTimes();
+
+ mockHostProviderService.hostDetected(eq(CLIENT_HOST_ID), capture(capturedHostDesc), eq(false));
+ expectLastCall().anyTimes();
+ replay(mockHostProviderService, manager.hostService);
+ packetService.processPacket(packetContext);
+ verify(mockHostProviderService);
+
+ HostDescription hostDesc = capturedHostDesc.getValue();
+ Set<HostLocation> hostLocations = hostDesc.locations();
+ assertEquals(2, hostLocations.size());
+ assertTrue(hostLocations.contains(CLIENT_LOCATION));
+ assertTrue(hostLocations.contains(CLIENT_DH_LOCATION));
+ }
+
private static class MockDefaultDhcpRelayConfig extends DefaultDhcpRelayConfig {
@Override
public boolean isValid() {
@@ -458,6 +712,18 @@
}
}
+ private static class MockIndirectDhcpRelayConfig extends IndirectDhcpRelayConfig {
+ @Override
+ public boolean isValid() {
+ return true;
+ }
+
+ @Override
+ public List<DhcpServerConfig> dhcpServerConfigs() {
+ return ImmutableList.of(new MockDhcpServerConfig(null));
+ }
+ }
+
private static class MockDhcpServerConfig extends DhcpServerConfig {
Ip4Address relayAgentIp;
@@ -484,35 +750,20 @@
public Optional<Ip4Address> getDhcpServerIp4() {
return Optional.of(SERVER_IP);
}
- }
-
- private class MockHostStore extends HostStoreAdapter {
-
- private final Map<HostId, HostDescription> hosts = Maps.newHashMap();
@Override
- public HostEvent createOrUpdateHost(ProviderId providerId, HostId hostId,
- HostDescription hostDescription,
- boolean replaceIps) {
- hosts.put(hostId, hostDescription);
-
- // not necessary to return host event in this test.
- return null;
- }
-
- public HostDescription hostDesc(HostId hostId) {
- return hosts.get(hostId);
+ public Optional<Ip4Address> getDhcpGatewayIp4() {
+ return Optional.of(GATEWAY_IP);
}
@Override
- public Iterable<Host> getHosts() {
- return hosts.values().stream()
- .map(hd -> new DefaultHost(DhcpRelayManager.PROVIDER_ID,
- HostId.hostId(hd.hwAddress(), hd.vlan()),
- hd.hwAddress(),
- hd.vlan(), hd.locations(),
- hd.ipAddress(), false))
- .collect(Collectors.toList());
+ public Optional<Ip6Address> getDhcpServerIp6() {
+ return Optional.of(SERVER_IP_V6);
+ }
+
+ @Override
+ public Optional<Ip6Address> getDhcpGatewayIp6() {
+ return Optional.of(GATEWAY_IP_V6);
}
}
@@ -821,4 +1072,266 @@
return this.inPacket;
}
}
+
+ /**
+ * Generates DHCP6 REQUEST packet.
+ */
+ private void buildDhcp6Packet(DHCP6 dhcp6, byte msgType, Ip6Address ip6Addr, IpPrefix prefix) {
+
+ // build address option
+ Dhcp6IaAddressOption iaAddressOption = new Dhcp6IaAddressOption();
+ iaAddressOption.setCode(DHCP6.OptionCode.IAADDR.value());
+ iaAddressOption.setIp6Address(ip6Addr);
+ iaAddressOption.setPreferredLifetime(3600);
+ iaAddressOption.setValidLifetime(1200);
+ iaAddressOption.setLength((short) Dhcp6IaAddressOption.DEFAULT_LEN);
+
+ Dhcp6IaNaOption iaNaOption = new Dhcp6IaNaOption();
+ iaNaOption.setCode(DHCP6.OptionCode.IA_NA.value());
+ iaNaOption.setIaId(0);
+ iaNaOption.setT1(302400);
+ iaNaOption.setT2(483840);
+ List<Dhcp6Option> iaNaSubOptions = new ArrayList<Dhcp6Option>();
+ iaNaSubOptions.add(iaAddressOption);
+ iaNaOption.setOptions(iaNaSubOptions);
+ iaNaOption.setLength((short) (Dhcp6IaNaOption.DEFAULT_LEN + iaAddressOption.getLength()));
+
+ // build prefix option
+ Dhcp6IaPrefixOption iaPrefixOption = new Dhcp6IaPrefixOption();
+ iaPrefixOption.setCode(DHCP6.OptionCode.IAPREFIX.value());
+ iaPrefixOption.setIp6Prefix(prefix.address().getIp6Address());
+ iaPrefixOption.setPrefixLength((byte) prefix.prefixLength());
+ iaPrefixOption.setPreferredLifetime(3601);
+ iaPrefixOption.setValidLifetime(1201);
+ iaPrefixOption.setLength((short) Dhcp6IaPrefixOption.DEFAULT_LEN);
+
+ Dhcp6IaPdOption iaPdOption = new Dhcp6IaPdOption();
+ iaPdOption.setCode(DHCP6.OptionCode.IA_PD.value());
+ iaPdOption.setIaId(0);
+ iaPdOption.setT1(302401);
+ iaPdOption.setT2(483841);
+ List<Dhcp6Option> iaPdSubOptions = new ArrayList<Dhcp6Option>();
+ iaPdSubOptions.add(iaPrefixOption);
+ iaPdOption.setOptions(iaPdSubOptions);
+ iaPdOption.setLength((short) (Dhcp6IaPdOption.DEFAULT_LEN + iaPrefixOption.getLength()));
+
+ dhcp6.setMsgType(msgType);
+ List<Dhcp6Option> dhcp6Options = new ArrayList<Dhcp6Option>();
+ dhcp6Options.add(iaNaOption);
+ dhcp6Options.add(iaPdOption);
+ dhcp6.setOptions(dhcp6Options);
+
+ }
+
+ private void buildRelayMsg(DHCP6 dhcp6Relay, byte msgType, Ip6Address linkAddr,
+ Ip6Address peerAddr, byte hop, byte[] interfaceIdBytes,
+ DHCP6 dhcp6Payload) {
+
+ dhcp6Relay.setMsgType(msgType);
+
+ dhcp6Relay.setLinkAddress(linkAddr.toOctets());
+ dhcp6Relay.setPeerAddress(peerAddr.toOctets());
+ dhcp6Relay.setHopCount(hop);
+ List<Dhcp6Option> options = new ArrayList<Dhcp6Option>();
+
+ // interfaceId option
+ Dhcp6Option interfaceId = new Dhcp6Option();
+ interfaceId.setCode(DHCP6.OptionCode.INTERFACE_ID.value());
+
+
+ interfaceId.setData(interfaceIdBytes);
+ interfaceId.setLength((short) interfaceIdBytes.length);
+ Dhcp6InterfaceIdOption interfaceIdOption = new Dhcp6InterfaceIdOption(interfaceId);
+ ByteBuffer bb = ByteBuffer.wrap(interfaceIdBytes);
+
+ byte[] macAddr = new byte[MacAddress.MAC_ADDRESS_LENGTH];
+ byte[] port = new byte[21];
+ bb.get(macAddr);
+ bb.get(); // separator
+ bb.get(port);
+ interfaceIdOption.setMacAddress(MacAddress.valueOf(macAddr));
+ interfaceIdOption.setInPort(port);
+
+ options.add(interfaceIdOption);
+
+ // relay message option
+ Dhcp6Option relayMsgOption = new Dhcp6Option();
+ relayMsgOption.setCode(DHCP6.OptionCode.RELAY_MSG.value());
+ byte[] dhcp6PayloadByte = dhcp6Payload.serialize();
+ relayMsgOption.setLength((short) dhcp6PayloadByte.length);
+ relayMsgOption.setPayload(dhcp6Payload);
+ Dhcp6RelayOption relayOpt = new Dhcp6RelayOption(relayMsgOption);
+
+ options.add(relayOpt);
+
+ dhcp6Relay.setOptions(options);
+ }
+ private byte[] buildInterfaceId(MacAddress clientMac, ConnectPoint clientCp) {
+ String inPortString = "-" + clientCp.toString();
+ byte[] clientSoureMacBytes = clientMac.toBytes();
+ byte[] inPortStringBytes = inPortString.getBytes();
+ byte[] interfaceIdBytes = new byte[clientSoureMacBytes.length + inPortStringBytes.length];
+
+ System.arraycopy(clientSoureMacBytes, 0, interfaceIdBytes, 0, clientSoureMacBytes.length);
+ System.arraycopy(inPortStringBytes, 0, interfaceIdBytes, clientSoureMacBytes.length, inPortStringBytes.length);
+
+ return interfaceIdBytes;
+ }
+
+ private class TestDhcp6RequestPacketContext extends PacketContextAdapter {
+
+
+ private InboundPacket inPacket;
+
+
+ public TestDhcp6RequestPacketContext(MacAddress clientMac, VlanId vlanId,
+ ConnectPoint clientCp,
+ Ip6Address clientGwAddr,
+ int relayLevel) {
+ super(0, null, null, false);
+
+ DHCP6 dhcp6 = new DHCP6();
+ if (relayLevel > 0) {
+ DHCP6 dhcp6Payload = new DHCP6();
+ buildDhcp6Packet(dhcp6Payload, DHCP6.MsgType.REQUEST.value(),
+ IP_FOR_CLIENT_V6,
+ PREFIX_FOR_ZERO);
+ DHCP6 dhcp6Parent = null;
+ DHCP6 dhcp6Child = dhcp6Payload;
+ for (int i = 0; i < relayLevel; i++) {
+ dhcp6Parent = new DHCP6();
+ byte[] interfaceId = buildInterfaceId(clientMac, clientCp);
+ buildRelayMsg(dhcp6Parent, DHCP6.MsgType.RELAY_FORW.value(),
+ INTERFACE_IP_V6.ipAddress().getIp6Address(),
+ OUTER_RELAY_IP_V6,
+ (byte) (relayLevel - 1), interfaceId,
+ dhcp6Child);
+ dhcp6Child = dhcp6Parent;
+ }
+ if (dhcp6Parent != null) {
+ dhcp6 = dhcp6Parent;
+ }
+ } else {
+ buildDhcp6Packet(dhcp6, DHCP6.MsgType.REQUEST.value(),
+ IP_FOR_CLIENT_V6,
+ PREFIX_FOR_ZERO);
+ }
+
+ UDP udp = new UDP();
+ udp.setPayload(dhcp6);
+ if (relayLevel > 0) {
+ udp.setSourcePort(UDP.DHCP_V6_SERVER_PORT);
+ } else {
+ udp.setSourcePort(UDP.DHCP_V6_CLIENT_PORT);
+ }
+ udp.setDestinationPort(UDP.DHCP_V6_SERVER_PORT);
+
+ IPv6 ipv6 = new IPv6();
+ ipv6.setPayload(udp);
+ ipv6.setNextHeader(IPv6.PROTOCOL_UDP);
+ ipv6.setDestinationAddress(SERVER_IP_V6_MCAST.toOctets());
+ ipv6.setSourceAddress(clientGwAddr.toOctets());
+
+ Ethernet eth = new Ethernet();
+ if (relayLevel > 0) {
+ eth.setEtherType(Ethernet.TYPE_IPV6)
+ .setVlanID(vlanId.toShort())
+ .setSourceMACAddress(OUTER_RELAY_MAC)
+ .setDestinationMACAddress(MacAddress.valueOf("33:33:00:01:00:02"))
+ .setPayload(ipv6);
+ } else {
+ eth.setEtherType(Ethernet.TYPE_IPV6)
+ .setVlanID(vlanId.toShort())
+ .setSourceMACAddress(clientMac)
+ .setDestinationMACAddress(MacAddress.valueOf("33:33:00:01:00:02"))
+ .setPayload(ipv6);
+ }
+ this.inPacket = new DefaultInboundPacket(clientCp, eth,
+ ByteBuffer.wrap(eth.serialize()));
+ }
+
+ @Override
+ public InboundPacket inPacket() {
+ return this.inPacket;
+ }
+ }
+
+ /**
+ * Generates DHCP6 REPLY packet.
+ */
+
+ private class TestDhcp6ReplyPacketContext extends PacketContextAdapter {
+ private InboundPacket inPacket;
+
+ public TestDhcp6ReplyPacketContext(ConnectPoint clientCp, MacAddress clientMac,
+ VlanId clientVlan, Ip6Address clientGwAddr,
+ int relayLevel) {
+ super(0, null, null, false);
+
+
+ DHCP6 dhcp6Payload = new DHCP6();
+ buildDhcp6Packet(dhcp6Payload, DHCP6.MsgType.REPLY.value(),
+ IP_FOR_CLIENT_V6,
+ PREFIX_FOR_CLIENT_V6);
+ byte[] interfaceId = buildInterfaceId(clientMac, clientCp);
+ DHCP6 dhcp6 = new DHCP6();
+ buildRelayMsg(dhcp6, DHCP6.MsgType.RELAY_REPL.value(),
+ INTERFACE_IP_V6.ipAddress().getIp6Address(),
+ CLIENT_LL_IP_V6,
+ (byte) 0, interfaceId,
+ dhcp6Payload);
+
+ DHCP6 dhcp6Parent = null;
+ DHCP6 dhcp6Child = dhcp6;
+ for (int i = 0; i < relayLevel; i++) { // relayLevel 0 : no relay
+ dhcp6Parent = new DHCP6();
+
+ buildRelayMsg(dhcp6Parent, DHCP6.MsgType.RELAY_REPL.value(),
+ INTERFACE_IP_V6.ipAddress().getIp6Address(),
+ OUTER_RELAY_IP_V6,
+ (byte) relayLevel, interfaceId,
+ dhcp6Child);
+
+ dhcp6Child = dhcp6Parent;
+ }
+ if (dhcp6Parent != null) {
+ dhcp6 = dhcp6Parent;
+ }
+
+
+ UDP udp = new UDP();
+ udp.setPayload(dhcp6);
+ udp.setSourcePort(UDP.DHCP_V6_SERVER_PORT);
+ udp.setDestinationPort(UDP.DHCP_V6_CLIENT_PORT);
+ IPv6 ipv6 = new IPv6();
+ ipv6.setPayload(udp);
+ ipv6.setNextHeader(IPv6.PROTOCOL_UDP);
+ ipv6.setDestinationAddress(IP_FOR_CLIENT_V6.toOctets());
+ ipv6.setSourceAddress(SERVER_IP_V6.toOctets());
+ Ethernet eth = new Ethernet();
+ if (relayLevel > 0) {
+ eth.setEtherType(Ethernet.TYPE_IPV6)
+ .setVlanID(SERVER_VLAN.toShort())
+ .setSourceMACAddress(SERVER_MAC)
+ .setDestinationMACAddress(OUTER_RELAY_MAC)
+ .setPayload(ipv6);
+ } else {
+ eth.setEtherType(Ethernet.TYPE_IPV6)
+ .setVlanID(SERVER_VLAN.toShort())
+ .setSourceMACAddress(SERVER_MAC)
+ .setDestinationMACAddress(CLIENT_MAC)
+ .setPayload(ipv6);
+ }
+
+ this.inPacket = new DefaultInboundPacket(SERVER_CONNECT_POINT, eth,
+ ByteBuffer.wrap(eth.serialize()));
+
+ }
+
+ @Override
+ public InboundPacket inPacket() {
+ return this.inPacket;
+ }
+ }
+
}
diff --git a/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/DefaultRoutingHandler.java b/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/DefaultRoutingHandler.java
index 0d263e7..709d05e 100644
--- a/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/DefaultRoutingHandler.java
+++ b/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/DefaultRoutingHandler.java
@@ -244,6 +244,11 @@
*/
// XXX refactor
protected void populateSubnet(Set<ConnectPoint> cpts, Set<IpPrefix> subnets) {
+ if (cpts == null || cpts.size() < 1 || cpts.size() > 2) {
+ log.warn("Skipping populateSubnet due to illegal size of connect points. {}", cpts);
+ return;
+ }
+
lastRoutingChange = DateTime.now();
statusLock.lock();
try {
diff --git a/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/DeviceConfiguration.java b/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/DeviceConfiguration.java
index 11a8425..18169bb 100644
--- a/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/DeviceConfiguration.java
+++ b/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/DeviceConfiguration.java
@@ -15,6 +15,9 @@
*/
package org.onosproject.segmentrouting.config;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.SetMultimap;
@@ -136,6 +139,7 @@
ConnectPoint connectPoint = networkInterface.connectPoint();
DeviceId dpid = connectPoint.deviceId();
PortNumber port = connectPoint.port();
+ MacAddress mac = networkInterface.mac();
SegmentRouterInfo info = deviceConfigMap.get(dpid);
// skip if there is no corresponding device for this ConenctPoint
@@ -158,6 +162,16 @@
info.subnets.put(port, interfaceAddress.subnetAddress());
}
});
+
+ // Override interface mac with router mac
+ if (!mac.equals(info.mac)) {
+ ArrayNode array = (ArrayNode) config.node();
+ for (JsonNode intfNode : array) {
+ ObjectNode objNode = (ObjectNode) intfNode;
+ objNode.put(InterfaceConfig.MAC, info.mac.toString());
+ }
+ srManager.cfgService.applyConfig(connectPoint, InterfaceConfig.class, array);
+ }
}
});
// We register the connect point with the NRS.
diff --git a/core/api/src/main/java/org/onosproject/net/pi/model/PiPipelineInterpreter.java b/core/api/src/main/java/org/onosproject/net/pi/model/PiPipelineInterpreter.java
index 6b93f5d..738996f 100644
--- a/core/api/src/main/java/org/onosproject/net/pi/model/PiPipelineInterpreter.java
+++ b/core/api/src/main/java/org/onosproject/net/pi/model/PiPipelineInterpreter.java
@@ -24,6 +24,7 @@
import org.onosproject.net.packet.InboundPacket;
import org.onosproject.net.packet.OutboundPacket;
import org.onosproject.net.pi.runtime.PiAction;
+import org.onosproject.net.pi.runtime.PiCounterId;
import org.onosproject.net.pi.runtime.PiHeaderFieldId;
import org.onosproject.net.pi.runtime.PiPacketOperation;
import org.onosproject.net.pi.runtime.PiTableId;
@@ -88,6 +89,15 @@
throws PiInterpreterException;
/**
+ * Returns a protocol-independent direct counter identifier for the given table, if present. If not present, it
+ * means that the given table does not support direct counters.
+ *
+ * @param piTableId table identifier
+ * @return optional direct counter identifier
+ */
+ Optional<PiCounterId> mapTableCounter(PiTableId piTableId);
+
+ /**
* Returns a collection of packet operations equivalent to the given OutboundPacket.
*
* @param packet a ONOS outbound packet
diff --git a/core/api/src/main/java/org/onosproject/net/pi/runtime/PiCounterCellId.java b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiCounterCellId.java
index d762f23..cd88d2a 100644
--- a/core/api/src/main/java/org/onosproject/net/pi/runtime/PiCounterCellId.java
+++ b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiCounterCellId.java
@@ -16,77 +16,22 @@
package org.onosproject.net.pi.runtime;
-import com.google.common.annotations.Beta;
-import com.google.common.base.Objects;
-import org.onlab.util.Identifier;
-
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkNotNull;
-
/**
- * Identifier of a counter cell of a protocol-independent pipeline.
+ * Identifier of a counter cell in a protocol-independent pipeline.
*/
-@Beta
-public final class PiCounterCellId extends Identifier<String> {
-
- private final PiCounterId counterId;
- private final long index;
-
- private PiCounterCellId(PiCounterId counterId, long index) {
- super(counterId.id() + "[" + index + "]");
- this.counterId = counterId;
- this.index = index;
- }
+public interface PiCounterCellId {
/**
- * Returns a counter cell identifier for the given counter identifier and index.
- *
- * @param counterId counter identifier
- * @param index index
- * @return counter cell identifier
- */
- public static PiCounterCellId of(PiCounterId counterId, long index) {
- checkNotNull(counterId);
- checkArgument(index >= 0, "Index must be a positive integer");
- return new PiCounterCellId(counterId, index);
- }
-
- /**
- * Returns the counter identifier of this cell.
+ * Returns the identifier of the counter instance where this cell is contained.
*
* @return counter identifier
*/
- public PiCounterId counterId() {
- return counterId;
- }
+ PiCounterId counterId();
/**
- * Returns the index of this cell.
+ * Returns the type of counter identified.
*
- * @return cell index
+ * @return counter type
*/
- public long index() {
- return index;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof PiCounterCellId)) {
- return false;
- }
- if (!super.equals(o)) {
- return false;
- }
- PiCounterCellId that = (PiCounterCellId) o;
- return index == that.index &&
- Objects.equal(counterId, that.counterId);
- }
-
- @Override
- public int hashCode() {
- return Objects.hashCode(super.hashCode(), counterId, index);
- }
+ PiCounterType type();
}
diff --git a/core/api/src/main/java/org/onosproject/net/pi/runtime/PiCounterId.java b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiCounterId.java
index 6fcd55e..dcc7c02 100644
--- a/core/api/src/main/java/org/onosproject/net/pi/runtime/PiCounterId.java
+++ b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiCounterId.java
@@ -17,7 +17,7 @@
package org.onosproject.net.pi.runtime;
import com.google.common.annotations.Beta;
-import org.onlab.util.Identifier;
+import com.google.common.base.Objects;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
@@ -26,22 +26,28 @@
* Identifier of a counter of a protocol-independent pipeline.
*/
@Beta
-public final class PiCounterId extends Identifier<String> {
+public final class PiCounterId {
- private PiCounterId(String name) {
- super(name);
+ private final String name;
+ private final PiCounterType type;
+
+ private PiCounterId(String name, PiCounterType type) {
+ this.name = name;
+ this.type = type;
}
/**
- * Returns a counter identifier for the given name.
+ * Returns a counter identifier for the given name and type.
*
* @param name counter name
+ * @param type counter type
* @return counter identifier
*/
- public static PiCounterId of(String name) {
+ public static PiCounterId of(String name, PiCounterType type) {
checkNotNull(name);
- checkArgument(!name.isEmpty(), "Name name can't be empty");
- return new PiCounterId(name);
+ checkNotNull(type);
+ checkArgument(!name.isEmpty(), "Name can't be empty");
+ return new PiCounterId(name, type);
}
/**
@@ -50,6 +56,38 @@
* @return counter name
*/
public String name() {
- return this.identifier;
+ return this.name;
+ }
+
+ /**
+ * Returns the type of the counter.
+ *
+ * @return counter type
+ */
+ public PiCounterType type() {
+ return this.type;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof PiCounterId)) {
+ return false;
+ }
+ PiCounterId that = (PiCounterId) o;
+ return Objects.equal(name, that.name) &&
+ type == that.type;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(name, type);
+ }
+
+ @Override
+ public String toString() {
+ return type.name().toLowerCase() + ":" + name;
}
}
diff --git a/core/api/src/main/java/org/onosproject/net/pi/runtime/PiCounterType.java b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiCounterType.java
new file mode 100644
index 0000000..b4a709a
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiCounterType.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.net.pi.runtime;
+
+/**
+ * Type of counter in a protocol-independent pipeline.
+ */
+public enum PiCounterType {
+ /**
+ * Identifies a counter associated to a match-action table, where cells are directly associated to table entries.
+ */
+ DIRECT,
+
+ /**
+ * Identifies a counter not associated with any other resource.
+ */
+ INDIRECT
+}
diff --git a/core/api/src/main/java/org/onosproject/net/pi/runtime/PiDirectCounterCellId.java b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiDirectCounterCellId.java
new file mode 100644
index 0000000..26ae363
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiDirectCounterCellId.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.net.pi.runtime;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.Objects;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static java.lang.String.format;
+import static org.onosproject.net.pi.runtime.PiCounterType.DIRECT;
+
+/**
+ * Identifier of a direct counter cell of a protocol-independent pipeline.
+ */
+@Beta
+public final class PiDirectCounterCellId implements PiCounterCellId {
+
+ private final PiCounterId counterId;
+ private final PiTableEntry tableEntry;
+
+ private PiDirectCounterCellId(PiCounterId counterId, PiTableEntry tableEntry) {
+ this.counterId = counterId;
+ this.tableEntry = tableEntry;
+ }
+
+ /**
+ * Returns a direct counter cell identifier for the given counter identifier and table entry.
+ *
+ * @param counterId counter identifier
+ * @param tableEntry table entry
+ * @return direct counter cell identifier
+ */
+ public static PiDirectCounterCellId of(PiCounterId counterId, PiTableEntry tableEntry) {
+ checkNotNull(counterId);
+ checkNotNull(tableEntry);
+ checkArgument(counterId.type() == DIRECT, "Counter ID must be of type DIRECT");
+ return new PiDirectCounterCellId(counterId, tableEntry);
+ }
+
+ /**
+ * Returns the table entry associated with this cell identifier.
+ *
+ * @return cell table entry
+ */
+ public PiTableEntry tableEntry() {
+ return tableEntry;
+ }
+
+ @Override
+ public PiCounterId counterId() {
+ return counterId;
+ }
+
+ @Override
+ public PiCounterType type() {
+ return DIRECT;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof PiDirectCounterCellId)) {
+ return false;
+ }
+ PiDirectCounterCellId that = (PiDirectCounterCellId) o;
+ return Objects.equal(counterId, that.counterId) &&
+ Objects.equal(tableEntry, that.tableEntry);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(counterId, tableEntry);
+ }
+
+ @Override
+ public String toString() {
+ return format("%s[{%s}]", counterId, tableEntry);
+ }
+}
diff --git a/core/api/src/main/java/org/onosproject/net/pi/runtime/PiIndirectCounterCellId.java b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiIndirectCounterCellId.java
new file mode 100644
index 0000000..6f3f73a
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiIndirectCounterCellId.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.net.pi.runtime;
+
+import com.google.common.annotations.Beta;
+import org.onlab.util.Identifier;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.onosproject.net.pi.runtime.PiCounterType.INDIRECT;
+
+/**
+ * Identifier of an indirect counter cell in a protocol-independent pipeline.
+ */
+@Beta
+public final class PiIndirectCounterCellId extends Identifier<String> implements PiCounterCellId {
+
+ private final PiCounterId counterId;
+ private final long index;
+
+ private PiIndirectCounterCellId(PiCounterId counterId, long index) {
+ super(counterId.toString() + "[" + index + "]");
+ this.counterId = counterId;
+ this.index = index;
+ }
+
+ /**
+ * Returns a counter cell identifier for the given counter identifier and index.
+ *
+ * @param counterId counter identifier
+ * @param index index
+ * @return counter cell identifier
+ */
+ public static PiIndirectCounterCellId of(PiCounterId counterId, long index) {
+ checkNotNull(counterId);
+ checkArgument(counterId.type() == INDIRECT, "Counter ID must be of type INDIRECT");
+ checkArgument(index >= 0, "Index must be a positive integer");
+ return new PiIndirectCounterCellId(counterId, index);
+ }
+
+ /**
+ * Returns the index of this cell.
+ *
+ * @return cell index
+ */
+ public long index() {
+ return index;
+ }
+
+ @Override
+ public PiCounterId counterId() {
+ return counterId;
+ }
+
+ @Override
+ public PiCounterType type() {
+ return INDIRECT;
+ }
+}
diff --git a/core/api/src/main/java/org/onosproject/net/pi/runtime/PiMatchKey.java b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiMatchKey.java
index 91cabfd..e2e8c3d 100644
--- a/core/api/src/main/java/org/onosproject/net/pi/runtime/PiMatchKey.java
+++ b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiMatchKey.java
@@ -24,14 +24,14 @@
import java.util.Optional;
import java.util.StringJoiner;
-import static com.google.common.base.Preconditions.checkArgument;
-
/**
* Representation of all field matches of an entry of a match+action table of a protocol-independent pipeline.
*/
@Beta
public final class PiMatchKey {
+ public static final PiMatchKey EMPTY = builder().build();
+
private final ImmutableMap<PiHeaderFieldId, PiFieldMatch> fieldMatches;
private PiMatchKey(ImmutableMap<PiHeaderFieldId, PiFieldMatch> fieldMatches) {
@@ -130,7 +130,6 @@
*/
public PiMatchKey build() {
ImmutableMap<PiHeaderFieldId, PiFieldMatch> fieldMatches = fieldMatchesBuilder.build();
- checkArgument(fieldMatches.size() > 0, "Field matches cannot be empty");
return new PiMatchKey(fieldMatches);
}
}
diff --git a/core/api/src/main/java/org/onosproject/net/pi/runtime/PiTableEntry.java b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiTableEntry.java
index b0192fd..6a5f75b 100644
--- a/core/api/src/main/java/org/onosproject/net/pi/runtime/PiTableEntry.java
+++ b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiTableEntry.java
@@ -31,6 +31,8 @@
@Beta
public final class PiTableEntry {
+ public static final PiTableEntry EMTPY = new PiTableEntry();
+
private static final int NO_PRIORITY = -1;
private static final double NO_TIMEOUT = -1;
@@ -41,6 +43,15 @@
private final int priority;
private final double timeout;
+ private PiTableEntry() {
+ this.tableId = null;
+ this.matchKey = null;
+ this.tableAction = null;
+ this.cookie = 0;
+ this.priority = NO_PRIORITY;
+ this.timeout = NO_TIMEOUT;
+ }
+
private PiTableEntry(PiTableId tableId, PiMatchKey matchKey,
PiTableAction tableAction, long cookie, int priority, double timeout) {
this.tableId = tableId;
diff --git a/core/api/src/main/java/org/onosproject/ui/topo/TopoUtils.java b/core/api/src/main/java/org/onosproject/ui/topo/TopoUtils.java
index 4a5d2fc..a8deff3 100644
--- a/core/api/src/main/java/org/onosproject/ui/topo/TopoUtils.java
+++ b/core/api/src/main/java/org/onosproject/ui/topo/TopoUtils.java
@@ -99,14 +99,14 @@
/**
* Returns a value representing a count of bits per second,
- * (clipped to a maximum of 10 Gbps).
+ * (clipped to a maximum of 100 Gbps).
* Note that the input is bytes per second.
*
* @param bytes bytes per second
* @return value representing bits per second
*/
public static ValueLabel formatClippedBitRate(long bytes) {
- return new ValueLabel(bytes * 8, BITS_UNIT).perSec().clipG(10.0);
+ return new ValueLabel(bytes * 8, BITS_UNIT).perSec().clipG(100.0);
}
/**
diff --git a/core/api/src/test/java/org/onosproject/net/pi/runtime/PiTableEntryTest.java b/core/api/src/test/java/org/onosproject/net/pi/runtime/PiTableEntryTest.java
index 505dba3..6caa63c 100644
--- a/core/api/src/test/java/org/onosproject/net/pi/runtime/PiTableEntryTest.java
+++ b/core/api/src/test/java/org/onosproject/net/pi/runtime/PiTableEntryTest.java
@@ -27,29 +27,27 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
-import static org.onosproject.net.pi.runtime.PiConstantsTest.DROP;
-import static org.onosproject.net.pi.runtime.PiConstantsTest.DST_ADDR;
-import static org.onosproject.net.pi.runtime.PiConstantsTest.IPV4_HEADER_NAME;
+import static org.onosproject.net.pi.runtime.PiConstantsTest.*;
/**
* Unit tests for PiTableEntry class.
*/
public class PiTableEntryTest {
- final PiTableEntry piTableEntry1 = PiTableEntry.builder()
+ private final PiTableEntry piTableEntry1 = PiTableEntry.builder()
.forTable(PiTableId.of("Table10"))
.withCookie(0xac)
.withPriority(10)
.withAction(PiAction.builder().withId(PiActionId.of(DROP)).build())
.withTimeout(100)
.build();
- final PiTableEntry sameAsPiTableEntry1 = PiTableEntry.builder()
+ private final PiTableEntry sameAsPiTableEntry1 = PiTableEntry.builder()
.forTable(PiTableId.of("Table10"))
.withCookie(0xac)
.withPriority(10)
.withAction(PiAction.builder().withId(PiActionId.of(DROP)).build())
.withTimeout(100)
.build();
- final PiTableEntry piTableEntry2 = PiTableEntry.builder()
+ private final PiTableEntry piTableEntry2 = PiTableEntry.builder()
.forTable(PiTableId.of("Table20"))
.withCookie(0xac)
.withPriority(10)
@@ -77,6 +75,16 @@
}
/**
+ * Tests equality of the empty table entry.
+ */
+ @Test
+ public void testEmptyEquals() {
+ new EqualsTester()
+ .addEqualityGroup(PiTableEntry.EMTPY, PiTableEntry.EMTPY)
+ .testEquals();
+ }
+
+ /**
* Tests creation of a DefaultFlowRule using a FlowRule constructor.
*/
@Test
diff --git a/core/api/src/test/java/org/onosproject/ui/topo/TopoUtilsTest.java b/core/api/src/test/java/org/onosproject/ui/topo/TopoUtilsTest.java
index 19f1495..1dc8fc3 100644
--- a/core/api/src/test/java/org/onosproject/ui/topo/TopoUtilsTest.java
+++ b/core/api/src/test/java/org/onosproject/ui/topo/TopoUtilsTest.java
@@ -207,9 +207,9 @@
@Test
public void formatClippedBitsGigaExceedThreshold() {
- vl = TopoUtils.formatClippedBitRate(5_000_000_000L);
- // approx. 37.25 Gbps
- assertEquals(AM_WL, "10 Gbps", vl.toString());
+ vl = TopoUtils.formatClippedBitRate(15_000_000_000L);
+ // approx. 111.75 Gbps
+ assertEquals(AM_WL, "100 Gbps", vl.toString());
assertTrue(AM_NCL, vl.clipped());
}
diff --git a/core/net/src/main/java/org/onosproject/net/host/impl/HostManager.java b/core/net/src/main/java/org/onosproject/net/host/impl/HostManager.java
index f6c5856..66159f7 100644
--- a/core/net/src/main/java/org/onosproject/net/host/impl/HostManager.java
+++ b/core/net/src/main/java/org/onosproject/net/host/impl/HostManager.java
@@ -29,6 +29,7 @@
import org.onlab.packet.VlanId;
import org.onlab.util.Tools;
import org.onosproject.cfg.ComponentConfigService;
+import org.onosproject.net.intf.Interface;
import org.onosproject.net.intf.InterfaceService;
import org.onosproject.net.HostLocation;
import org.onosproject.net.edge.EdgePortService;
@@ -63,7 +64,6 @@
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static org.onlab.packet.IPv6.getLinkLocalAddress;
-import static org.onosproject.net.link.ProbedLinkProvider.DEFAULT_MAC;
import static org.onosproject.security.AppGuard.checkPermission;
import static org.onosproject.security.AppPermission.Type.HOST_EVENT;
import static org.onosproject.security.AppPermission.Type.HOST_READ;
@@ -349,7 +349,7 @@
// Greedy learning of IPv6 host. We have to disable the greedy
// learning of configured hosts. Validate hosts each time will
- // overwrite the learnt information with the configured informations.
+ // overwrite the learnt information with the configured information.
if (greedyLearningIpv6) {
// Auto-generation of the IPv6 link local address
// using the mac address
@@ -365,19 +365,18 @@
}
// Host does not exist in the store or the target is not known
if ((host == null || !host.ipAddresses().contains(targetIp6Address))) {
- // We generate ONOS ip from the ONOS default mac
- // We could use the mac generated for the link
- // discovery but maybe does not worth
- MacAddress onosMacAddress = MacAddress.valueOf(DEFAULT_MAC);
- Ip6Address onosIp6Address = Ip6Address.valueOf(
- getLinkLocalAddress(onosMacAddress.toBytes())
- );
+ // Use DAD to probe if interface MAC is not specified
+ MacAddress probeMac = interfaceService.getInterfacesByPort(hostDescription.location())
+ .stream().map(Interface::mac).findFirst().orElse(MacAddress.ONOS);
+ Ip6Address probeIp = !probeMac.equals(MacAddress.ONOS) ?
+ Ip6Address.valueOf(getLinkLocalAddress(probeMac.toBytes())) :
+ Ip6Address.ZERO;
// We send a probe using the monitoring service
monitor.sendProbe(
hostDescription.location(),
targetIp6Address,
- onosIp6Address,
- onosMacAddress,
+ probeIp,
+ probeMac,
hostId.vlanId()
);
}
diff --git a/core/net/src/main/java/org/onosproject/net/host/impl/HostMonitor.java b/core/net/src/main/java/org/onosproject/net/host/impl/HostMonitor.java
index 950bedd..3d9861c 100644
--- a/core/net/src/main/java/org/onosproject/net/host/impl/HostMonitor.java
+++ b/core/net/src/main/java/org/onosproject/net/host/impl/HostMonitor.java
@@ -18,6 +18,8 @@
import org.onlab.packet.ARP;
import org.onlab.packet.Ethernet;
import org.onlab.packet.IPv6;
+import org.onlab.packet.Ip4Address;
+import org.onlab.packet.Ip6Address;
import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
@@ -194,28 +196,26 @@
intf.ipAddressesList().stream()
.filter(ia -> ia.subnetAddress().contains(targetIp))
.forEach(ia -> {
- log.debug("Sending probe for target:{} out of intf:{} vlan:{}",
- targetIp, intf.connectPoint(), intf.vlan());
- sendProbe(intf.connectPoint(), targetIp, ia.ipAddress(),
- intf.mac(), intf.vlan());
+ MacAddress probeMac = intf.mac();
+ IpAddress probeIp = !probeMac.equals(MacAddress.ONOS) ?
+ ia.ipAddress() :
+ (ia.ipAddress().isIp4() ? Ip4Address.ZERO : Ip6Address.ZERO);
+ sendProbe(intf.connectPoint(), targetIp, probeIp, probeMac, intf.vlan());
+
// account for use-cases where tagged-vlan config is used
if (!intf.vlanTagged().isEmpty()) {
intf.vlanTagged().forEach(tag -> {
- log.debug("Sending probe for target:{} out of intf:{} vlan:{}",
- targetIp, intf.connectPoint(), tag);
- sendProbe(intf.connectPoint(), targetIp, ia.ipAddress(),
- intf.mac(), tag);
+ sendProbe(intf.connectPoint(), targetIp, probeIp, probeMac, tag);
});
}
});
});
}
- public void sendProbe(ConnectPoint connectPoint,
- IpAddress targetIp,
- IpAddress sourceIp,
- MacAddress sourceMac,
- VlanId vlan) {
+ public void sendProbe(ConnectPoint connectPoint, IpAddress targetIp, IpAddress sourceIp,
+ MacAddress sourceMac, VlanId vlan) {
+ log.debug("Sending probe for target:{} out of intf:{} vlan:{}", targetIp, connectPoint, vlan);
+
Ethernet probePacket;
if (targetIp.isIp4()) {
diff --git a/core/net/src/test/java/org/onosproject/net/pi/impl/MockInterpreter.java b/core/net/src/test/java/org/onosproject/net/pi/impl/MockInterpreter.java
index 794e7f8..a9178ca 100644
--- a/core/net/src/test/java/org/onosproject/net/pi/impl/MockInterpreter.java
+++ b/core/net/src/test/java/org/onosproject/net/pi/impl/MockInterpreter.java
@@ -32,6 +32,7 @@
import org.onosproject.net.pi.runtime.PiActionId;
import org.onosproject.net.pi.runtime.PiActionParam;
import org.onosproject.net.pi.runtime.PiActionParamId;
+import org.onosproject.net.pi.runtime.PiCounterId;
import org.onosproject.net.pi.runtime.PiHeaderFieldId;
import org.onosproject.net.pi.runtime.PiPacketOperation;
import org.onosproject.net.pi.runtime.PiTableId;
@@ -103,6 +104,11 @@
}
@Override
+ public Optional<PiCounterId> mapTableCounter(PiTableId piTableId) {
+ return Optional.empty();
+ }
+
+ @Override
public Collection<PiPacketOperation> mapOutboundPacket(OutboundPacket packet)
throws PiInterpreterException {
return ImmutableList.of();
diff --git a/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/DefaultP4Interpreter.java b/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/DefaultP4Interpreter.java
index d22fc07..5fb0497 100644
--- a/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/DefaultP4Interpreter.java
+++ b/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/DefaultP4Interpreter.java
@@ -43,6 +43,8 @@
import org.onosproject.net.pi.runtime.PiActionId;
import org.onosproject.net.pi.runtime.PiActionParam;
import org.onosproject.net.pi.runtime.PiActionParamId;
+import org.onosproject.net.pi.runtime.PiCounterId;
+import org.onosproject.net.pi.runtime.PiCounterType;
import org.onosproject.net.pi.runtime.PiHeaderFieldId;
import org.onosproject.net.pi.runtime.PiPacketMetadata;
import org.onosproject.net.pi.runtime.PiPacketMetadataId;
@@ -77,6 +79,7 @@
private static final boolean PACKET_IO_ENABLED = true;
public static final String TABLE0 = "table0";
+ public static final String TABLE0_COUNTER = "table0_counter";
public static final String SEND_TO_CPU = "send_to_cpu";
public static final String PORT = "port";
public static final String DROP = "_drop";
@@ -84,12 +87,17 @@
public static final String EGRESS_PORT = "egress_port";
public static final String INGRESS_PORT = "ingress_port";
+ private static final PiTableId TABLE0_ID = PiTableId.of(TABLE0);
+
protected static final PiHeaderFieldId ETH_DST_ID = PiHeaderFieldId.of("ethernet", "dstAddr");
protected static final PiHeaderFieldId ETH_SRC_ID = PiHeaderFieldId.of("ethernet", "srcAddr");
protected static final PiHeaderFieldId ETH_TYPE_ID = PiHeaderFieldId.of("ethernet", "etherType");
private static final ImmutableBiMap<Integer, PiTableId> TABLE_MAP = ImmutableBiMap.of(
- 0, PiTableId.of(TABLE0));
+ 0, TABLE0_ID);
+
+ private static final ImmutableBiMap<PiTableId, PiCounterId> TABLE_COUNTER_MAP = ImmutableBiMap.of(
+ TABLE0_ID, PiCounterId.of(TABLE0_COUNTER, PiCounterType.DIRECT));
private boolean targetAttributesInitialized = false;
@@ -192,6 +200,11 @@
}
@Override
+ public Optional<PiCounterId> mapTableCounter(PiTableId piTableId) {
+ return Optional.ofNullable(TABLE_COUNTER_MAP.get(piTableId));
+ }
+
+ @Override
public Collection<PiPacketOperation> mapOutboundPacket(OutboundPacket packet)
throws PiInterpreterException {
diff --git a/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/DefaultP4PortStatisticsDiscovery.java b/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/DefaultP4PortStatisticsDiscovery.java
index 2946304..b127855 100644
--- a/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/DefaultP4PortStatisticsDiscovery.java
+++ b/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/DefaultP4PortStatisticsDiscovery.java
@@ -24,6 +24,7 @@
import org.onosproject.net.pi.runtime.PiCounterCellData;
import org.onosproject.net.pi.runtime.PiCounterCellId;
import org.onosproject.net.pi.runtime.PiCounterId;
+import org.onosproject.net.pi.runtime.PiIndirectCounterCellId;
import java.util.Collection;
import java.util.Collections;
@@ -32,6 +33,8 @@
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
+import static org.onosproject.net.pi.runtime.PiCounterType.INDIRECT;
+
/**
* Implementation of a PortStatisticsBehaviour that can be used for any P4 program based on default.p4 (i.e. those
* under onos/tools/test/p4src).
@@ -39,8 +42,8 @@
public class DefaultP4PortStatisticsDiscovery extends AbstractP4RuntimeHandlerBehaviour
implements PortStatisticsDiscovery {
- private static final PiCounterId INGRESS_COUNTER_ID = PiCounterId.of("ingress_port_counter");
- private static final PiCounterId EGRESS_COUNTER_ID = PiCounterId.of("egress_port_counter");
+ private static final PiCounterId INGRESS_COUNTER_ID = PiCounterId.of("ingress_port_counter", INDIRECT);
+ private static final PiCounterId EGRESS_COUNTER_ID = PiCounterId.of("egress_port_counter", INDIRECT);
@Override
public Collection<PortStatistics> discoverPortStatistics() {
@@ -54,14 +57,14 @@
deviceService.getPorts(deviceId)
.forEach(p -> portStatBuilders.put(p.number().toLong(),
DefaultPortStatistics.builder()
- .setPort((int) p.number().toLong())
+ .setPort(p.number())
.setDeviceId(deviceId)));
Set<PiCounterCellId> counterCellIds = Sets.newHashSet();
portStatBuilders.keySet().forEach(p -> {
// Counter cell/index = port number.
- counterCellIds.add(PiCounterCellId.of(INGRESS_COUNTER_ID, p));
- counterCellIds.add(PiCounterCellId.of(EGRESS_COUNTER_ID, p));
+ counterCellIds.add(PiIndirectCounterCellId.of(INGRESS_COUNTER_ID, p));
+ counterCellIds.add(PiIndirectCounterCellId.of(EGRESS_COUNTER_ID, p));
});
Collection<PiCounterCellData> counterEntryResponse;
@@ -73,20 +76,25 @@
return Collections.emptyList();
}
- counterEntryResponse.forEach(counterEntry -> {
- if (!portStatBuilders.containsKey(counterEntry.cellId().index())) {
- log.warn("Unrecognized counter index {}, skipping", counterEntry);
+ counterEntryResponse.forEach(counterData -> {
+ if (counterData.cellId().type() != INDIRECT) {
+ log.warn("Invalid counter data type {}, skipping", counterData.cellId().type());
return;
}
- DefaultPortStatistics.Builder statsBuilder = portStatBuilders.get(counterEntry.cellId().index());
- if (counterEntry.cellId().counterId().equals(INGRESS_COUNTER_ID)) {
- statsBuilder.setPacketsReceived(counterEntry.packets());
- statsBuilder.setBytesReceived(counterEntry.bytes());
- } else if (counterEntry.cellId().counterId().equals(EGRESS_COUNTER_ID)) {
- statsBuilder.setPacketsSent(counterEntry.packets());
- statsBuilder.setBytesSent(counterEntry.bytes());
+ PiIndirectCounterCellId indCellId = (PiIndirectCounterCellId) counterData.cellId();
+ if (!portStatBuilders.containsKey(indCellId.index())) {
+ log.warn("Unrecognized counter index {}, skipping", counterData);
+ return;
+ }
+ DefaultPortStatistics.Builder statsBuilder = portStatBuilders.get(indCellId.index());
+ if (counterData.cellId().counterId().equals(INGRESS_COUNTER_ID)) {
+ statsBuilder.setPacketsReceived(counterData.packets());
+ statsBuilder.setBytesReceived(counterData.bytes());
+ } else if (counterData.cellId().counterId().equals(EGRESS_COUNTER_ID)) {
+ statsBuilder.setPacketsSent(counterData.packets());
+ statsBuilder.setBytesSent(counterData.bytes());
} else {
- log.warn("Unrecognized counter ID {}, skipping", counterEntry);
+ log.warn("Unrecognized counter ID {}, skipping", counterData);
}
});
diff --git a/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/P4RuntimeFlowRuleProgrammable.java b/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/P4RuntimeFlowRuleProgrammable.java
index ad9329a..50b808e 100644
--- a/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/P4RuntimeFlowRuleProgrammable.java
+++ b/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/P4RuntimeFlowRuleProgrammable.java
@@ -19,6 +19,7 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
+import io.grpc.StatusRuntimeException;
import org.onosproject.net.flow.DefaultFlowEntry;
import org.onosproject.net.flow.FlowEntry;
import org.onosproject.net.flow.FlowRule;
@@ -26,6 +27,10 @@
import org.onosproject.net.pi.model.PiPipelineInterpreter;
import org.onosproject.net.pi.model.PiPipelineModel;
import org.onosproject.net.pi.model.PiTableModel;
+import org.onosproject.net.pi.runtime.PiCounterCellData;
+import org.onosproject.net.pi.runtime.PiCounterCellId;
+import org.onosproject.net.pi.runtime.PiCounterId;
+import org.onosproject.net.pi.runtime.PiDirectCounterCellId;
import org.onosproject.net.pi.runtime.PiFlowRuleTranslationService;
import org.onosproject.net.pi.runtime.PiTableEntry;
import org.onosproject.net.pi.runtime.PiTableId;
@@ -36,6 +41,8 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
+import java.util.Set;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.locks.Lock;
@@ -72,6 +79,13 @@
// TODO: can remove this check as soon as the BMv2 bug when reading ECMP entries is fixed.
private boolean ignoreDeviceWhenGet = true;
+ /*
+ If true, we read all direct counters of a table with one request. Otherwise, send as many request as the number of
+ table entries.
+ */
+ // TODO: set to true as soon as the feature is implemented in P4Runtime.
+ private boolean readAllDirectCounters = false;
+
// Needed to synchronize operations over the same table entry.
private static final ConcurrentMap<P4RuntimeTableEntryReference, Lock> ENTRY_LOCKS = Maps.newConcurrentMap();
@@ -132,33 +146,70 @@
Collection<PiTableEntry> installedEntries;
try {
+ // TODO: optimize by dumping entries and counters in parallel, from ALL tables with the same request.
installedEntries = client.dumpTable(piTableId, pipeconf).get();
} catch (InterruptedException | ExecutionException e) {
- log.error("Exception while dumping table {} of {}", piTableId, deviceId, e);
+ if (!(e.getCause() instanceof StatusRuntimeException)) {
+ // gRPC errors are logged in the client.
+ log.error("Exception while dumping table {} of {}", piTableId, deviceId, e);
+ }
return Collections.emptyList();
}
+ Map<PiTableEntry, PiCounterCellData> counterCellMap;
+ try {
+ if (interpreter.mapTableCounter(piTableId).isPresent()) {
+ PiCounterId piCounterId = interpreter.mapTableCounter(piTableId).get();
+ Collection<PiCounterCellData> cellDatas;
+ if (readAllDirectCounters) {
+ cellDatas = client.readAllCounterCells(Collections.singleton(piCounterId), pipeconf).get();
+ } else {
+ Set<PiCounterCellId> cellIds = installedEntries.stream()
+ .map(entry -> PiDirectCounterCellId.of(piCounterId, entry))
+ .collect(Collectors.toSet());
+ cellDatas = client.readCounterCells(cellIds, pipeconf).get();
+ }
+ counterCellMap = cellDatas.stream()
+ .collect(Collectors.toMap(c -> ((PiDirectCounterCellId) c.cellId()).tableEntry(), c -> c));
+ } else {
+ counterCellMap = Collections.emptyMap();
+ }
+ installedEntries = client.dumpTable(piTableId, pipeconf).get();
+ } catch (InterruptedException | ExecutionException e) {
+ if (!(e.getCause() instanceof StatusRuntimeException)) {
+ // gRPC errors are logged in the client.
+ log.error("Exception while reading counters of table {} of {}", piTableId, deviceId, e);
+ }
+ counterCellMap = Collections.emptyMap();
+ }
+
for (PiTableEntry installedEntry : installedEntries) {
- P4RuntimeTableEntryReference entryRef = new P4RuntimeTableEntryReference(deviceId, piTableId,
+ P4RuntimeTableEntryReference entryRef = new P4RuntimeTableEntryReference(deviceId,
+ piTableId,
installedEntry.matchKey());
- P4RuntimeFlowRuleWrapper frWrapper = ENTRY_STORE.get(entryRef);
-
-
- if (frWrapper == null) {
+ if (!ENTRY_STORE.containsKey(entryRef)) {
// Inconsistent entry
inconsistentEntries.add(installedEntry);
continue; // next one.
}
- // TODO: implement table entry counter retrieval.
+ P4RuntimeFlowRuleWrapper frWrapper = ENTRY_STORE.get(entryRef);
+
long bytes = 0L;
long packets = 0L;
+ if (counterCellMap.containsKey(installedEntry)) {
+ PiCounterCellData counterCellData = counterCellMap.get(installedEntry);
+ bytes = counterCellData.bytes();
+ packets = counterCellData.packets();
+ }
- FlowEntry entry = new DefaultFlowEntry(frWrapper.rule(), ADDED, frWrapper.lifeInSeconds(),
- packets, bytes);
- resultBuilder.add(entry);
+ resultBuilder.add(new DefaultFlowEntry(frWrapper.rule(),
+ ADDED,
+ frWrapper.lifeInSeconds(),
+ packets,
+ bytes));
}
}
diff --git a/protocols/p4runtime/ctl/src/main/java/org/onosproject/p4runtime/ctl/CounterEntryCodec.java b/protocols/p4runtime/ctl/src/main/java/org/onosproject/p4runtime/ctl/CounterEntryCodec.java
new file mode 100644
index 0000000..025a5a3
--- /dev/null
+++ b/protocols/p4runtime/ctl/src/main/java/org/onosproject/p4runtime/ctl/CounterEntryCodec.java
@@ -0,0 +1,201 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.p4runtime.ctl;
+
+import org.onosproject.net.pi.model.PiPipeconf;
+import org.onosproject.net.pi.runtime.PiCounterCellData;
+import org.onosproject.net.pi.runtime.PiCounterCellId;
+import org.onosproject.net.pi.runtime.PiCounterId;
+import org.onosproject.net.pi.runtime.PiDirectCounterCellId;
+import org.onosproject.net.pi.runtime.PiIndirectCounterCellId;
+import org.onosproject.net.pi.runtime.PiTableEntry;
+import org.slf4j.Logger;
+import p4.P4RuntimeOuterClass.CounterData;
+import p4.P4RuntimeOuterClass.CounterEntry;
+import p4.P4RuntimeOuterClass.DirectCounterEntry;
+import p4.P4RuntimeOuterClass.Entity;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+import static java.lang.String.format;
+import static org.slf4j.LoggerFactory.getLogger;
+import static p4.P4RuntimeOuterClass.Entity.EntityCase.COUNTER_ENTRY;
+import static p4.P4RuntimeOuterClass.Entity.EntityCase.DIRECT_COUNTER_ENTRY;
+
+/**
+ * Encoder/decoder of PI counter IDs to counter entry protobuf messages, and vice versa.
+ */
+final class CounterEntryCodec {
+
+ private static final Logger log = getLogger(CounterEntryCodec.class);
+
+ private CounterEntryCodec() {
+ // Hides constructor.
+ }
+
+ /**
+ * Returns a collection of P4Runtime entity protobuf messages describing both counter or direct counter entries,
+ * encoded from the given collection of PI counter cell identifiers, for the given pipeconf. If a PI counter cell
+ * identifier cannot be encoded, it is skipped, hence the returned collection might have different size than the
+ * input one.
+ * <p>
+ * This method takes as parameter also a map between numeric P4Info IDs and PI counter IDs, that will be populated
+ * during the process and that is then needed to aid in the decode process.
+ *
+ * @param cellIds counter cell identifiers
+ * @param counterIdMap counter ID map (empty, it will be populated during this method execution)
+ * @param pipeconf pipeconf
+ * @return collection of entity messages describing both counter or direct counter entries
+ */
+ static Collection<Entity> encodePiCounterCellIds(Collection<PiCounterCellId> cellIds,
+ Map<Integer, PiCounterId> counterIdMap,
+ PiPipeconf pipeconf) {
+ return cellIds
+ .stream()
+ .map(cellId -> {
+ try {
+ return encodePiCounterCellId(cellId, counterIdMap, pipeconf);
+ } catch (P4InfoBrowser.NotFoundException | EncodeException e) {
+ log.warn("Unable to encode PI counter cell id: {}", e.getMessage());
+ return null;
+ }
+ })
+ .filter(Objects::nonNull)
+ .collect(Collectors.toList());
+ }
+
+ /**
+ * Returns a collection of PI counter cell data, decoded from the given P4Runtime entity protobuf messages
+ * describing both counter or direct counter entries, for the given counter ID map (populated by {@link
+ * #encodePiCounterCellIds(Collection, Map, PiPipeconf)}), and pipeconf. If an entity message cannot be encoded, it
+ * is skipped, hence the returned collection might have different size than the input one.
+ *
+ * @param entities P4Runtime entity messages
+ * @param counterIdMap counter ID map (previously populated)
+ * @param pipeconf pipeconf
+ * @return collection of PI counter cell data
+ */
+ static Collection<PiCounterCellData> decodeCounterEntities(Collection<Entity> entities,
+ Map<Integer, PiCounterId> counterIdMap,
+ PiPipeconf pipeconf) {
+ return entities
+ .stream()
+ .filter(entity -> entity.getEntityCase() == COUNTER_ENTRY ||
+ entity.getEntityCase() == DIRECT_COUNTER_ENTRY)
+ .map(entity -> {
+ try {
+ return decodeCounterEntity(entity, counterIdMap, pipeconf);
+ } catch (EncodeException | P4InfoBrowser.NotFoundException e) {
+ log.warn("Unable to decode counter entity message: {}", e.getMessage());
+ return null;
+ }
+ })
+ .filter(Objects::nonNull)
+ .collect(Collectors.toList());
+ }
+
+ private static Entity encodePiCounterCellId(PiCounterCellId cellId, Map<Integer, PiCounterId> counterIdMap,
+ PiPipeconf pipeconf)
+ throws P4InfoBrowser.NotFoundException, EncodeException {
+
+ final P4InfoBrowser browser = PipeconfHelper.getP4InfoBrowser(pipeconf);
+
+ int counterId;
+ Entity entity;
+ // Encode PI cell ID into entity message and add to read request.
+ switch (cellId.type()) {
+ case INDIRECT:
+ counterId = browser.counters().getByNameOrAlias(cellId.counterId().name()).getPreamble().getId();
+ PiIndirectCounterCellId indCellId = (PiIndirectCounterCellId) cellId;
+ entity = Entity.newBuilder().setCounterEntry(CounterEntry.newBuilder()
+ .setCounterId(counterId)
+ .setIndex(indCellId.index())
+ .build())
+ .build();
+ break;
+ case DIRECT:
+ counterId = browser.directCounters().getByNameOrAlias(cellId.counterId().name()).getPreamble().getId();
+ PiDirectCounterCellId dirCellId = (PiDirectCounterCellId) cellId;
+ DirectCounterEntry.Builder entryBuilder = DirectCounterEntry.newBuilder().setCounterId(counterId);
+ if (!dirCellId.tableEntry().equals(PiTableEntry.EMTPY)) {
+ entryBuilder.setTableEntry(TableEntryEncoder.encode(dirCellId.tableEntry(), pipeconf));
+ }
+ entity = Entity.newBuilder().setDirectCounterEntry(entryBuilder.build()).build();
+ break;
+ default:
+ throw new EncodeException(format("Unrecognized PI counter cell ID type '%s'", cellId.type()));
+ }
+ counterIdMap.put(counterId, cellId.counterId());
+
+ return entity;
+ }
+
+ private static PiCounterCellData decodeCounterEntity(Entity entity, Map<Integer, PiCounterId> counterIdMap,
+ PiPipeconf pipeconf)
+ throws EncodeException, P4InfoBrowser.NotFoundException {
+
+ int counterId;
+ CounterData counterData;
+
+ if (entity.getEntityCase() == COUNTER_ENTRY) {
+ counterId = entity.getCounterEntry().getCounterId();
+ counterData = entity.getCounterEntry().getData();
+ } else {
+ counterId = entity.getDirectCounterEntry().getCounterId();
+ counterData = entity.getDirectCounterEntry().getData();
+ }
+
+ // Process only counter IDs that were requested in the first place.
+ if (!counterIdMap.containsKey(counterId)) {
+ throw new EncodeException(format("Unrecognized counter ID '%s'", counterId));
+ }
+
+ PiCounterId piCounterId = counterIdMap.get(counterId);
+
+ // Compute PI cell ID.
+ PiCounterCellId piCellId;
+
+ switch (piCounterId.type()) {
+ case INDIRECT:
+ if (entity.getEntityCase() != COUNTER_ENTRY) {
+ throw new EncodeException(format(
+ "Counter ID '%s' is indirect, but processed entity is %s",
+ piCounterId, entity.getEntityCase()));
+ }
+ piCellId = PiIndirectCounterCellId.of(piCounterId,
+ entity.getCounterEntry().getIndex());
+ break;
+ case DIRECT:
+ if (entity.getEntityCase() != DIRECT_COUNTER_ENTRY) {
+ throw new EncodeException(format(
+ "Counter ID '%s' is direct, but processed entity is %s",
+ piCounterId, entity.getEntityCase()));
+ }
+ PiTableEntry piTableEntry = TableEntryEncoder.decode(entity.getDirectCounterEntry().getTableEntry(),
+ pipeconf);
+ piCellId = PiDirectCounterCellId.of(piCounterId, piTableEntry);
+ break;
+ default:
+ throw new EncodeException(format("Unrecognized PI counter ID type '%s'", piCounterId.type()));
+ }
+
+ return new PiCounterCellData(piCellId, counterData.getPacketCount(), counterData.getByteCount());
+ }
+}
diff --git a/protocols/p4runtime/ctl/src/main/java/org/onosproject/p4runtime/ctl/P4RuntimeClientImpl.java b/protocols/p4runtime/ctl/src/main/java/org/onosproject/p4runtime/ctl/P4RuntimeClientImpl.java
index 87652c3..4dff7ea 100644
--- a/protocols/p4runtime/ctl/src/main/java/org/onosproject/p4runtime/ctl/P4RuntimeClientImpl.java
+++ b/protocols/p4runtime/ctl/src/main/java/org/onosproject/p4runtime/ctl/P4RuntimeClientImpl.java
@@ -16,9 +16,9 @@
package org.onosproject.p4runtime.ctl;
-import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
import com.google.protobuf.ByteString;
import io.grpc.Context;
import io.grpc.ManagedChannel;
@@ -31,6 +31,8 @@
import org.onosproject.net.pi.runtime.PiCounterCellData;
import org.onosproject.net.pi.runtime.PiCounterCellId;
import org.onosproject.net.pi.runtime.PiCounterId;
+import org.onosproject.net.pi.runtime.PiDirectCounterCellId;
+import org.onosproject.net.pi.runtime.PiIndirectCounterCellId;
import org.onosproject.net.pi.runtime.PiPacketOperation;
import org.onosproject.net.pi.runtime.PiPipeconfService;
import org.onosproject.net.pi.runtime.PiTableEntry;
@@ -39,7 +41,6 @@
import org.onosproject.p4runtime.api.P4RuntimeEvent;
import org.slf4j.Logger;
import p4.P4RuntimeGrpc;
-import p4.P4RuntimeOuterClass.CounterEntry;
import p4.P4RuntimeOuterClass.Entity;
import p4.P4RuntimeOuterClass.ForwardingPipelineConfig;
import p4.P4RuntimeOuterClass.MasterArbitrationUpdate;
@@ -78,7 +79,6 @@
import static org.onlab.util.Tools.groupedThreads;
import static org.onosproject.net.pi.model.PiPipeconf.ExtensionType;
import static org.slf4j.LoggerFactory.getLogger;
-import static p4.P4RuntimeOuterClass.Entity.EntityCase.COUNTER_ENTRY;
import static p4.P4RuntimeOuterClass.Entity.EntityCase.TABLE_ENTRY;
import static p4.P4RuntimeOuterClass.PacketOut;
import static p4.P4RuntimeOuterClass.SetForwardingPipelineConfigRequest.Action.VERIFY_AND_COMMIT;
@@ -88,11 +88,6 @@
*/
public final class P4RuntimeClientImpl implements P4RuntimeClient {
- private static final int DEADLINE_SECONDS = 15;
-
- // FIXME: use static election ID, since mastership arbitration is not yet support on BMv2 or Tofino.
- private static final int ELECTION_ID = 1;
-
private static final Map<WriteOperationType, Update.Type> UPDATE_TYPES = ImmutableMap.of(
WriteOperationType.UNSPECIFIED, Update.Type.UNSPECIFIED,
WriteOperationType.INSERT, Update.Type.INSERT,
@@ -143,7 +138,11 @@
try {
return supplier.get();
} catch (Throwable ex) {
- log.error("Exception in P4Runtime client of {}, executing {}", deviceId, opDescription, ex);
+ if (ex instanceof StatusRuntimeException) {
+ log.warn("Unable to execute {} on {}: {}", opDescription, deviceId, ex.toString());
+ } else {
+ log.error("Exception in client of {}, executing {}", deviceId, opDescription, ex);
+ }
throw ex;
} finally {
writeLock.unlock();
@@ -193,10 +192,31 @@
@Override
public CompletableFuture<Collection<PiCounterCellData>> readAllCounterCells(Set<PiCounterId> counterIds,
PiPipeconf pipeconf) {
- Set<PiCounterCellId> cellIds = counterIds.stream()
- // Cell with index 0 means all cells.
- .map(counterId -> PiCounterCellId.of(counterId, 0))
- .collect(Collectors.toSet());
+
+ /*
+ From p4runtime.proto, the scope of a ReadRequest is defined as follows:
+ CounterEntry:
+ - All counter cells for all meters if counter_id = 0 (default).
+ - All counter cells for given counter_id if index = 0 (default).
+ DirectCounterEntry:
+ - All counter cells for all meters if counter_id = 0 (default).
+ - All counter cells for given counter_id if table_entry.match is empty.
+ */
+
+ Set<PiCounterCellId> cellIds = Sets.newHashSet();
+
+ for (PiCounterId counterId : counterIds) {
+ switch (counterId.type()) {
+ case INDIRECT:
+ cellIds.add(PiIndirectCounterCellId.of(counterId, 0));
+ break;
+ case DIRECT:
+ cellIds.add(PiDirectCounterCellId.of(counterId, PiTableEntry.EMTPY));
+ break;
+ default:
+ log.warn("Unrecognized PI counter ID '{}'", counterId.type());
+ }
+ }
return supplyInContext(() -> doReadCounterCells(cellIds, pipeconf),
"readAllCounterCells-" + cellIds.hashCode());
@@ -433,62 +453,32 @@
private Collection<PiCounterCellData> doReadCounterCells(Collection<PiCounterCellId> cellIds, PiPipeconf pipeconf) {
- // From p4runtime.proto:
- // For ReadRequest, the scope is defined as follows:
- // - All counter cells for all meters if counter_id = 0 (default).
- // - All counter cells for given counter_id if index = 0 (default).
-
- final ReadRequest.Builder requestBuilder = ReadRequest.newBuilder().setDeviceId(p4DeviceId);
- final P4InfoBrowser browser = PipeconfHelper.getP4InfoBrowser(pipeconf);
+ // We use this map to remember the original PI counter IDs of the returned response.
final Map<Integer, PiCounterId> counterIdMap = Maps.newHashMap();
- for (PiCounterCellId cellId : cellIds) {
- int counterId;
- try {
- counterId = browser.counters().getByNameOrAlias(cellId.counterId().id()).getPreamble().getId();
- } catch (P4InfoBrowser.NotFoundException e) {
- log.warn("Skipping counter cell {}: {}", cellId, e.getMessage());
- continue;
- }
- requestBuilder
- .addEntities(Entity.newBuilder()
- .setCounterEntry(CounterEntry.newBuilder()
- .setCounterId(counterId)
- .setIndex(cellId.index())
- .build()));
- counterIdMap.put(counterId, cellId.counterId());
+ final ReadRequest request = ReadRequest.newBuilder()
+ .setDeviceId(p4DeviceId)
+ .addAllEntities(CounterEntryCodec.encodePiCounterCellIds(cellIds, counterIdMap, pipeconf))
+ .build();
+
+ if (request.getEntitiesList().size() == 0) {
+ return Collections.emptyList();
}
- final Iterator<ReadResponse> responses;
+ final Iterable<ReadResponse> responses;
try {
- responses = blockingStub.read(requestBuilder.build());
+ responses = () -> blockingStub.read(request);
} catch (StatusRuntimeException e) {
log.warn("Unable to read counters: {}", e.getMessage());
return Collections.emptyList();
}
- final Iterable<ReadResponse> responseIterable = () -> responses;
- final ImmutableList.Builder<PiCounterCellData> piCounterEntryListBuilder = ImmutableList.builder();
-
- StreamSupport
- .stream(responseIterable.spliterator(), false)
+ List<Entity> entities = StreamSupport.stream(responses.spliterator(), false)
.map(ReadResponse::getEntitiesList)
.flatMap(List::stream)
- .filter(entity -> entity.getEntityCase() == COUNTER_ENTRY)
- .map(Entity::getCounterEntry)
- .forEach(counterEntryMsg -> {
- if (!counterIdMap.containsKey(counterEntryMsg.getCounterId())) {
- log.warn("Unrecognized counter ID '{}', skipping", counterEntryMsg.getCounterId());
- return;
- }
- PiCounterCellId cellId = PiCounterCellId.of(counterIdMap.get(counterEntryMsg.getCounterId()),
- counterEntryMsg.getIndex());
- piCounterEntryListBuilder.add(new PiCounterCellData(cellId,
- counterEntryMsg.getData().getPacketCount(),
- counterEntryMsg.getData().getByteCount()));
- });
+ .collect(Collectors.toList());
- return piCounterEntryListBuilder.build();
+ return CounterEntryCodec.decodeCounterEntities(entities, counterIdMap, pipeconf);
}
/**
diff --git a/protocols/p4runtime/ctl/src/main/java/org/onosproject/p4runtime/ctl/TableEntryEncoder.java b/protocols/p4runtime/ctl/src/main/java/org/onosproject/p4runtime/ctl/TableEntryEncoder.java
index 0dd82f3..9ffc18f 100644
--- a/protocols/p4runtime/ctl/src/main/java/org/onosproject/p4runtime/ctl/TableEntryEncoder.java
+++ b/protocols/p4runtime/ctl/src/main/java/org/onosproject/p4runtime/ctl/TableEntryEncoder.java
@@ -70,8 +70,8 @@
}
/**
- * Returns a collection of P4Runtime table entry protobuf messages, encoded from the given collection of PI
- * table entries for the given pipeconf. If a PI table entry cannot be encoded, it is skipped, hence the returned
+ * Returns a collection of P4Runtime table entry protobuf messages, encoded from the given collection of PI table
+ * entries for the given pipeconf. If a PI table entry cannot be encoded, it is skipped, hence the returned
* collection might have different size than the input one.
* <p>
* Please check the log for an explanation of any error that might have occurred.
@@ -103,6 +103,26 @@
}
/**
+ * Same as {@link #encode(Collection, PiPipeconf)} but encodes only one entry.
+ *
+ * @param piTableEntry table entry
+ * @param pipeconf pipeconf
+ * @return encoded table entry message
+ * @throws EncodeException if entry cannot be encoded
+ * @throws P4InfoBrowser.NotFoundException if the required information cannot be find in the pipeconf's P4info
+ */
+ static TableEntry encode(PiTableEntry piTableEntry, PiPipeconf pipeconf)
+ throws EncodeException, P4InfoBrowser.NotFoundException {
+
+ P4InfoBrowser browser = PipeconfHelper.getP4InfoBrowser(pipeconf);
+ if (browser == null) {
+ throw new EncodeException(format("Unable to get a P4Info browser for pipeconf %s", pipeconf.id()));
+ }
+
+ return encodePiTableEntry(piTableEntry, browser);
+ }
+
+ /**
* Returns a collection of PI table entry objects, decoded from the given collection of P4Runtime table entry
* messages for the given pipeconf. If a table entry message cannot be decoded, it is skipped, hence the returned
* collection might have different size than the input one.
@@ -135,12 +155,63 @@
return piTableEntryListBuilder.build();
}
+ /**
+ * Same as {@link #decode(Collection, PiPipeconf)} but decodes only one entry.
+ *
+ * @param tableEntryMsg table entry message
+ * @param pipeconf pipeconf
+ * @return decoded PI table entry
+ * @throws EncodeException if message cannot be decoded
+ * @throws P4InfoBrowser.NotFoundException if the required information cannot be find in the pipeconf's P4info
+ */
+ static PiTableEntry decode(TableEntry tableEntryMsg, PiPipeconf pipeconf)
+ throws EncodeException, P4InfoBrowser.NotFoundException {
+
+ P4InfoBrowser browser = PipeconfHelper.getP4InfoBrowser(pipeconf);
+ if (browser == null) {
+ throw new EncodeException(format("Unable to get a P4Info browser for pipeconf %s", pipeconf.id()));
+ }
+ return decodeTableEntryMsg(tableEntryMsg, browser);
+ }
+
+ /**
+ * Returns a table entry protobuf message, encoded from the given table id and match key, for the given pipeconf.
+ * The returned table entry message can be only used to reference an existing entry, i.e. a read operation, and not
+ * a write one wince it misses other fields (action, priority, etc.).
+ *
+ * @param tableId table identifier
+ * @param matchKey match key
+ * @param pipeconf pipeconf
+ * @return table entry message
+ * @throws EncodeException if message cannot be encoded
+ * @throws P4InfoBrowser.NotFoundException if the required information cannot be find in the pipeconf's P4info
+ */
+ static TableEntry encode(PiTableId tableId, PiMatchKey matchKey, PiPipeconf pipeconf)
+ throws EncodeException, P4InfoBrowser.NotFoundException {
+
+ P4InfoBrowser browser = PipeconfHelper.getP4InfoBrowser(pipeconf);
+ TableEntry.Builder tableEntryMsgBuilder = TableEntry.newBuilder();
+
+ //FIXME this throws some kind of NPE
+ P4InfoOuterClass.Table tableInfo = browser.tables().getByName(tableId.id());
+
+ // Table id.
+ tableEntryMsgBuilder.setTableId(tableInfo.getPreamble().getId());
+
+ // Field matches.
+ for (PiFieldMatch piFieldMatch : matchKey.fieldMatches()) {
+ tableEntryMsgBuilder.addMatch(encodePiFieldMatch(piFieldMatch, tableInfo, browser));
+ }
+
+ return tableEntryMsgBuilder.build();
+ }
+
private static TableEntry encodePiTableEntry(PiTableEntry piTableEntry, P4InfoBrowser browser)
throws P4InfoBrowser.NotFoundException, EncodeException {
TableEntry.Builder tableEntryMsgBuilder = TableEntry.newBuilder();
- //FIXME this thorws some kind of NPE
+ //FIXME this throws some kind of NPE
P4InfoOuterClass.Table tableInfo = browser.tables().getByName(piTableEntry.table().id());
// Table id.
@@ -193,11 +264,7 @@
// FIXME: how to decode table entry messages with timeout, given that the timeout value is lost after encoding?
// Match key for field matches.
- PiMatchKey.Builder piMatchKeyBuilder = PiMatchKey.builder();
- for (FieldMatch fieldMatchMsg : tableEntryMsg.getMatchList()) {
- piMatchKeyBuilder.addFieldMatch(decodeFieldMatchMsg(fieldMatchMsg, tableInfo, browser));
- }
- piTableEntryBuilder.withMatchKey(piMatchKeyBuilder.build());
+ piTableEntryBuilder.withMatchKey(decodeFieldMatchMsgs(tableEntryMsg.getMatchList(), tableInfo, browser));
return piTableEntryBuilder.build();
}
@@ -280,6 +347,33 @@
}
}
+ /**
+ * Returns a PI match key, decoded from the given table entry protobuf message, for the given pipeconf.
+ *
+ * @param tableEntryMsg table entry message
+ * @param pipeconf pipeconf
+ * @return PI match key
+ * @throws EncodeException if message cannot be decoded
+ * @throws P4InfoBrowser.NotFoundException if the required information cannot be find in the pipeconf's P4info
+ */
+ static PiMatchKey decodeMatchKey(TableEntry tableEntryMsg, PiPipeconf pipeconf)
+ throws P4InfoBrowser.NotFoundException, EncodeException {
+ P4InfoBrowser browser = PipeconfHelper.getP4InfoBrowser(pipeconf);
+ P4InfoOuterClass.Table tableInfo = browser.tables().getById(tableEntryMsg.getTableId());
+ return decodeFieldMatchMsgs(tableEntryMsg.getMatchList(), tableInfo, browser);
+ }
+
+ private static PiMatchKey decodeFieldMatchMsgs(Collection<FieldMatch> fieldMatchs, P4InfoOuterClass.Table tableInfo,
+ P4InfoBrowser browser)
+ throws P4InfoBrowser.NotFoundException, EncodeException {
+ // Match key for field matches.
+ PiMatchKey.Builder piMatchKeyBuilder = PiMatchKey.builder();
+ for (FieldMatch fieldMatchMsg : fieldMatchs) {
+ piMatchKeyBuilder.addFieldMatch(decodeFieldMatchMsg(fieldMatchMsg, tableInfo, browser));
+ }
+ return piMatchKeyBuilder.build();
+ }
+
private static PiFieldMatch decodeFieldMatchMsg(FieldMatch fieldMatchMsg, P4InfoOuterClass.Table tableInfo,
P4InfoBrowser browser)
throws P4InfoBrowser.NotFoundException, EncodeException {
diff --git a/providers/host/src/main/java/org/onosproject/provider/host/impl/HostLocationProvider.java b/providers/host/src/main/java/org/onosproject/provider/host/impl/HostLocationProvider.java
index 90efcf4..a0d6e37 100644
--- a/providers/host/src/main/java/org/onosproject/provider/host/impl/HostLocationProvider.java
+++ b/providers/host/src/main/java/org/onosproject/provider/host/impl/HostLocationProvider.java
@@ -151,13 +151,11 @@
private boolean requestIpv6ND = false;
@Property(name = "useDhcp", boolValue = false,
- label = "Use DHCP for neighbor discovery by the " +
- "Host Location Provider; default is false")
+ label = "Use DHCP to update IP address of the host; default is false")
private boolean useDhcp = false;
@Property(name = "useDhcp6", boolValue = false,
- label = "Use DHCPv6 for neighbor discovery by the " +
- "Host Location Provider; default is false")
+ label = "Use DHCPv6 to update IP address of the host; default is false")
private boolean useDhcp6 = false;
@Property(name = "requestInterceptsEnabled", boolValue = true,
@@ -541,25 +539,18 @@
// IPv4: update location only
} else if (eth.getEtherType() == Ethernet.TYPE_IPV4) {
- DHCP dhcp = findDhcp(eth).orElse(null);
- if (dhcp != null) {
- if (useDhcp) {
- // learn host (server or client) MAC address
- createOrUpdateHost(hid, srcMac, vlan, hloc, null);
-
- // DHCP ACK: additionally update IP of DHCP client
- if (dhcp.getPacketType().equals(DHCP.MsgType.DHCPACK)) {
- MacAddress hostMac = MacAddress.valueOf(dhcp.getClientHardwareAddress());
- VlanId hostVlan = VlanId.vlanId(eth.getVlanID());
- HostId hostId = HostId.hostId(hostMac, hostVlan);
- updateHostIp(hostId, IpAddress.valueOf(dhcp.getYourIPAddress()));
- }
+ // Update host location
+ createOrUpdateHost(hid, srcMac, vlan, hloc, null);
+ if (useDhcp) {
+ DHCP dhcp = findDhcp(eth).orElse(null);
+ // DHCP ACK: additionally update IP of DHCP client
+ if (dhcp != null && dhcp.getPacketType().equals(DHCP.MsgType.DHCPACK)) {
+ MacAddress hostMac = MacAddress.valueOf(dhcp.getClientHardwareAddress());
+ VlanId hostVlan = VlanId.vlanId(eth.getVlanID());
+ HostId hostId = HostId.hostId(hostMac, hostVlan);
+ updateHostIp(hostId, IpAddress.valueOf(dhcp.getYourIPAddress()));
}
- } else {
- // learn host MAC address
- createOrUpdateHost(hid, srcMac, vlan, hloc, null);
}
- //
// NeighborAdvertisement and NeighborSolicitation: possible
// new hosts, update both location and IP.
//
@@ -605,8 +596,8 @@
}
}
- // multicast
- if (eth.isMulticast()) {
+ // multicast, exclude DHCPv6
+ if (eth.isMulticast() && dhcp6 == null) {
return;
}
diff --git a/providers/host/src/test/java/org/onosproject/provider/host/impl/HostLocationProviderTest.java b/providers/host/src/test/java/org/onosproject/provider/host/impl/HostLocationProviderTest.java
index 5c924b5..77e2caa 100644
--- a/providers/host/src/test/java/org/onosproject/provider/host/impl/HostLocationProviderTest.java
+++ b/providers/host/src/test/java/org/onosproject/provider/host/impl/HostLocationProviderTest.java
@@ -439,18 +439,6 @@
}
/**
- * The host store should not updated when we disabled "useDhcp".
- */
- @Test
- public void receiveDhcpButNotEnabled() {
- TestUtils.setField(provider, "useDhcp", false);
- // DHCP Request
- testProcessor.process(new TestDhcpRequestPacketContext(DEV1, VLAN));
- assertThat("receiveDhcpButNotEnabled. No host description expected",
- providerService.descriptions.size(), is(0));
- }
-
- /**
* When receiving NeighborAdvertisement, updates location and IP.
*/
@Test
diff --git a/providers/netcfghost/src/main/java/org/onosproject/provider/netcfghost/NetworkConfigHostProvider.java b/providers/netcfghost/src/main/java/org/onosproject/provider/netcfghost/NetworkConfigHostProvider.java
index fefecab..42278d3 100644
--- a/providers/netcfghost/src/main/java/org/onosproject/provider/netcfghost/NetworkConfigHostProvider.java
+++ b/providers/netcfghost/src/main/java/org/onosproject/provider/netcfghost/NetworkConfigHostProvider.java
@@ -172,15 +172,19 @@
HostId hostId = (HostId) event.subject();
MacAddress mac = hostId.mac();
VlanId vlan = hostId.vlanId();
- BasicHostConfig hostConfig =
- networkConfigRegistry.getConfig(hostId, BasicHostConfig.class);
+ BasicHostConfig hostConfig = networkConfigRegistry.getConfig(hostId, BasicHostConfig.class);
Set<IpAddress> ipAddresses = null;
Set<HostLocation> locations = null;
// Note: There will be no config presented in the CONFIG_REMOVE case
if (hostConfig != null) {
ipAddresses = hostConfig.ipAddresses();
- locations = hostConfig.locations().stream()
+ locations = hostConfig.locations();
+ if (locations == null || locations.size() < 1) {
+ log.debug("Ignore network config event without host locations {}", event);
+ return;
+ }
+ locations = locations.stream()
.map(hostLocation -> new HostLocation(hostLocation, System.currentTimeMillis()))
.collect(Collectors.toSet());
}
diff --git a/tools/test/topos/dual-onos.py b/tools/test/topos/dual-onos.py
new file mode 100644
index 0000000..b0b92ed
--- /dev/null
+++ b/tools/test/topos/dual-onos.py
@@ -0,0 +1,6 @@
+#!/usr/bin/python
+
+from onosnet import run
+from dual import DualTopo
+
+run( DualTopo() )
diff --git a/tools/test/topos/dual.json b/tools/test/topos/dual.json
new file mode 100644
index 0000000..87a22db
--- /dev/null
+++ b/tools/test/topos/dual.json
@@ -0,0 +1,35 @@
+{
+ "devices": {
+ "of:0000000000000001": {
+ "basic": {
+ "name": "SW-A",
+ "latitude": 43.3700,
+ "longitude": -104.6572
+ }
+ },
+ "of:0000000000000002": {
+ "basic": {
+ "name": "SW-B",
+ "latitude": 38.5189,
+ "longitude": -109.2781
+ }
+ }
+ },
+
+ "hosts": {
+ "00:00:00:00:00:01/-1": {
+ "basic": {
+ "locations": [
+ "of:0000000000000001/1",
+ "of:0000000000000002/1"
+ ],
+ "ips": [
+ "10.0.0.1"
+ ],
+ "name": "Host-X",
+ "latitude": 39.9444,
+ "longitude": -91.7822
+ }
+ }
+ }
+}
diff --git a/tools/test/topos/dual.py b/tools/test/topos/dual.py
new file mode 100644
index 0000000..d795a37
--- /dev/null
+++ b/tools/test/topos/dual.py
@@ -0,0 +1,35 @@
+#!/usr/bin/env python
+
+"""
+"""
+from mininet.topo import Topo
+
+class DualTopo( Topo ):
+ """Switches and Dual-homed host"""
+
+ def __init__( self ):
+ """Create a topology."""
+
+ # Initialize Topology
+ Topo.__init__( self )
+
+ # add nodes, switches first...
+ SWA = self.addSwitch( 's1' )
+ SWB = self.addSwitch( 's2' )
+
+ # ... and now hosts
+ HOSTX = self.addHost( 'h1' )
+
+ # add edges between switch and corresponding host
+ self.addLink( SWA, HOSTX )
+ self.addLink( SWB, HOSTX )
+
+ # add edges between switches
+ self.addLink( SWA, SWB, bw=10, delay='1.0ms' )
+
+
+topos = { 'dual': ( lambda: DualTopo() ) }
+
+if __name__ == '__main__':
+ from onosnet import run
+ run( DualTopo() )
diff --git a/tools/test/topos/dual.recipe b/tools/test/topos/dual.recipe
new file mode 100644
index 0000000..99dded7
--- /dev/null
+++ b/tools/test/topos/dual.recipe
@@ -0,0 +1,4 @@
+# Simple Dual topology recipe
+export OTD=2
+export OTL=1
+export OTH=1
diff --git a/utils/misc/src/main/java/org/onlab/packet/DHCP6.java b/utils/misc/src/main/java/org/onlab/packet/DHCP6.java
index 924d181..f807000 100644
--- a/utils/misc/src/main/java/org/onlab/packet/DHCP6.java
+++ b/utils/misc/src/main/java/org/onlab/packet/DHCP6.java
@@ -23,8 +23,10 @@
import org.onlab.packet.dhcp.Dhcp6IaAddressOption;
import org.onlab.packet.dhcp.Dhcp6IaNaOption;
import org.onlab.packet.dhcp.Dhcp6IaTaOption;
+import org.onlab.packet.dhcp.Dhcp6IaPdOption;
import org.onlab.packet.dhcp.Dhcp6Option;
import org.onlab.packet.dhcp.Dhcp6RelayOption;
+import org.onlab.packet.dhcp.Dhcp6InterfaceIdOption;
import java.nio.ByteBuffer;
import java.util.List;
@@ -88,7 +90,8 @@
RELAY_MSG((short) 9), AUTH((short) 11), UNICAST((short) 12),
STATUS_CODE((short) 13), RAPID_COMMIT((short) 14), USER_CLASS((short) 15),
VENDOR_CLASS((short) 16), VENDOR_OPTS((short) 17), INTERFACE_ID((short) 18),
- RECONF_MSG((short) 19), RECONF_ACCEPT((short) 20), SUBSCRIBER_ID((short) 38);
+ RECONF_MSG((short) 19), RECONF_ACCEPT((short) 20), IA_PD((short) 25), IAPREFIX((short) 26),
+ SUBSCRIBER_ID((short) 38);
protected short value;
OptionCode(final short value) {
@@ -100,11 +103,15 @@
}
private static final Map<Short, Deserializer<Dhcp6Option>> OPT_DESERIALIZERS =
- ImmutableMap.of(OptionCode.IA_NA.value, Dhcp6IaNaOption.deserializer(),
- OptionCode.IA_TA.value, Dhcp6IaTaOption.deserializer(),
- OptionCode.IAADDR.value, Dhcp6IaAddressOption.deserializer(),
- OptionCode.RELAY_MSG.value, Dhcp6RelayOption.deserializer(),
- OptionCode.CLIENTID.value, Dhcp6ClientIdOption.deserializer());
+ ImmutableMap.<Short, Deserializer<Dhcp6Option>>builder()
+ .put(OptionCode.IA_NA.value, Dhcp6IaNaOption.deserializer())
+ .put(OptionCode.IA_TA.value, Dhcp6IaTaOption.deserializer())
+ .put(OptionCode.IAADDR.value, Dhcp6IaAddressOption.deserializer())
+ .put(OptionCode.RELAY_MSG.value, Dhcp6RelayOption.deserializer())
+ .put(OptionCode.CLIENTID.value, Dhcp6ClientIdOption.deserializer())
+ .put(OptionCode.IA_PD.value, Dhcp6IaPdOption.deserializer())
+ .put(OptionCode.INTERFACE_ID.value, Dhcp6InterfaceIdOption.deserializer())
+ .build();
// general field
private byte msgType; // 1 byte
diff --git a/utils/misc/src/main/java/org/onlab/packet/dhcp/Dhcp6IaPdOption.java b/utils/misc/src/main/java/org/onlab/packet/dhcp/Dhcp6IaPdOption.java
new file mode 100644
index 0000000..e76f055
--- /dev/null
+++ b/utils/misc/src/main/java/org/onlab/packet/dhcp/Dhcp6IaPdOption.java
@@ -0,0 +1,247 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.onlab.packet.dhcp;
+
+import com.google.common.collect.Lists;
+import org.onlab.packet.DHCP6;
+import org.onlab.packet.DeserializationException;
+import org.onlab.packet.Deserializer;
+
+import java.nio.ByteBuffer;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * DHCPv6 Identity Association for Prefix Delegation Option.
+ * Based on RFC-3633
+ */
+public final class Dhcp6IaPdOption extends Dhcp6Option {
+ public static final int DEFAULT_LEN = 12;
+ private int iaId;
+ private int t1;
+ private int t2;
+ private List<Dhcp6Option> options;
+
+ @Override
+ public short getCode() {
+ return DHCP6.OptionCode.IA_PD.value();
+ }
+
+ @Override
+ public short getLength() {
+ return (short) (DEFAULT_LEN + options.stream()
+ .mapToInt(opt -> (int) opt.getLength() + Dhcp6Option.DEFAULT_LEN)
+ .sum());
+
+ }
+
+ /**
+ * Gets Identity Association ID.
+ * The unique identifier for this IA_PD; the IAID must
+ * be unique among the identifiers for all of this
+ * requesting router's IA_PDs.
+ *
+ * @return the Identity Association ID
+ */
+ public int getIaId() {
+ return iaId;
+ }
+
+ /**
+ * Sets Identity Association ID.
+ *
+ * @param iaId the Identity Association ID.
+ */
+ public void setIaId(int iaId) {
+ this.iaId = iaId;
+ }
+
+ /**
+ * Gets time 1.
+ * The time at which the requesting router should
+ * contact the delegating router from which the
+ * prefixes in the IA_PD were obtained to extend the
+ * lifetimes of the prefixes delegated to the IA_PD;
+ * T1 is a time duration relative to the current time
+ * expressed in units of seconds.
+ *
+ * @return the value of time 1
+ */
+ public int getT1() {
+ return t1;
+ }
+
+ /**
+ * Sets time 1.
+ *
+ * @param t1 the value of time 1
+ */
+ public void setT1(int t1) {
+ this.t1 = t1;
+ }
+
+ /**
+ * Gets time 2.
+ * The time at which the requesting router should
+ * contact any available delegating router to extend
+ * the lifetimes of the prefixes assigned to the
+ * IA_PD; T2 is a time duration relative to the
+ * current time expressed in units of seconds.
+ *
+ * @return the value of time 2
+ */
+ public int getT2() {
+ return t2;
+ }
+
+ /**
+ * Sets time 2.
+ *
+ * @param t2 the value of time 2
+ */
+ public void setT2(int t2) {
+ this.t2 = t2;
+ }
+
+ /**
+ * Gets sub-options.
+ *
+ * @return sub-options of this option
+ */
+ public List<Dhcp6Option> getOptions() {
+ return options;
+ }
+
+ /**
+ * Sets sub-options.
+ *
+ * @param options the sub-options of this option
+ */
+ public void setOptions(List<Dhcp6Option> options) {
+ this.options = options;
+ }
+
+ /**
+ * Default constructor.
+ */
+ public Dhcp6IaPdOption() {
+ }
+
+ /**
+ * Constructs a DHCPv6 IA PD option with DHCPv6 option.
+ *
+ * @param dhcp6Option the DHCPv6 option
+ */
+ public Dhcp6IaPdOption(Dhcp6Option dhcp6Option) {
+ super(dhcp6Option);
+ }
+
+ /**
+ * Gets deserializer.
+ *
+ * @return the deserializer
+ */
+ public static Deserializer<Dhcp6Option> deserializer() {
+ return (data, offset, length) -> {
+ Dhcp6Option dhcp6Option =
+ Dhcp6Option.deserializer().deserialize(data, offset, length);
+ if (dhcp6Option.getLength() < DEFAULT_LEN) {
+ throw new DeserializationException("Invalid IA PD option data");
+ }
+ Dhcp6IaPdOption iaPdOption = new Dhcp6IaPdOption(dhcp6Option);
+ byte[] optionData = iaPdOption.getData();
+ ByteBuffer bb = ByteBuffer.wrap(optionData);
+ iaPdOption.iaId = bb.getInt();
+ iaPdOption.t1 = bb.getInt();
+ iaPdOption.t2 = bb.getInt();
+
+ iaPdOption.options = Lists.newArrayList();
+ while (bb.remaining() >= Dhcp6Option.DEFAULT_LEN) {
+ Dhcp6Option option;
+ ByteBuffer optByteBuffer = ByteBuffer.wrap(optionData,
+ bb.position(),
+ optionData.length - bb.position());
+ short code = optByteBuffer.getShort();
+ short len = optByteBuffer.getShort();
+ int optLen = UNSIGNED_SHORT_MASK & len;
+ byte[] subOptData = new byte[Dhcp6Option.DEFAULT_LEN + optLen];
+ bb.get(subOptData);
+
+ // TODO: put more sub-options?
+ if (code == DHCP6.OptionCode.IAPREFIX.value()) {
+ option = Dhcp6IaPrefixOption.deserializer()
+ .deserialize(subOptData, 0, subOptData.length);
+ } else {
+ option = Dhcp6Option.deserializer()
+ .deserialize(subOptData, 0, subOptData.length);
+ }
+ iaPdOption.options.add(option);
+ }
+ return iaPdOption;
+ };
+ }
+
+ @Override
+ public byte[] serialize() {
+ int payloadLen = DEFAULT_LEN + options.stream()
+ .mapToInt(opt -> (int) opt.getLength() + Dhcp6Option.DEFAULT_LEN)
+ .sum();
+ int len = Dhcp6Option.DEFAULT_LEN + payloadLen;
+ ByteBuffer bb = ByteBuffer.allocate(len);
+ bb.putShort(DHCP6.OptionCode.IA_PD.value());
+ bb.putShort((short) payloadLen);
+ bb.putInt(iaId);
+ bb.putInt(t1);
+ bb.putInt(t2);
+
+ options.stream().map(Dhcp6Option::serialize).forEach(bb::put);
+ return bb.array();
+ }
+
+ @Override
+ public int hashCode() {
+ return 31 * super.hashCode() + Objects.hash(iaId, t1, t2, options);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null || getClass() != obj.getClass()) {
+ return false;
+ }
+ if (!super.equals(obj)) {
+ return false;
+ }
+ final Dhcp6IaPdOption other = (Dhcp6IaPdOption) obj;
+ return Objects.equals(this.iaId, other.iaId)
+ && Objects.equals(this.t1, other.t1)
+ && Objects.equals(this.t2, other.t2)
+ && Objects.equals(this.options, other.options);
+ }
+
+ @Override
+ public String toString() {
+ return getToStringHelper()
+ .add("iaId", iaId)
+ .add("t1", t1)
+ .add("t2", t2)
+ .add("options", options)
+ .toString();
+ }
+}
diff --git a/utils/misc/src/main/java/org/onlab/packet/dhcp/Dhcp6IaPrefixOption.java b/utils/misc/src/main/java/org/onlab/packet/dhcp/Dhcp6IaPrefixOption.java
new file mode 100644
index 0000000..997455d
--- /dev/null
+++ b/utils/misc/src/main/java/org/onlab/packet/dhcp/Dhcp6IaPrefixOption.java
@@ -0,0 +1,226 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.onlab.packet.dhcp;
+
+import org.onlab.packet.DHCP6;
+import org.onlab.packet.Data;
+import org.onlab.packet.DeserializationException;
+import org.onlab.packet.Deserializer;
+import org.onlab.packet.IPacket;
+import org.onlab.packet.Ip6Address;
+
+import java.nio.ByteBuffer;
+import java.util.Objects;
+
+/**
+ * IA Address option for DHCPv6.
+ * Based on RFC-3633.
+ */
+public final class Dhcp6IaPrefixOption extends Dhcp6Option {
+ public static final int DEFAULT_LEN = 25;
+
+ private Ip6Address ip6Prefix;
+ private byte prefixLength;
+ private int preferredLifetime;
+ private int validLifetime;
+ private IPacket options;
+
+ @Override
+ public short getCode() {
+ return DHCP6.OptionCode.IAPREFIX.value();
+ }
+
+ @Override
+ public short getLength() {
+ return (short) (options == null ? DEFAULT_LEN : DEFAULT_LEN + options.serialize().length);
+ }
+
+ /**
+ * Sets IPv6 prefix.
+ *
+ * @param ip6Prefix the IPv6 prefix
+ */
+ public void setIp6Prefix(Ip6Address ip6Prefix) {
+ this.ip6Prefix = ip6Prefix;
+ }
+
+ /**
+ * Sets prefix length.
+ *
+ * @param prefixLength the prefix length
+ */
+ public void setPrefixLength(byte prefixLength) {
+ this.prefixLength = prefixLength;
+ }
+
+ /**
+ * Sets preferred lifetime.
+ *
+ * @param preferredLifetime the preferred lifetime
+ */
+ public void setPreferredLifetime(int preferredLifetime) {
+ this.preferredLifetime = preferredLifetime;
+ }
+
+ /**
+ * Sets valid lifetime.
+ *
+ * @param validLifetime the valid lifetime
+ */
+ public void setValidLifetime(int validLifetime) {
+ this.validLifetime = validLifetime;
+ }
+
+ /**
+ * Sets options data.
+ *
+ * @param options the options data
+ */
+ public void setOptions(IPacket options) {
+ this.options = options;
+ }
+
+ /**
+ * Gets IPv6 address.
+ *
+ * @return the IPv6 address
+ */
+ public Ip6Address getIp6Prefix() {
+ return ip6Prefix;
+ }
+
+ /**
+ * Gets prefix length.
+ *
+ * @return the prefix length
+ */
+ public byte getPrefixLength() {
+ return prefixLength;
+ }
+
+ /**
+ * Gets preferred lifetime.
+ *
+ * @return the preferred lifetime
+ */
+ public int getPreferredLifetime() {
+ return preferredLifetime;
+ }
+
+ /**
+ * Gets valid lifetime.
+ *
+ * @return the valid lifetime
+ */
+ public int getValidLifetime() {
+ return validLifetime;
+ }
+
+ /**
+ * Gets options of IA Address option.
+ *
+ * @return the options data
+ */
+ public IPacket getOptions() {
+ return options;
+ }
+
+ public static Deserializer<Dhcp6Option> deserializer() {
+ return (data, offset, length) -> {
+ Dhcp6IaPrefixOption iaPrefixOption = new Dhcp6IaPrefixOption();
+ Dhcp6Option dhcp6Option =
+ Dhcp6Option.deserializer().deserialize(data, offset, length);
+ iaPrefixOption.setPayload(dhcp6Option.getPayload());
+ if (dhcp6Option.getLength() < DEFAULT_LEN) {
+ throw new DeserializationException("Invalid length of IA prefix option");
+ }
+ ByteBuffer bb = ByteBuffer.wrap(dhcp6Option.getData());
+ iaPrefixOption.preferredLifetime = bb.getInt();
+ iaPrefixOption.validLifetime = bb.getInt();
+ iaPrefixOption.prefixLength = bb.get();
+ byte[] ipv6Pref = new byte[Ip6Address.BYTE_LENGTH];
+ bb.get(ipv6Pref);
+ iaPrefixOption.ip6Prefix = Ip6Address.valueOf(ipv6Pref);
+
+ // options length of IA Address option
+ int optionsLen = dhcp6Option.getLength() - DEFAULT_LEN;
+ if (optionsLen > 0) {
+ byte[] optionsData = new byte[optionsLen];
+ bb.get(optionsData);
+ iaPrefixOption.options =
+ Data.deserializer().deserialize(optionsData, 0, optionsLen);
+ }
+ return iaPrefixOption;
+ };
+ }
+
+ @Override
+ public byte[] serialize() {
+ int payloadLen = options == null ? DEFAULT_LEN : DEFAULT_LEN + options.serialize().length;
+ ByteBuffer bb = ByteBuffer.allocate(payloadLen + Dhcp6Option.DEFAULT_LEN);
+ bb.putShort(DHCP6.OptionCode.IAPREFIX.value());
+ bb.putShort((short) payloadLen);
+ bb.putInt(preferredLifetime);
+ bb.putInt(validLifetime);
+ bb.put(prefixLength);
+ bb.put(ip6Prefix.toOctets());
+ if (options != null) {
+ bb.put(options.serialize());
+ }
+ return bb.array();
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(super.hashCode(), ip6Prefix, prefixLength, preferredLifetime,
+ validLifetime, options);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (!(obj instanceof Dhcp6IaAddressOption)) {
+ return false;
+ }
+ final Dhcp6IaPrefixOption other = (Dhcp6IaPrefixOption) obj;
+
+ return Objects.equals(getCode(), other.getCode()) &&
+ Objects.equals(getLength(), other.getLength()) &&
+ Objects.equals(preferredLifetime, other.preferredLifetime) &&
+ Objects.equals(validLifetime, other.validLifetime) &&
+ Objects.equals(prefixLength, other.prefixLength) &&
+ Objects.equals(ip6Prefix, other.ip6Prefix) &&
+ Objects.equals(options, other.options);
+ }
+
+ @Override
+ public String toString() {
+ return getToStringHelper()
+ .add("preferredLifetime", preferredLifetime)
+ .add("validLifetime", validLifetime)
+ .add("prefixLength", prefixLength)
+ .add("ip6Address", ip6Prefix)
+ .add("options", options)
+ .toString();
+ }
+}
diff --git a/utils/misc/src/main/java/org/onlab/packet/dhcp/Dhcp6InterfaceIdOption.java b/utils/misc/src/main/java/org/onlab/packet/dhcp/Dhcp6InterfaceIdOption.java
new file mode 100644
index 0000000..abb8257
--- /dev/null
+++ b/utils/misc/src/main/java/org/onlab/packet/dhcp/Dhcp6InterfaceIdOption.java
@@ -0,0 +1,137 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.onlab.packet.dhcp;
+import org.onlab.packet.MacAddress;
+import com.google.common.base.MoreObjects;
+import org.onlab.packet.DHCP6;
+import org.onlab.packet.Deserializer;
+import org.onlab.packet.DeserializationException;
+
+
+import java.nio.ByteBuffer;
+
+/**
+ * Relay option for DHCPv6.
+ * Based on RFC-3315.
+ */
+public final class Dhcp6InterfaceIdOption extends Dhcp6Option {
+ private MacAddress peerMacAddr;
+ private byte[] inPort;
+ @Override
+ public short getCode() {
+ return DHCP6.OptionCode.INTERFACE_ID.value();
+ }
+
+ @Override
+ public short getLength() {
+ return (short) payload.serialize().length;
+ }
+
+ @Override
+ public byte[] getData() {
+ return this.payload.serialize();
+ }
+
+ /**
+ * Default constructor.
+ */
+ public Dhcp6InterfaceIdOption() {
+ }
+
+ /**
+ * Constructs a DHCPv6 relay option with DHCPv6 option.
+ *
+ * @param dhcp6Option the DHCPv6 option
+ */
+ public Dhcp6InterfaceIdOption(Dhcp6Option dhcp6Option) {
+ super(dhcp6Option);
+ }
+
+ /**
+ * Sets MacAddress address.
+ *
+ * @param macAddress the client peer MacAddress
+ */
+ public void setMacAddress(MacAddress macAddress) {
+ this.peerMacAddr = macAddress;
+ }
+
+ /**
+ * Gets Mac address.
+ *
+ * @return the client peer mac address
+ */
+ public MacAddress getMacAddress() {
+ return peerMacAddr;
+ }
+
+ /**
+ * Sets inPort string.
+ *
+ * @param port the port from which client packet is received
+ */
+ public void setInPort(byte[] port) {
+ this.inPort = port;
+ }
+
+ /**
+ * Gets inPort string.
+ *
+ * @return the port from which client packet is received
+ */
+ public byte[] getInPort() {
+ return inPort;
+ }
+
+ /**
+ * Gets deserializer for DHCPv6 relay option.
+ *
+ * @return the deserializer
+ */
+ public static Deserializer<Dhcp6Option> deserializer() {
+ return (data, offset, len) -> {
+ Dhcp6Option dhcp6Option = Dhcp6Option.deserializer().deserialize(data, offset, len);
+ if (dhcp6Option.getLength() < DEFAULT_LEN) {
+ throw new DeserializationException("Invalid InterfaceIoption data");
+ }
+ Dhcp6InterfaceIdOption interfaceIdOption = new Dhcp6InterfaceIdOption(dhcp6Option);
+ byte[] optionData = interfaceIdOption.getData();
+ if (optionData.length >= 28) {
+ ByteBuffer bb = ByteBuffer.wrap(optionData);
+
+ byte[] macAddr = new byte[MacAddress.MAC_ADDRESS_LENGTH];
+ byte[] port = new byte[21];
+ bb.get(macAddr);
+ bb.get(); // separator
+ bb.get(port);
+ interfaceIdOption.setMacAddress(MacAddress.valueOf(macAddr));
+ interfaceIdOption.setInPort(port);
+ }
+ return interfaceIdOption;
+ };
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("code", getCode())
+ .add("length", getLength())
+ .add("data", payload.toString())
+ .toString();
+ }
+}
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandlerBase.java b/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandlerBase.java
index c3eae02..aa920e2 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandlerBase.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandlerBase.java
@@ -341,14 +341,17 @@
ObjectNode payload = objectNode()
.put("id", host.id().toString())
- .put("type", isNullOrEmpty(hostType) ? "endstation" : hostType)
- .put("ingress", compactLinkString(edgeLink(host, true)))
- .put("egress", compactLinkString(edgeLink(host, false)));
+ .put("type", isNullOrEmpty(hostType) ? "endstation" : hostType);
+ // set most recent connect point (and previous if we know it)
payload.set("cp", hostConnect(host.location()));
if (prevHost != null && prevHost.location() != null) {
payload.set("prevCp", hostConnect(prevHost.location()));
}
+
+ // set ALL connect points
+ addAllCps(host.locations(), payload);
+
payload.set("labels", labels(nameForHost(host), ip, host.mac().toString()));
payload.set("props", props(host.annotations()));
addGeoLocation(host, payload);
@@ -358,6 +361,12 @@
return JsonUtils.envelope(type, payload);
}
+ private void addAllCps(Set<HostLocation> locations, ObjectNode payload) {
+ ArrayNode cps = arrayNode();
+ locations.forEach(loc -> cps.add(hostConnect(loc)));
+ payload.set("allCps", cps);
+ }
+
// Encodes the specified host location into a JSON object.
private ObjectNode hostConnect(HostLocation location) {
return objectNode()
diff --git a/web/gui/src/main/webapp/app/view/topo/topoForce.js b/web/gui/src/main/webapp/app/view/topo/topoForce.js
index f3a2d0e..b4073a0 100644
--- a/web/gui/src/main/webapp/app/view/topo/topoForce.js
+++ b/web/gui/src/main/webapp/app/view/topo/topoForce.js
@@ -160,7 +160,7 @@
function addHost(data) {
var id = data.id,
- d, lnk;
+ d;
// although this is an add host event, if we already have the
// host, treat it as an update instead..
@@ -174,12 +174,28 @@
lu[id] = d;
updateNodes();
- lnk = tms.createHostLink(data);
- if (lnk) {
- d.linkData = lnk; // cache ref on its host
- network.links.push(lnk);
- lu[d.ingress] = lnk;
- lu[d.egress] = lnk;
+ function mkLinkKey(devId, devPort) {
+ return id + '/0-' + devId + '/' + devPort;
+ }
+
+ // need to handle possible multiple links (multi-homed host)
+ d.links = [];
+ data.allCps.forEach(function (cp) {
+ var linkData = {
+ key: mkLinkKey(cp.device, cp.port),
+ dst: cp.device,
+ dstPort: cp.port,
+ };
+ d.links.push(linkData);
+
+ var lnk = tms.createHostLink(id, cp.device, cp.port);
+ if (lnk) {
+ network.links.push(lnk);
+ lu[linkData.key] = lnk;
+ }
+ });
+
+ if (d.links.length) {
updateLinks();
}
fStart();
@@ -201,8 +217,10 @@
var id = data.id,
d = lu[id],
lnk;
+
if (d) {
// first remove the old host link
+ // FIXME: what if the host has multiple links??????
removeLinkElement(d.linkData);
// merge new data
@@ -212,12 +230,17 @@
}
// now create a new host link
- lnk = tms.createHostLink(data);
+ // TODO: verify this is the APPROPRIATE host link
+ lnk = tms.createHostLink(id, data.cp.device, data.cp.port);
if (lnk) {
- d.linkData = lnk;
network.links.push(lnk);
- lu[d.ingress] = lnk;
- lu[d.egress] = lnk;
+ lu[lnk.key] = lnk;
+
+ d.links.push({
+ key: id + '/0-' + cp.device + '/' + cp.port,
+ dst: data.cp.device,
+ dstPort: data.cp.port,
+ });
}
updateNodes();
diff --git a/web/gui/src/main/webapp/app/view/topo/topoModel.js b/web/gui/src/main/webapp/app/view/topo/topoModel.js
index caaf38b..2ef94a6 100644
--- a/web/gui/src/main/webapp/app/view/topo/topoModel.js
+++ b/web/gui/src/main/webapp/app/view/topo/topoModel.js
@@ -158,11 +158,9 @@
return node;
}
- function createHostLink(host) {
- var src = host.id,
- dst = host.cp.device,
- id = host.ingress,
- lnk = linkEndPoints(src, dst);
+ function createHostLink(hostId, devId, devPort) {
+ var linkKey = hostId + '/0-' + devId + '/' + devPort,
+ lnk = linkEndPoints(hostId, devId);
if (!lnk) {
return null;
@@ -170,10 +168,10 @@
// Synthesize link ...
angular.extend(lnk, {
- key: id,
+ key: linkKey,
class: 'link',
// NOTE: srcPort left undefined (host end of the link)
- tgtPort: host.cp.port,
+ tgtPort: devPort,
type: function () { return 'hostLink'; },
expected: function () { return true; },
diff --git a/web/gui/src/main/webapp/app/view/topo/topoSelect.js b/web/gui/src/main/webapp/app/view/topo/topoSelect.js
index a0e8c31..d026e73 100644
--- a/web/gui/src/main/webapp/app/view/topo/topoSelect.js
+++ b/web/gui/src/main/webapp/app/view/topo/topoSelect.js
@@ -197,17 +197,15 @@
// special handling for links...
if (itemClass === 'link') {
payload.key = data.key;
+ payload.sourceId = data.source.id;
+ payload.targetId = data.target.id;
+ payload.targetPort = data.tgtPort;
+
if (data.source.class === 'host') {
payload.isEdgeLink = true;
- payload.sourceId = data.source.id;
- payload.targetId = data.source.cp.device;
- payload.targetPort = data.source.cp.port;
} else {
payload.isEdgeLink = false;
- payload.sourceId = data.source.id;
payload.sourcePort = data.srcPort;
- payload.targetId = data.target.id;
- payload.targetPort = data.tgtPort;
}
}
diff --git a/web/gui/src/main/webapp/tests/app/view/topo/topoModel-spec.js b/web/gui/src/main/webapp/tests/app/view/topo/topoModel-spec.js
index 04b9a692..8092a34 100644
--- a/web/gui/src/main/webapp/tests/app/view/topo/topoModel-spec.js
+++ b/web/gui/src/main/webapp/tests/app/view/topo/topoModel-spec.js
@@ -358,7 +358,8 @@
// === unit tests for createHostLink()
- it('should create a basic host link', function () {
+ // TODO: fix this test to use new createHostLink(...) API
+ xit('should create a basic host link', function () {
var link = tms.createHostLink(host1);
expect(link.source).toEqual(host1);
expect(link.target).toEqual(dev1);
@@ -370,7 +371,8 @@
expect(link.online()).toEqual(true);
});
- it('should return null for failed endpoint lookup', function () {
+ // TODO: fix this test to use new createHostLink(...) API
+ xit('should return null for failed endpoint lookup', function () {
spyOn($log, 'error');
var link = tms.createHostLink(host2);
expect(link).toBeNull();