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;
+ }
+ }
+}