Implement kubevirt loadbalancer service with unit tests
Change-Id: I1c29e75aa5196b497f8f12f1d182788e3d173244
(cherry picked from commit 870abf8c7a7904c5953e20807ee7c681d8b5cd0b)
diff --git a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/DefaultKubevirtLoadBalancer.java b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/DefaultKubevirtLoadBalancer.java
new file mode 100644
index 0000000..bf4a21d
--- /dev/null
+++ b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/DefaultKubevirtLoadBalancer.java
@@ -0,0 +1,193 @@
+/*
+ * 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 com.google.common.collect.ImmutableSet;
+import org.onlab.packet.IpAddress;
+
+import java.util.Objects;
+import java.util.Set;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+/**
+ * Default implementation of kubevirt load balancer.
+ */
+public final class DefaultKubevirtLoadBalancer implements KubevirtLoadBalancer {
+
+ private static final String NOT_NULL_MSG = "Loadbalancer % cannot be null";
+
+ private final String name;
+ private final String description;
+ private final String networkId;
+ private final IpAddress vip;
+ private final Set<IpAddress> members;
+ private final Set<KubevirtLoadBalancerRule> rules;
+
+ /**
+ * Default constructor.
+ *
+ * @param name load balancer name
+ * @param description load balancer description
+ * @param networkId load balancer network identifier
+ * @param vip load balancer virtual IP address
+ * @param members load balancer members
+ * @param rules load balancer rules
+ */
+ public DefaultKubevirtLoadBalancer(String name, String description, String networkId,
+ IpAddress vip, Set<IpAddress> members,
+ Set<KubevirtLoadBalancerRule> rules) {
+ this.name = name;
+ this.description = description;
+ this.networkId = networkId;
+ this.vip = vip;
+ this.members = members;
+ this.rules = rules;
+ }
+
+ @Override
+ public String name() {
+ return name;
+ }
+
+ @Override
+ public String description() {
+ return description;
+ }
+
+ @Override
+ public String networkId() {
+ return networkId;
+ }
+
+ @Override
+ public IpAddress vip() {
+ return vip;
+ }
+
+ @Override
+ public Set<IpAddress> members() {
+ if (members == null) {
+ return ImmutableSet.of();
+ } else {
+ return ImmutableSet.copyOf(members);
+ }
+ }
+
+ @Override
+ public Set<KubevirtLoadBalancerRule> rules() {
+ if (rules == null) {
+ return ImmutableSet.of();
+ } else {
+ return ImmutableSet.copyOf(rules);
+ }
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ DefaultKubevirtLoadBalancer that = (DefaultKubevirtLoadBalancer) o;
+ return name.equals(that.name) && Objects.equals(description, that.description) &&
+ networkId.equals(that.networkId) && vip.equals(that.vip) &&
+ Objects.equals(members, that.members) && Objects.equals(rules, that.rules);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(name, description, networkId, vip, members, rules);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this)
+ .add("name", name)
+ .add("description", description)
+ .add("networkId", networkId)
+ .add("vip", vip)
+ .add("members", members)
+ .add("rules", rules)
+ .toString();
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static final class Builder implements KubevirtLoadBalancer.Builder {
+
+ private String name;
+ private String description;
+ private String networkId;
+ private IpAddress vip;
+ private Set<IpAddress> members;
+ private Set<KubevirtLoadBalancerRule> rules;
+
+ // private constructor not intended to use from external
+ private Builder() {
+ }
+
+ @Override
+ public KubevirtLoadBalancer build() {
+ checkArgument(networkId != null, NOT_NULL_MSG, "networkId");
+ checkArgument(name != null, NOT_NULL_MSG, "name");
+ checkArgument(vip != null, NOT_NULL_MSG, "vip");
+
+ return new DefaultKubevirtLoadBalancer(name, description, networkId, vip, members, rules);
+ }
+
+ @Override
+ public Builder name(String name) {
+ this.name = name;
+ return this;
+ }
+
+ @Override
+ public Builder description(String description) {
+ this.description = description;
+ return this;
+ }
+
+ @Override
+ public Builder networkId(String networkId) {
+ this.networkId = networkId;
+ return this;
+ }
+
+ @Override
+ public Builder vip(IpAddress vip) {
+ this.vip = vip;
+ return this;
+ }
+
+ @Override
+ public Builder members(Set<IpAddress> members) {
+ this.members = members;
+ return this;
+ }
+
+ @Override
+ public Builder rules(Set<KubevirtLoadBalancerRule> rules) {
+ this.rules = rules;
+ return this;
+ }
+ }
+}
diff --git a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/DefaultKubevirtLoadBalancerRule.java b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/DefaultKubevirtLoadBalancerRule.java
new file mode 100644
index 0000000..453610e
--- /dev/null
+++ b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/DefaultKubevirtLoadBalancerRule.java
@@ -0,0 +1,134 @@
+/*
+ * 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 java.util.Objects;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+/**
+ * Default implementation class of kubevirt load balancer rule.
+ */
+public final class DefaultKubevirtLoadBalancerRule implements KubevirtLoadBalancerRule {
+ private static final String NOT_NULL_MSG = "Load Balancer Rule % cannot be null";
+
+ private final String protocol;
+ private final Integer portRangeMax;
+ private final Integer portRangeMin;
+
+ /**
+ * A default constructor.
+ *
+ * @param protocol protocol
+ * @param portRangeMax port range max
+ * @param portRangeMin port range min
+ */
+ public DefaultKubevirtLoadBalancerRule(String protocol,
+ Integer portRangeMax,
+ Integer portRangeMin) {
+ this.protocol = protocol;
+ this.portRangeMax = portRangeMax;
+ this.portRangeMin = portRangeMin;
+ }
+
+ @Override
+ public String protocol() {
+ return protocol;
+ }
+
+ @Override
+ public Integer portRangeMax() {
+ return portRangeMax;
+ }
+
+ @Override
+ public Integer portRangeMin() {
+ return portRangeMin;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ DefaultKubevirtLoadBalancerRule that = (DefaultKubevirtLoadBalancerRule) o;
+ return protocol.equals(that.protocol) &&
+ portRangeMax.equals(that.portRangeMax) &&
+ portRangeMin.equals(that.portRangeMin);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(protocol, portRangeMax, portRangeMin);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this)
+ .add("protocol", protocol)
+ .add("portRangeMax", portRangeMax)
+ .add("portRangeMin", portRangeMin)
+ .toString();
+ }
+
+ /**
+ * Returns new builder instance.
+ *
+ * @return kubevirt load balancer rule builder
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static final class Builder implements KubevirtLoadBalancerRule.Builder {
+
+ private String protocol;
+ private Integer portRangeMax;
+ private Integer portRangeMin;
+
+ @Override
+ public KubevirtLoadBalancerRule build() {
+ checkArgument(protocol != null, NOT_NULL_MSG, "protocol");
+ checkArgument(portRangeMax != null, NOT_NULL_MSG, "portRangeMax");
+ checkArgument(portRangeMin != null, NOT_NULL_MSG, "portRangeMin");
+
+ return new DefaultKubevirtLoadBalancerRule(protocol, portRangeMax, portRangeMin);
+ }
+
+ @Override
+ public Builder portRangeMax(Integer portRangeMax) {
+ this.portRangeMax = portRangeMax;
+ return this;
+ }
+
+ @Override
+ public Builder portRangeMin(Integer portRangeMin) {
+ this.portRangeMin = portRangeMin;
+ return this;
+ }
+
+ @Override
+ public Builder protocol(String protocol) {
+ this.protocol = protocol;
+ return this;
+ }
+ }
+}
diff --git a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtLoadBalancer.java b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtLoadBalancer.java
new file mode 100644
index 0000000..7547547
--- /dev/null
+++ b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtLoadBalancer.java
@@ -0,0 +1,128 @@
+/*
+ * 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;
+
+import java.util.Set;
+
+/**
+ * Representation of load balancer.
+ */
+public interface KubevirtLoadBalancer {
+
+ /**
+ * Returns the load balancer name.
+ *
+ * @return load balancer name
+ */
+ String name();
+
+ /**
+ * Returns the load balancer description.
+ *
+ * @return load balancer description
+ */
+ String description();
+
+ /**
+ * Returns the network identifier.
+ *
+ * @return network identifier
+ */
+ String networkId();
+
+ /**
+ * Returns the load balancer virtual IP address.
+ *
+ * @return load balancer virtual IP address
+ */
+ IpAddress vip();
+
+ /**
+ * Returns the IP address of members.
+ *
+ * @return IP addresses
+ */
+ Set<IpAddress> members();
+
+ /**
+ * Returns the load balancer rules.
+ *
+ * @return load balancer rules
+ */
+ Set<KubevirtLoadBalancerRule> rules();
+
+ /**
+ * A default builder interface.
+ */
+ interface Builder {
+ /**
+ * Builds an immutable load balancer instance.
+ *
+ * @return kubevirt load balancer
+ */
+ KubevirtLoadBalancer build();
+
+ /**
+ * Returns kubevirt load balancer builder with supplied load balancer name.
+ *
+ * @param name load balancer name
+ * @return load balancer builder
+ */
+ Builder name(String name);
+
+ /**
+ * Returns kubevirt load balancer builder with supplied load balancer description.
+ *
+ * @param description load balancer description
+ * @return load balancer builder
+ */
+ Builder description(String description);
+
+ /**
+ * Returns kubevirt load balancer builder with supplied load balancer network identifier.
+ *
+ * @param networkId load balancer network identifier
+ * @return load balancer builder
+ */
+ Builder networkId(String networkId);
+
+ /**
+ * Returns kubevirt load balancer builder with supplied load balancer vip.
+ *
+ * @param vip load balancer vip
+ * @return load balancer builder
+ */
+ Builder vip(IpAddress vip);
+
+ /**
+ * Returns kubevirt load balancer builder with supplied load balancer members.
+ *
+ * @param members load balancer members
+ * @return load balancer builder
+ */
+ Builder members(Set<IpAddress> members);
+
+ /**
+ * Returns kubevirt load balancer builder with supplied load balancer rules.
+ *
+ * @param rules load balancer rules
+ * @return load balancer builder
+ */
+ Builder rules(Set<KubevirtLoadBalancerRule> rules);
+ }
+}
diff --git a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtLoadBalancerAdminService.java b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtLoadBalancerAdminService.java
new file mode 100644
index 0000000..a81adb8
--- /dev/null
+++ b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtLoadBalancerAdminService.java
@@ -0,0 +1,48 @@
+/*
+ * 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;
+
+/**
+ * Service for administering the inventory of kubevirt load balancer service.
+ */
+public interface KubevirtLoadBalancerAdminService extends KubevirtLoadBalancerService {
+
+ /**
+ * Create a kubevirt load balancer with the given information.
+ *
+ * @param lb a new load balancer
+ */
+ void createLoadBalancer(KubevirtLoadBalancer lb);
+
+ /**
+ * Updates the kubevirt load balancer with the given information.
+ *
+ * @param lb the updated load balancer
+ */
+ void updateLoadBalancer(KubevirtLoadBalancer lb);
+
+ /**
+ * Removes the load balancer.
+ *
+ * @param name load balancer name
+ */
+ void removeLoadBalancer(String name);
+
+ /**
+ * Removes all load balancers.
+ */
+ void clear();
+}
diff --git a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtLoadBalancerEvent.java b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtLoadBalancerEvent.java
new file mode 100644
index 0000000..ad09091
--- /dev/null
+++ b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtLoadBalancerEvent.java
@@ -0,0 +1,49 @@
+/*
+ * 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.onosproject.event.AbstractEvent;
+
+public class KubevirtLoadBalancerEvent
+ extends AbstractEvent<KubevirtLoadBalancerEvent.Type, KubevirtLoadBalancer> {
+
+ /**
+ * LoadBalancerEvent constructor.
+ *
+ * @param type LoadBalancerEvent type
+ * @param lb LoadBalancer object
+ */
+ public KubevirtLoadBalancerEvent(Type type, KubevirtLoadBalancer lb) {
+ super(type, lb);
+ }
+
+ public enum Type {
+ /**
+ * Signifies that a new kubevirt load balancer is created.
+ */
+ KUBEVIRT_LOAD_BALANCER_CREATED,
+
+ /**
+ * Signifies that a new kubevirt load balancer is removed.
+ */
+ KUBEVIRT_LOAD_BALANCER_REMOVED,
+
+ /**
+ * Signifies that a new kubevirt load balancer is updated.
+ */
+ KUBEVIRT_LOAD_BALANCER_UPDATED,
+ }
+}
diff --git a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtLoadBalancerListener.java b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtLoadBalancerListener.java
new file mode 100644
index 0000000..2711831
--- /dev/null
+++ b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtLoadBalancerListener.java
@@ -0,0 +1,24 @@
+/*
+ * 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.onosproject.event.EventListener;
+
+/**
+ * Listener for kubevirt load balancer event.
+ */
+public interface KubevirtLoadBalancerListener extends EventListener<KubevirtLoadBalancerEvent> {
+}
diff --git a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtLoadBalancerRule.java b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtLoadBalancerRule.java
new file mode 100644
index 0000000..665024a
--- /dev/null
+++ b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtLoadBalancerRule.java
@@ -0,0 +1,80 @@
+/*
+ * 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;
+
+/**
+ * Representation of load balancer rule.
+ */
+public interface KubevirtLoadBalancerRule {
+
+ /**
+ * Returns the maximum port range.
+ *
+ * @return maximum port range
+ */
+ Integer portRangeMax();
+
+ /**
+ * Returns the minimum port range.
+ *
+ * @return minimum port range
+ */
+ Integer portRangeMin();
+
+ /**
+ * Returns the network protocol.
+ *
+ * @return network protocol
+ */
+ String protocol();
+
+ /**
+ * A default builder interface.
+ */
+ interface Builder {
+ /**
+ * Builds an immutable load balancer rule instance.
+ *
+ * @return kubevirt load balancer rule
+ */
+ KubevirtLoadBalancerRule build();
+
+ /**
+ * Returns kubevirt load balancer rule builder with supplied maximum port range.
+ *
+ * @param portRangeMax maximum port range
+ * @return balancer rule rule builder
+ */
+ Builder portRangeMax(Integer portRangeMax);
+
+ /**
+ * Returns kubevirt load balancer rule builder with supplied minimum port range.
+ *
+ * @param portRangeMin minimum port range
+ * @return balancer rule rule builder
+ */
+ Builder portRangeMin(Integer portRangeMin);
+
+ /**
+ * Returns kubevirt load balancer rule builder with supplied protocol.
+ *
+ * @param protocol network protocol
+ * @return balancer rule rule builder
+ */
+ Builder protocol(String protocol);
+
+ }
+}
diff --git a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtLoadBalancerService.java b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtLoadBalancerService.java
new file mode 100644
index 0000000..732bb91a
--- /dev/null
+++ b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtLoadBalancerService.java
@@ -0,0 +1,42 @@
+/*
+ * 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.onosproject.event.ListenerService;
+
+import java.util.Set;
+
+/**
+ * Service for interacting with the inventory of kubevirt load balancer.
+ */
+public interface KubevirtLoadBalancerService
+ extends ListenerService<KubevirtLoadBalancerEvent, KubevirtLoadBalancerListener> {
+
+ /**
+ * Returns the kubevirt load balancer with the supplied load balancer name.
+ *
+ * @param name load balancer name
+ * @return kubevirt load balancer
+ */
+ KubevirtLoadBalancer loadBalancer(String name);
+
+ /**
+ * Returns all kubevirt load balancers registered in the service.
+ *
+ * @return set of kubevirt load balancers
+ */
+ Set<KubevirtLoadBalancer> loadBalancers();
+}
diff --git a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtLoadBalancerStore.java b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtLoadBalancerStore.java
new file mode 100644
index 0000000..b6a2021
--- /dev/null
+++ b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtLoadBalancerStore.java
@@ -0,0 +1,69 @@
+/*
+ * 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.onosproject.store.Store;
+
+import java.util.Set;
+
+/**
+ * Manages inventory of kubevirt load balancer states; not intended for direct use.
+ */
+public interface KubevirtLoadBalancerStore
+ extends Store<KubevirtLoadBalancerEvent, KubevirtLoadBalancerStoreDelegate> {
+
+ /**
+ * Creates a new kubevirt load balancer.
+ *
+ * @param lb kubevirt load balancer
+ */
+ void createLoadBalancer(KubevirtLoadBalancer lb);
+
+ /**
+ * Updates the kubevirt load balancer.
+ *
+ * @param lb kubevirt load balancer
+ */
+ void updateLoadBalancer(KubevirtLoadBalancer lb);
+
+ /**
+ * Removes the kubevirt load balancer with the given load balancer name.
+ *
+ * @param name load balancer name
+ * @return remove kubevirt load balancer; null if failed
+ */
+ KubevirtLoadBalancer removeLoadBalancer(String name);
+
+ /**
+ * Returns the kubevirt load balancer with the given load balancer name.
+ *
+ * @param name load balancer name
+ * @return load balancer; null if failed
+ */
+ KubevirtLoadBalancer loadBalancer(String name);
+
+ /**
+ * Returns all kubevirt load balancers.
+ *
+ * @return set of kubevirt load balancers
+ */
+ Set<KubevirtLoadBalancer> loadBalancers();
+
+ /**
+ * Removes all kubevirt load balancers.
+ */
+ void clear();
+}
diff --git a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtLoadBalancerStoreDelegate.java b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtLoadBalancerStoreDelegate.java
new file mode 100644
index 0000000..f5e8370
--- /dev/null
+++ b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtLoadBalancerStoreDelegate.java
@@ -0,0 +1,24 @@
+/*
+ * 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.onosproject.store.StoreDelegate;
+
+/**
+ * Kubevirt load balancer store delegate abstraction.
+ */
+public interface KubevirtLoadBalancerStoreDelegate extends StoreDelegate<KubevirtLoadBalancerEvent> {
+}
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 7313aa9..ff25a02 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
@@ -51,7 +51,7 @@
* Returns the kubevirt router with the given router name.
*
* @param name router name
- * @return removed kubevirt router; null if failed
+ * @return kubevirt router; null if failed
*/
KubevirtRouter router(String name);
diff --git a/apps/kubevirt-networking/api/src/test/java/org/onosproject/kubevirtnetworking/api/DefaultKubevirtLoadBalancerTest.java b/apps/kubevirt-networking/api/src/test/java/org/onosproject/kubevirtnetworking/api/DefaultKubevirtLoadBalancerTest.java
new file mode 100644
index 0000000..e9ec471
--- /dev/null
+++ b/apps/kubevirt-networking/api/src/test/java/org/onosproject/kubevirtnetworking/api/DefaultKubevirtLoadBalancerTest.java
@@ -0,0 +1,138 @@
+/*
+ * 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.collect.ImmutableSet;
+import com.google.common.testing.EqualsTester;
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.packet.IpAddress;
+
+import java.util.Set;
+
+import static junit.framework.TestCase.assertEquals;
+import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
+
+/**
+ * Unit tests for the default kubevirt load balancer class.
+ */
+public class DefaultKubevirtLoadBalancerTest {
+
+ private static final String NAME_1 = "lb-1";
+ private static final String NAME_2 = "lb-2";
+ private static final String DESCRIPTION_1 = "dummy lb 1";
+ private static final String DESCRIPTION_2 = "dummy lb 2";
+ private static final String NETWORK_ID_1 = "net-1";
+ private static final String NETWORK_ID_2 = "net-2";
+ private static final IpAddress VIP_1 = IpAddress.valueOf("10.10.10.10");
+ private static final IpAddress VIP_2 = IpAddress.valueOf("20.20.20.20");
+ private static final Integer PORT_RANGE_MAX_1 = 80;
+ private static final Integer PORT_RANGE_MAX_2 = 8080;
+ private static final Integer PORT_RANGE_MIN_1 = 80;
+ private static final Integer PORT_RANGE_MIN_2 = 8080;
+ private static final String PROTOCOL_1 = "tcp";
+ private static final String PROTOCOL_2 = "udp";
+ private static final Set<IpAddress> MEMBERS_1 =
+ ImmutableSet.of(IpAddress.valueOf("10.10.10.11"),
+ IpAddress.valueOf("10.10.10.12"));
+ private static final Set<IpAddress> MEMBERS_2 =
+ ImmutableSet.of(IpAddress.valueOf("20.20.20.21"),
+ IpAddress.valueOf("20.20.20.22"));
+ private static final KubevirtLoadBalancerRule RULE_1 =
+ DefaultKubevirtLoadBalancerRule.builder()
+ .protocol(PROTOCOL_1)
+ .portRangeMax(PORT_RANGE_MAX_1)
+ .portRangeMin(PORT_RANGE_MIN_1)
+ .build();
+ private static final KubevirtLoadBalancerRule RULE_2 =
+ DefaultKubevirtLoadBalancerRule.builder()
+ .protocol(PROTOCOL_2)
+ .portRangeMax(PORT_RANGE_MAX_2)
+ .portRangeMin(PORT_RANGE_MIN_2)
+ .build();
+ private static final Set<KubevirtLoadBalancerRule> RULES_1 = ImmutableSet.of(RULE_1);
+ private static final Set<KubevirtLoadBalancerRule> RULES_2 = ImmutableSet.of(RULE_2);
+
+ private KubevirtLoadBalancer lb1;
+ private KubevirtLoadBalancer sameAsLb1;
+ private KubevirtLoadBalancer lb2;
+
+ /**
+ * Tests class immutability.
+ */
+ @Test
+ public void testImmutability() {
+ assertThatClassIsImmutable(DefaultKubevirtLoadBalancer.class);
+ }
+
+ /**
+ * Initial setup for this unit test.
+ */
+ @Before
+ public void setUp() {
+ lb1 = DefaultKubevirtLoadBalancer.builder()
+ .name(NAME_1)
+ .description(DESCRIPTION_1)
+ .networkId(NETWORK_ID_1)
+ .vip(VIP_1)
+ .members(MEMBERS_1)
+ .rules(RULES_1)
+ .build();
+
+ sameAsLb1 = DefaultKubevirtLoadBalancer.builder()
+ .name(NAME_1)
+ .description(DESCRIPTION_1)
+ .networkId(NETWORK_ID_1)
+ .vip(VIP_1)
+ .members(MEMBERS_1)
+ .rules(RULES_1)
+ .build();
+
+ lb2 = DefaultKubevirtLoadBalancer.builder()
+ .name(NAME_2)
+ .description(DESCRIPTION_2)
+ .networkId(NETWORK_ID_2)
+ .vip(VIP_2)
+ .members(MEMBERS_2)
+ .rules(RULES_2)
+ .build();
+ }
+
+ /**
+ * Tests object equality.
+ */
+ @Test
+ public void testEquality() {
+ new EqualsTester().addEqualityGroup(lb1, sameAsLb1)
+ .addEqualityGroup(lb2)
+ .testEquals();
+ }
+
+ /**
+ * Test object construction.
+ */
+ @Test
+ public void testConstruction() {
+ KubevirtLoadBalancer lb = lb1;
+
+ assertEquals(NAME_1, lb.name());
+ assertEquals(DESCRIPTION_1, lb.description());
+ assertEquals(NETWORK_ID_1, lb.networkId());
+ assertEquals(VIP_1, lb.vip());
+ assertEquals(MEMBERS_1, lb.members());
+ assertEquals(RULES_1, lb.rules());
+ }
+}