Initial implementation of kubevirt router along with peer router

Change-Id: Ibf97f4ca09e4cdbfea42d1edadd3e671c238878f
diff --git a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/DefaultKubevirtRouter.java b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/DefaultKubevirtRouter.java
new file mode 100644
index 0000000..e606275
--- /dev/null
+++ b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/DefaultKubevirtRouter.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 com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import org.onlab.packet.IpAddress;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+/**
+ * Default implementation class of kubevirt router.
+ */
+public final class DefaultKubevirtRouter implements KubevirtRouter {
+
+    private static final String NOT_NULL_MSG = "Router % cannot be null";
+
+    private final String name;
+    private final String description;
+    private final boolean enableSnat;
+    private final Set<String> internal;
+    private final Map<IpAddress, String> external;
+    private final KubevirtPeerRouter peerRouter;
+
+    /**
+     * A default constructor.
+     *
+     * @param name          router name
+     * @param description   router description
+     * @param enableSnat    snat use indicator
+     * @param internal      internal networks
+     * @param external      external network
+     * @param peerRouter    external peer router
+     */
+    public DefaultKubevirtRouter(String name, String description, boolean enableSnat,
+                                 Set<String> internal,
+                                 Map<IpAddress, String> external,
+                                 KubevirtPeerRouter peerRouter) {
+        this.name = name;
+        this.description = description;
+        this.enableSnat = enableSnat;
+        this.internal = internal;
+        this.external = external;
+        this.peerRouter = peerRouter;
+    }
+
+    @Override
+    public String name() {
+        return name;
+    }
+
+    @Override
+    public String description() {
+        return description;
+    }
+
+    @Override
+    public boolean enableSnat() {
+        return enableSnat;
+    }
+
+    @Override
+    public Set<String> internal() {
+        return ImmutableSet.copyOf(internal);
+    }
+
+    @Override
+    public Map<IpAddress, String> external() {
+        return ImmutableMap.copyOf(external);
+    }
+
+    @Override
+    public KubevirtPeerRouter peerRouter() {
+        return peerRouter;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+        DefaultKubevirtRouter that = (DefaultKubevirtRouter) o;
+        return enableSnat == that.enableSnat && name.equals(that.name) &&
+                description.equals(that.description) && internal.equals(that.internal) &&
+                external.equals(that.external) && peerRouter.equals(that.peerRouter);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(name, description, enableSnat, internal, external, peerRouter);
+    }
+
+    @Override
+    public String toString() {
+        return MoreObjects.toStringHelper(this)
+                .add("name", name)
+                .add("description", description)
+                .add("enableSnat", enableSnat)
+                .add("internal", internal)
+                .add("external", external)
+                .add("peerRouter", peerRouter)
+                .toString();
+    }
+
+    /**
+     * Returns new builder instance.
+     *
+     * @return kubevirt router builder
+     */
+    public static Builder builder() {
+        return new Builder();
+    }
+
+    public static final class Builder implements KubevirtRouter.Builder {
+
+        private String name;
+        private String description;
+        private boolean enableSnat;
+        private Set<String> internal;
+        private Map<IpAddress, String> external;
+        private KubevirtPeerRouter peerRouter;
+
+        @Override
+        public KubevirtRouter build() {
+            checkArgument(name != null, NOT_NULL_MSG, "name");
+
+            return new DefaultKubevirtRouter(name, description, enableSnat,
+                    internal, external, peerRouter);
+        }
+
+        @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 enableSnat(boolean flag) {
+            this.enableSnat = flag;
+            return this;
+        }
+
+        @Override
+        public Builder internal(Set<String> internal) {
+            this.internal = Objects.requireNonNullElseGet(internal, HashSet::new);
+            return this;
+        }
+
+        @Override
+        public Builder external(Map<IpAddress, String> external) {
+            this.external = Objects.requireNonNullElseGet(external, HashMap::new);
+            return this;
+        }
+
+        @Override
+        public Builder peerRouter(KubevirtPeerRouter router) {
+            this.peerRouter = router;
+            return this;
+        }
+    }
+}
diff --git a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtNetworkAdminService.java b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtNetworkAdminService.java
index a8fbf34..ecec1579 100644
--- a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtNetworkAdminService.java
+++ b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtNetworkAdminService.java
@@ -17,6 +17,9 @@
 
 import org.onlab.packet.IpAddress;
 
+/**
+ * Service for administering the inventory of kubevirt network service.
+ */
 public interface KubevirtNetworkAdminService extends KubevirtNetworkService {
 
     /**
diff --git a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtPeerRouter.java b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtPeerRouter.java
new file mode 100644
index 0000000..00dbc2f
--- /dev/null
+++ b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtPeerRouter.java
@@ -0,0 +1,84 @@
+/*
+ * 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 org.onlab.packet.MacAddress;
+
+import java.util.Objects;
+
+/**
+ * External peer router class.
+ */
+public class KubevirtPeerRouter {
+
+    private final IpAddress ipAddress;
+    private final MacAddress macAddress;
+
+    /**
+     * A default constructor.
+     *
+     * @param ipAddress  IP address
+     * @param macAddress MAC address
+     */
+    KubevirtPeerRouter(IpAddress ipAddress, MacAddress macAddress) {
+        this.ipAddress = ipAddress;
+        this.macAddress = macAddress;
+    }
+
+    /**
+     * Obtains the peer router IP address.
+     * @return IP address
+     */
+    public IpAddress ipAddress() {
+        return ipAddress;
+    }
+
+    /**
+     * Obtains the peer router MAC address.
+     *
+     * @return MAC address
+     */
+    public MacAddress macAddress() {
+        return macAddress;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+        KubevirtPeerRouter that = (KubevirtPeerRouter) o;
+        return ipAddress.equals(that.ipAddress) && macAddress.equals(that.macAddress);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(ipAddress, macAddress);
+    }
+
+    @Override
+    public String toString() {
+        return MoreObjects.toStringHelper(this)
+                .add("ipAddress", ipAddress)
+                .add("macAddress", macAddress)
+                .toString();
+    }
+}
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
new file mode 100644
index 0000000..c10116f
--- /dev/null
+++ b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtRouter.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.Map;
+import java.util.Set;
+
+/**
+ * Representation of virtual router.
+ */
+public interface KubevirtRouter {
+
+    /**
+     * Returns the router name.
+     *
+     * @return router name
+     */
+    String name();
+
+    /**
+     * Returns the router description.
+     *
+     * @return router description
+     */
+    String description();
+
+    /**
+     * Returns the SNAT enable flag.
+     *
+     * @return true if the router support SNAT, false otherwise
+     */
+    boolean enableSnat();
+
+    /**
+     * Returns a set of internal networks.
+     *
+     * @return a set of internal networks
+     */
+    Set<String> internal();
+
+    /**
+     * Returns external network along with external router IP address.
+     * We use IP address as the key, and external network name as the value.
+     *
+     * @return external network paired with external router IP address
+     */
+    Map<IpAddress, String> external();
+
+    /**
+     * Returns external peer router.
+     *
+     * @return peer router
+     */
+    KubevirtPeerRouter peerRouter();
+
+    interface Builder {
+
+        /**
+         * Builds an immutable network instance.
+         *
+         * @return kubevirt router
+         */
+        KubevirtRouter build();
+
+        /**
+         * Returns kubevirt router builder with supplied router name.
+         *
+         * @param name router name
+         * @return router builder
+         */
+        Builder name(String name);
+
+        /**
+         * Returns kubevirt router builder with supplied router description.
+         *
+         * @param description router description
+         * @return router builder
+         */
+        Builder description(String description);
+
+        /**
+         * Returns kubevirt router builder with supplied enable SNAT flag.
+         *
+         * @param flag router flag
+         * @return router builder
+         */
+        Builder enableSnat(boolean flag);
+
+        /**
+         * Returns kubevirt router builder with supplied internal networks.
+         *
+         * @param internal internal network set
+         * @return router builder
+         */
+        Builder internal(Set<String> internal);
+
+        /**
+         * Returns kubevirt router builder with supplied external network with IP.
+         *
+         * @param external external network with IP
+         * @return router builder
+         */
+        Builder external(Map<IpAddress, String> external);
+
+        /**
+         * Returns kubevirt router builder with supplied peer router.
+         *
+         * @param router peer router
+         * @return router builder
+         */
+        Builder peerRouter(KubevirtPeerRouter 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
new file mode 100644
index 0000000..c963551
--- /dev/null
+++ b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtRouterAdminService.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 router service.
+ */
+public interface KubevirtRouterAdminService extends KubevirtRouterService {
+
+    /**
+     * Creates a kubevirt router with the given information.
+     *
+     * @param router a new router
+     */
+    void createRouter(KubevirtRouter router);
+
+    /**
+     * Updates the kubevirt router with the given information.
+     *
+     * @param router the updated router
+     */
+    void updateRouter(KubevirtRouter router);
+
+    /**
+     * Removes the router.
+     *
+     * @param name router name
+     */
+    void removeRouter(String name);
+
+    /**
+     * 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
new file mode 100644
index 0000000..52d4824
--- /dev/null
+++ b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtRouterEvent.java
@@ -0,0 +1,51 @@
+/*
+ * 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;
+
+/**
+ * Kubevirt router event class.
+ */
+public class KubevirtRouterEvent extends AbstractEvent<KubevirtRouterEvent.Type, KubevirtRouter> {
+
+    /**
+     * Creates an event of a given type for the specified kubevirt router.
+     *
+     * @param type      kubevirt router event type
+     * @param subject   kubevirt router
+     */
+    protected KubevirtRouterEvent(Type type, KubevirtRouter subject) {
+        super(type, subject);
+    }
+
+    public enum Type {
+        /**
+         * Signifies that a new kubevirt router is created.
+         */
+        KUBEVIRT_ROUTER_CREATED,
+
+        /**
+         * Signifies that the kubevirt router is updated.
+         */
+        KUBEVIRT_ROUTER_UPDATED,
+
+        /**
+         * Signifies that the kubevirt router is removed.
+         */
+        KUBEVIRT_ROUTER_REMOVED,
+    }
+}
diff --git a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtRouterListener.java b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtRouterListener.java
new file mode 100644
index 0000000..18e9ba2
--- /dev/null
+++ b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtRouterListener.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 router event.
+ */
+public interface KubevirtRouterListener extends EventListener<KubevirtRouterEvent> {
+}
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
new file mode 100644
index 0000000..03b6d35
--- /dev/null
+++ b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtRouterService.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 router.
+ */
+public interface KubevirtRouterService
+        extends ListenerService<KubevirtRouterEvent, KubevirtRouterListener> {
+
+    /**
+     * Returns the kubevirt router with the supplied router name.
+     *
+     * @param name router name
+     * @return kubevirt router
+     */
+    KubevirtRouter router(String name);
+
+    /**
+     * Returns all kubevirt routers registered in the service.
+     *
+     * @return set of kubevirt routers
+     */
+    Set<KubevirtRouter> routers();
+}
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
new file mode 100644
index 0000000..c63daa2
--- /dev/null
+++ b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtRouterStore.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 router states; not intended for direct use.
+ */
+public interface KubevirtRouterStore
+        extends Store<KubevirtRouterEvent, KubevirtRouterStoreDelegate> {
+
+    /**
+     * Creates a new kubevirt router.
+     *
+     * @param router kubevirt router
+     */
+    void createRouter(KubevirtRouter router);
+
+    /**
+     * Updates the kubevirt router.
+     *
+     * @param router kubevirt router
+     */
+    void updateRouter(KubevirtRouter router);
+
+    /**
+     * Removes the kubevirt router with the given router identifier.
+     *
+     * @param name router name
+     * @return remove kubevirt router; null if failed
+     */
+    KubevirtRouter removeRouter(String name);
+
+    /**
+     * Returns the kubevirt router with the given router name.
+     *
+     * @param name router name
+     * @return removed kubevirt router; null if failed
+     */
+    KubevirtRouter router(String name);
+
+    /**
+     * Returns all kubevirt routes.
+     *
+     * @return set of kubevirt routers
+     */
+    Set<KubevirtRouter> routers();
+
+    /**
+     * Removes all kubevirt routers.
+     */
+    void clear();
+}
diff --git a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtRouterStoreDelegate.java b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtRouterStoreDelegate.java
new file mode 100644
index 0000000..1c9a865
--- /dev/null
+++ b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtRouterStoreDelegate.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 router store delegate abstraction.
+ */
+public interface KubevirtRouterStoreDelegate extends StoreDelegate<KubevirtRouterEvent> {
+}
diff --git a/apps/kubevirt-networking/api/src/test/java/org/onosproject/kubevirtnetworking/api/DefaultKubevirtRouterTest.java b/apps/kubevirt-networking/api/src/test/java/org/onosproject/kubevirtnetworking/api/DefaultKubevirtRouterTest.java
new file mode 100644
index 0000000..2ced87e
--- /dev/null
+++ b/apps/kubevirt-networking/api/src/test/java/org/onosproject/kubevirtnetworking/api/DefaultKubevirtRouterTest.java
@@ -0,0 +1,121 @@
+/*
+ * 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.ImmutableMap;
+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 org.onlab.packet.MacAddress;
+
+import static junit.framework.TestCase.assertEquals;
+import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
+import static org.onosproject.kubevirtnetworking.api.KubevirtNetwork.Type.FLAT;
+import static org.onosproject.kubevirtnetworking.api.KubevirtNetwork.Type.VXLAN;
+
+/**
+ * Unit tests for the default kubevirt router class.
+ */
+public class DefaultKubevirtRouterTest {
+
+    private static final String NAME_1 = "router-1";
+    private static final String NAME_2 = "router-2";
+    private static final String DESCRIPTION_1 = "dummy router 1";
+    private static final String DESCRIPTION_2 = "dummy router 2";
+    private static final boolean ENABLE_SNAT_1 = false;
+    private static final boolean ENABLE_SNAT_2 = true;
+    private static final KubevirtNetwork.Type TYPE_1 = FLAT;
+    private static final KubevirtNetwork.Type TYPE_2 = VXLAN;
+    private static final String NETWORK_NAME_1 = "net-1";
+    private static final String NETWORK_NAME_2 = "net-2";
+
+    private static final KubevirtPeerRouter PEER_ROUTER_1 =
+            new KubevirtPeerRouter(IpAddress.valueOf("192.168.10.10"),
+                    MacAddress.valueOf("11:22:33:44:55:66"));
+    private static final KubevirtPeerRouter PEER_ROUTER_2 =
+            new KubevirtPeerRouter(IpAddress.valueOf("192.168.20.20"),
+                    MacAddress.valueOf("22:33:44:55:66:77"));
+
+    private KubevirtRouter router1;
+    private KubevirtRouter sameAsRouter1;
+    private KubevirtRouter router2;
+
+    /**
+     * Tests class immutability.
+     */
+    @Test
+    public void testImmutability() {
+        assertThatClassIsImmutable(DefaultKubevirtRouter.class);
+    }
+
+    /**
+     * Initial setup for this unit test.
+     */
+    @Before
+    public void setUp() {
+        router1 = DefaultKubevirtRouter.builder()
+                .name(NAME_1)
+                .description(DESCRIPTION_1)
+                .enableSnat(ENABLE_SNAT_1)
+                .internal(ImmutableSet.of(NETWORK_NAME_1))
+                .external(ImmutableMap.of(IpAddress.valueOf("10.10.10.10"), NETWORK_NAME_1))
+                .peerRouter(PEER_ROUTER_1)
+                .build();
+        sameAsRouter1 = DefaultKubevirtRouter.builder()
+                .name(NAME_1)
+                .description(DESCRIPTION_1)
+                .enableSnat(ENABLE_SNAT_1)
+                .internal(ImmutableSet.of(NETWORK_NAME_1))
+                .external(ImmutableMap.of(IpAddress.valueOf("10.10.10.10"), NETWORK_NAME_1))
+                .peerRouter(PEER_ROUTER_1)
+                .build();
+        router2 = DefaultKubevirtRouter.builder()
+                .name(NAME_2)
+                .description(DESCRIPTION_2)
+                .enableSnat(ENABLE_SNAT_2)
+                .internal(ImmutableSet.of(NETWORK_NAME_2))
+                .external(ImmutableMap.of(IpAddress.valueOf("20.20.20.20"), NETWORK_NAME_2))
+                .peerRouter(PEER_ROUTER_2)
+                .build();
+    }
+
+    /**
+     * Tests object equality.
+     */
+    @Test
+    public void testEquality() {
+        new EqualsTester().addEqualityGroup(router1, sameAsRouter1)
+                .addEqualityGroup(router2)
+                .testEquals();
+    }
+
+    /**
+     * Test object construction.
+     */
+    @Test
+    public void testConstruction() {
+        KubevirtRouter router = router1;
+
+        assertEquals(NAME_1, router.name());
+        assertEquals(DESCRIPTION_1, router.description());
+        assertEquals(ENABLE_SNAT_1, router.enableSnat());
+        assertEquals(ImmutableSet.of(NETWORK_NAME_1), router.internal());
+        assertEquals(ImmutableMap.of(IpAddress.valueOf("10.10.10.10"), NETWORK_NAME_1), router.external());
+        assertEquals(PEER_ROUTER_1, router.peerRouter());
+    }
+}