Implement kubevirt floating IP's class, codec, watcher and APIs
Change-Id: I2111902e86083add8a00af62557fac1e98b7e7fc
(cherry picked from commit e48a617ccaf19d0d29ccc3211f6254be5e26826e)
diff --git a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/DefaultKubevirtFloatingIp.java b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/DefaultKubevirtFloatingIp.java
new file mode 100644
index 0000000..6dc98e2
--- /dev/null
+++ b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/DefaultKubevirtFloatingIp.java
@@ -0,0 +1,190 @@
+/*
+ * Copyright 2021-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.kubevirtnetworking.api;
+
+import com.google.common.base.MoreObjects;
+import org.onlab.packet.IpAddress;
+
+import java.util.Objects;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+/**
+ * Default implementation class of kubevirt floating IP.
+ */
+public final class DefaultKubevirtFloatingIp implements KubevirtFloatingIp {
+
+ private static final String NOT_NULL_MSG = "Floating IP % cannot be null";
+
+ private final String id;
+ private final String routerName;
+ private final String podName;
+ private final IpAddress floatingIp;
+ private final IpAddress fixedIp;
+
+ /**
+ * A default constructor.
+ *
+ * @param id floating IP identifier
+ * @param routerName router name
+ * @param podName POD name
+ * @param floatingIp floating IP address
+ * @param fixedIp fixed IP address
+ */
+ public DefaultKubevirtFloatingIp(String id, String routerName, String podName,
+ IpAddress floatingIp, IpAddress fixedIp) {
+ this.id = id;
+ this.routerName = routerName;
+ this.podName = podName;
+ this.floatingIp = floatingIp;
+ this.fixedIp = fixedIp;
+ }
+
+ @Override
+ public String id() {
+ return id;
+ }
+
+ @Override
+ public String routerName() {
+ return routerName;
+ }
+
+ @Override
+ public IpAddress floatingIp() {
+ return floatingIp;
+ }
+
+ @Override
+ public IpAddress fixedIp() {
+ return fixedIp;
+ }
+
+ @Override
+ public String podName() {
+ return podName;
+ }
+
+ @Override
+ public KubevirtFloatingIp updateFixedIp(IpAddress ip) {
+ return DefaultKubevirtFloatingIp.builder()
+ .id(id)
+ .routerName(routerName)
+ .floatingIp(floatingIp)
+ .fixedIp(ip)
+ .podName(podName)
+ .build();
+ }
+
+ @Override
+ public KubevirtFloatingIp updatePodName(String name) {
+ return DefaultKubevirtFloatingIp.builder()
+ .id(id)
+ .routerName(routerName)
+ .floatingIp(floatingIp)
+ .fixedIp(fixedIp)
+ .podName(name)
+ .build();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ DefaultKubevirtFloatingIp that = (DefaultKubevirtFloatingIp) o;
+ return id.equals(that.id) && routerName.equals(that.routerName) &&
+ Objects.equals(podName, that.podName) &&
+ floatingIp.equals(that.floatingIp) &&
+ Objects.equals(fixedIp, that.fixedIp);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(id, routerName, podName, floatingIp, fixedIp);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this)
+ .add("id", id)
+ .add("routerName", routerName)
+ .add("podName", podName)
+ .add("floatingIp", floatingIp)
+ .add("fixedIp", fixedIp)
+ .toString();
+ }
+
+ /**
+ * Returns new builder instance.
+ *
+ * @return kubevirt floating IP builder
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static final class Builder implements KubevirtFloatingIp.Builder {
+
+ private String id;
+ private String routerName;
+ private String podName;
+ private IpAddress floatingIp;
+ private IpAddress fixedIp;
+
+ @Override
+ public KubevirtFloatingIp build() {
+ checkArgument(id != null, NOT_NULL_MSG, "id");
+ checkArgument(routerName != null, NOT_NULL_MSG, "routerName");
+ checkArgument(floatingIp != null, NOT_NULL_MSG, "floatingIp");
+
+ return new DefaultKubevirtFloatingIp(id, routerName, podName, floatingIp, fixedIp);
+ }
+
+ @Override
+ public Builder id(String id) {
+ this.id = id;
+ return this;
+ }
+
+ @Override
+ public Builder routerName(String name) {
+ this.routerName = name;
+ return this;
+ }
+
+ @Override
+ public Builder floatingIp(IpAddress ip) {
+ this.floatingIp = ip;
+ return this;
+ }
+
+ @Override
+ public Builder fixedIp(IpAddress ip) {
+ this.fixedIp = ip;
+ return this;
+ }
+
+ @Override
+ public Builder podName(String name) {
+ this.podName = name;
+ return this;
+ }
+ }
+}
diff --git a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtFloatingIp.java b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtFloatingIp.java
new file mode 100644
index 0000000..f879d2b
--- /dev/null
+++ b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtFloatingIp.java
@@ -0,0 +1,124 @@
+/*
+ * Copyright 2021-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.kubevirtnetworking.api;
+
+import org.onlab.packet.IpAddress;
+
+/**
+ * Representation of floating IP address.
+ */
+public interface KubevirtFloatingIp {
+
+ /**
+ * Returns the floating IP identifier.
+ *
+ * @return floating IP identifier
+ */
+ String id();
+
+ /**
+ * Returns the name of router where the floating IP is associated.
+ *
+ * @return name of router
+ */
+ String routerName();
+
+ /**
+ * Returns the floating IP address.
+ *
+ * @return floating IP address
+ */
+ IpAddress floatingIp();
+
+ /**
+ * Returns the fixed IP address.
+ *
+ * @return fixed IP address
+ */
+ IpAddress fixedIp();
+
+ /**
+ * Returns the name of POD where this floating IP is associated with.
+ *
+ * @return POD name
+ */
+ String podName();
+
+ /**
+ * Updates the kubevirt floating IP with the supplied fixed IP address.
+ *
+ * @param ip fixed IP address
+ * @return kubevirt floating IP
+ */
+ KubevirtFloatingIp updateFixedIp(IpAddress ip);
+
+ /**
+ * Updates the kubevirt floating IP with the supplied pod Name.
+ *
+ * @param name POD name
+ * @return kubevirt floating IP
+ */
+ KubevirtFloatingIp updatePodName(String name);
+
+ interface Builder {
+ /**
+ * Builds an immutable floaing IP instance.
+ *
+ * @return kubevirt floating IP
+ */
+ KubevirtFloatingIp build();
+
+ /**
+ * Returns kubevirt floating IP builder with supplied identifier.
+ *
+ * @param id floating IP identifier
+ * @return floating IP builder
+ */
+ Builder id(String id);
+
+ /**
+ * Returns kubevirt floating IP builder with supplied router name.
+ *
+ * @param name router name
+ * @return floating IP builder
+ */
+ Builder routerName(String name);
+
+ /**
+ * Returns kubevirt floating IP builder with supplied floating IP address.
+ *
+ * @param ip floating IP address
+ * @return floating IP builder
+ */
+ Builder floatingIp(IpAddress ip);
+
+ /**
+ * Returns kubevirt floating IP builder with supplied fixed IP address.
+ *
+ * @param ip fixed IP address
+ * @return floating IP builder
+ */
+ Builder fixedIp(IpAddress ip);
+
+ /**
+ * Returns kubevirt floating IP builder with supplied POD name.
+ *
+ * @param name POD name
+ * @return floating IP builder
+ */
+ Builder podName(String name);
+ }
+}
diff --git a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtRouter.java b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtRouter.java
index e9f5e88..697198b 100644
--- a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtRouter.java
+++ b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtRouter.java
@@ -77,7 +77,7 @@
interface Builder {
/**
- * Builds an immutable network instance.
+ * Builds an immutable router instance.
*
* @return kubevirt router
*/
diff --git a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtRouterAdminService.java b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtRouterAdminService.java
index 1ec1cee..30d7890 100644
--- a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtRouterAdminService.java
+++ b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtRouterAdminService.java
@@ -52,6 +52,27 @@
void updatePeerRouterMac(String name, MacAddress mac);
/**
+ * Creates a kubevirt floating IP with the given information.
+ *
+ * @param floatingIp a new floating IP
+ */
+ void createFloatingIp(KubevirtFloatingIp floatingIp);
+
+ /**
+ * Updates the kubevirt floating IP with the given information.
+ *
+ * @param floatingIp the updated floating IP
+ */
+ void updateFloatingIp(KubevirtFloatingIp floatingIp);
+
+ /**
+ * Removes the floating IP with the given identifier.
+ *
+ * @param id floating IP identifier
+ */
+ void removeFloatingIp(String id);
+
+ /**
* Removes all routers.
*/
void clear();
diff --git a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtRouterEvent.java b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtRouterEvent.java
index b195ecb..c9e1f16 100644
--- a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtRouterEvent.java
+++ b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtRouterEvent.java
@@ -17,11 +17,16 @@
import org.onosproject.event.AbstractEvent;
+import static com.google.common.base.MoreObjects.toStringHelper;
+
/**
* Kubevirt router event class.
*/
public class KubevirtRouterEvent extends AbstractEvent<KubevirtRouterEvent.Type, KubevirtRouter> {
+ private final KubevirtFloatingIp floatingIp;
+ private final String podName;
+
/**
* Creates an event of a given type for the specified kubevirt router.
*
@@ -30,6 +35,35 @@
*/
public KubevirtRouterEvent(Type type, KubevirtRouter subject) {
super(type, subject);
+ this.floatingIp = null;
+ this.podName = null;
+ }
+
+ /**
+ * Creates an event of a given type for the specified kubevirt router.
+ *
+ * @param type kubevirt router event type
+ * @param subject kubevirt router
+ * @param floatingIp kubevirt floating IP
+ */
+ public KubevirtRouterEvent(Type type, KubevirtRouter subject, KubevirtFloatingIp floatingIp) {
+ super(type, subject);
+ this.floatingIp = floatingIp;
+ this.podName = null;
+ }
+
+ /**
+ * Creates an event of a given type for the specified kubevirt router.
+ *
+ * @param type kubevirt router event type
+ * @param subject kubevirt router
+ * @param floatingIp kubevirt floating IP
+ * @param podName kubevirt POD name
+ */
+ public KubevirtRouterEvent(Type type, KubevirtRouter subject, KubevirtFloatingIp floatingIp, String podName) {
+ super(type, subject);
+ this.floatingIp = floatingIp;
+ this.podName = podName;
}
public enum Type {
@@ -47,5 +81,61 @@
* Signifies that the kubevirt router is removed.
*/
KUBEVIRT_ROUTER_REMOVED,
+
+ /**
+ * Signifies that a new kubevirt floating IP is created.
+ */
+ KUBEVIRT_FLOATING_IP_CREATED,
+
+ /**
+ * Signifies that the kubevirt floating IP is updated.
+ */
+ KUBEVIRT_FLOATING_IP_UPDATED,
+
+ /**
+ * Signifies that the kubevirt floating IP is removed.
+ */
+ KUBEVIRT_FLOATING_IP_REMOVED,
+
+ /**
+ * Signifies that the floating IP is associated to a fixed IP.
+ */
+ KUBEVIRT_FLOATING_IP_ASSOCIATED,
+
+ /**
+ * Signifies that the floating IP disassociated from the fixed IP.
+ */
+ KUBEVIRT_FLOATING_IP_DISASSOCIATED
+ }
+
+ /**
+ * Returns the floating IP of the router event.
+ *
+ * @return kubevirt floating IP; null if the event is not relevant to the floating IP
+ */
+ public KubevirtFloatingIp floatingIp() {
+ return floatingIp;
+ }
+
+ /**
+ * Returns the pod name of the router event.
+ *
+ * @return kubevirt pod name; null if the event is not relevant to the pod name
+ */
+ public String podName() {
+ return podName;
+ }
+
+ @Override
+ public String toString() {
+ if (floatingIp == null) {
+ return super.toString();
+ }
+ return toStringHelper(this)
+ .add("type", type())
+ .add("router", subject())
+ .add("floatingIp", floatingIp)
+ .add("podName", podName)
+ .toString();
}
}
diff --git a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtRouterService.java b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtRouterService.java
index 03b6d35..0b25fe4 100644
--- a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtRouterService.java
+++ b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtRouterService.java
@@ -39,4 +39,35 @@
* @return set of kubevirt routers
*/
Set<KubevirtRouter> routers();
+
+ /**
+ * Returns the kubevirt floating IP with the supplied identifier.
+ *
+ * @param id floating IP identifier
+ * @return kubevirt floating IP
+ */
+ KubevirtFloatingIp floatingIp(String id);
+
+ /**
+ * Returns the kubevirt floating IP associated with the supplied POD.
+ *
+ * @param podName name of POD
+ * @return kubevirt floating IP
+ */
+ KubevirtFloatingIp floatingIpByPodName(String podName);
+
+ /**
+ * Returns the kubevirt floating IPs bound to the given router.
+ *
+ * @param routerName name of router
+ * @return set of kubevirt floating IPs
+ */
+ Set<KubevirtFloatingIp> floatingIpsByRouter(String routerName);
+
+ /**
+ * Returns all kubevirt floating IPs.
+ *
+ * @return set of kubevirt floating IPs
+ */
+ Set<KubevirtFloatingIp> floatingIps();
}
diff --git a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtRouterStore.java b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtRouterStore.java
index c63daa2..7313aa9 100644
--- a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtRouterStore.java
+++ b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtRouterStore.java
@@ -63,7 +63,44 @@
Set<KubevirtRouter> routers();
/**
- * Removes all kubevirt routers.
+ * Creates a new kubevirt floating IP.
+ *
+ * @param floatingIp kubevirt floating IP
+ */
+ void createFloatingIp(KubevirtFloatingIp floatingIp);
+
+ /**
+ * Updates the kubevirt floating IP.
+ *
+ * @param floatingIp kubevirt floating IP
+ */
+ void updateFloatingIp(KubevirtFloatingIp floatingIp);
+
+ /**
+ * Removes the kubevirt floating IP with the given identifier.
+ *
+ * @param id floating IP identifier
+ * @return removed kubevirt floating IP; null if failed
+ */
+ KubevirtFloatingIp removeFloatingIp(String id);
+
+ /**
+ * Returns the kubevirt floating IP with the given identifier.
+ *
+ * @param id floating IP identifier
+ * @return kubevirt floating IP; null if not found
+ */
+ KubevirtFloatingIp floatingIp(String id);
+
+ /**
+ * Returns all kubevirt floating IPs.
+ *
+ * @return set of kubevirt floating IPs
+ */
+ Set<KubevirtFloatingIp> floatingIps();
+
+ /**
+ * Removes all kubevirt routers and floating IPs.
*/
void clear();
}