Tap Port implementation in VPP renderer
[groupbasedpolicy.git] / renderers / vpp / src / main / java / org / opendaylight / groupbasedpolicy / renderer / vpp / commands / VhostUserCommand.java
index b5c827763ed07474deea163c5cd463eace464c54..f72452490485e63aca917952777e14f71b2a8969 100644 (file)
-/*\r
- * Copyright (c) 2016 Cisco Systems. All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-\r
-package org.opendaylight.groupbasedpolicy.renderer.vpp.commands;\r
-\r
-import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;\r
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;\r
-import org.opendaylight.groupbasedpolicy.renderer.vpp.util.General;\r
-import org.opendaylight.groupbasedpolicy.renderer.vpp.util.General.Operations;\r
-import org.opendaylight.groupbasedpolicy.renderer.vpp.util.VppIidFactory;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VhostUserRole;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceAugmentation;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceAugmentationBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.L2Builder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.VhostUserBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.base.attributes.interconnection.BridgeBasedBuilder;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-import com.google.common.base.Preconditions;\r
-import com.google.common.base.Strings;\r
-\r
-public class VhostUserCommand extends AbstractInterfaceCommand<VhostUserCommand> {\r
-\r
-    private static final Logger LOG = LoggerFactory.getLogger(VhostUserCommand.class);\r
-    private String socket;\r
-    private VhostUserRole role;\r
-    private String bridgeDomain;\r
-\r
-    private VhostUserCommand(VhostUserCommandBuilder builder) {\r
-        this.name = builder.getName();\r
-        this.operation = builder.getOperation();\r
-        this.socket = builder.getSocket();\r
-        this.role = builder.getRole();\r
-        this.enabled = builder.isEnabled();\r
-        this.description = builder.getDescription();\r
-        this.bridgeDomain = builder.getBridgeDomain();\r
-\r
-    }\r
-\r
-    public static VhostUserCommandBuilder builder() {\r
-        return new VhostUserCommandBuilder();\r
-    }\r
-\r
-    public String getSocket() {\r
-        return socket;\r
-    }\r
-\r
-    public VhostUserRole getRole() {\r
-        return role;\r
-    }\r
-\r
-    public String getBridgeDomain() {\r
-        return bridgeDomain;\r
-    }\r
-\r
-    @Override\r
-    public void execute(ReadWriteTransaction readWriteTransaction) {\r
-        switch (getOperation()) {\r
-\r
-            case PUT:\r
-                LOG.debug("Executing Add operation for command: {}", this);\r
-                put(readWriteTransaction);\r
-                break;\r
-            case DELETE:\r
-                LOG.debug("Executing Delete operation for command: {}", this);\r
-                delete(readWriteTransaction);\r
-                break;\r
-            case MERGE:\r
-                LOG.debug("Executing Update operation for command: {}", this);\r
-                merge(readWriteTransaction);\r
-                break;\r
-            default:\r
-                LOG.error("Execution failed for command: {}", this);\r
-                break;\r
-        }\r
-    }\r
-\r
-    private void put(ReadWriteTransaction readWriteTransaction) {\r
-        InterfaceBuilder interfaceBuilder = getVhostUserInterfaceBuilder();\r
-\r
-        readWriteTransaction.put(LogicalDatastoreType.CONFIGURATION,\r
-                VppIidFactory.getInterfaceIID(interfaceBuilder.getKey()), interfaceBuilder.build(), true);\r
-    }\r
-\r
-    private void merge(ReadWriteTransaction readWriteTransaction) {\r
-        InterfaceBuilder interfaceBuilder = getVhostUserInterfaceBuilder();\r
-\r
-            readWriteTransaction.merge(LogicalDatastoreType.CONFIGURATION,\r
-                    VppIidFactory.getInterfaceIID(interfaceBuilder.getKey()), interfaceBuilder.build());\r
-    }\r
-\r
-    private InterfaceBuilder getVhostUserInterfaceBuilder() {\r
-        InterfaceBuilder interfaceBuilder =\r
-                new InterfaceBuilder().setKey(new InterfaceKey(name))\r
-                        .setEnabled(enabled)\r
-                        .setDescription(description)\r
-                        .setType(\r
-                                org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VhostUser.class)\r
-                        .setName(name)\r
-                        .setLinkUpDownTrapEnable(Interface.LinkUpDownTrapEnable.Enabled);\r
-\r
-        // Create the vhost augmentation\r
-        VppInterfaceAugmentationBuilder vppAugmentationBuilder = new VppInterfaceAugmentationBuilder()\r
-            .setVhostUser(new VhostUserBuilder().setRole(role).setSocket(socket).build());\r
-        if (!Strings.isNullOrEmpty(bridgeDomain)) {\r
-            vppAugmentationBuilder.setL2(new L2Builder()\r
-                .setInterconnection(new BridgeBasedBuilder().setBridgeDomain(bridgeDomain).build()).build());\r
-        }\r
-\r
-        interfaceBuilder.addAugmentation(VppInterfaceAugmentation.class, vppAugmentationBuilder.build());\r
-        return interfaceBuilder;\r
-    }\r
-\r
-    private void delete(ReadWriteTransaction readWriteTransaction) {\r
-        try {\r
-            readWriteTransaction.delete(LogicalDatastoreType.CONFIGURATION,\r
-                    VppIidFactory.getInterfaceIID(new InterfaceKey(name)));\r
-        } catch (IllegalStateException ex) {\r
-            LOG.debug("Vhost Interface is not present in DS", ex);\r
-        }\r
-\r
-    }\r
-\r
-    @Override\r
-    public String toString() {\r
-        return "VhostUserCommand [socket=" + socket + ", role=" + role + ", bridgeDomain=" + bridgeDomain\r
-                + ", operation=" + operation + ", name=" + name + ", description=" + description + ", enabled="\r
-                + enabled + "]";\r
-    }\r
-\r
-\r
-\r
-    public static class VhostUserCommandBuilder {\r
-\r
-        private String name;\r
-        private General.Operations operation;\r
-        private String socket;\r
-        private VhostUserRole role = VhostUserRole.Server;\r
-        private boolean enabled = true;\r
-        private String description;\r
-        private String bridgeDomain;\r
-\r
-        public String getName() {\r
-            return name;\r
-        }\r
-\r
-        public VhostUserCommandBuilder setName(String name) {\r
-            this.name = name;\r
-            return this;\r
-        }\r
-\r
-        public General.Operations getOperation() {\r
-            return operation;\r
-        }\r
-\r
-        public VhostUserCommandBuilder setOperation(General.Operations operation) {\r
-            this.operation = operation;\r
-            return this;\r
-        }\r
-\r
-        public String getSocket() {\r
-            return socket;\r
-        }\r
-\r
-        public VhostUserCommandBuilder setSocket(String socket) {\r
-            this.socket = socket;\r
-            return this;\r
-        }\r
-\r
-        public VhostUserRole getRole() {\r
-            return role;\r
-        }\r
-\r
-        public VhostUserCommandBuilder setRole(VhostUserRole role) {\r
-            this.role = role;\r
-            return this;\r
-        }\r
-\r
-        public boolean isEnabled() {\r
-            return enabled;\r
-        }\r
-\r
-        public VhostUserCommandBuilder setEnabled(boolean enabled) {\r
-            this.enabled = enabled;\r
-            return this;\r
-        }\r
-\r
-        public String getDescription() {\r
-            return description;\r
-        }\r
-\r
-        public VhostUserCommandBuilder setDescription(String description) {\r
-            this.description = description;\r
-            return this;\r
-        }\r
-\r
-        public String getBridgeDomain() {\r
-            return bridgeDomain;\r
-        }\r
-\r
-        public VhostUserCommandBuilder setBridgeDomain(String bridgeDomain) {\r
-            this.bridgeDomain = bridgeDomain;\r
-            return this;\r
-        }\r
-\r
-        /**\r
-         * VhostUserCommand build method.\r
-         *\r
-         * @return VhostUserCommand\r
-         * @throws IllegalArgumentException if name, operation or socket is null.\r
-         */\r
-        public VhostUserCommand build() {\r
-            Preconditions.checkArgument(this.name != null);\r
-            Preconditions.checkArgument(this.operation != null);\r
-            if (operation == Operations.PUT) {\r
-                Preconditions.checkArgument(this.socket != null);\r
-            }\r
-\r
-            return new VhostUserCommand(this);\r
-        }\r
-    }\r
-}\r
+/*
+ * Copyright (c) 2016 Cisco Systems. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.groupbasedpolicy.renderer.vpp.commands;
+
+import org.opendaylight.groupbasedpolicy.renderer.vpp.util.General;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.util.General.Operations;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VhostUserRole;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceAugmentationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.L2Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.VhostUserBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.base.attributes.interconnection.BridgeBasedBuilder;
+
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+
+public class VhostUserCommand extends AbstractInterfaceCommand<VhostUserCommand> {
+
+    private String socket;
+    private VhostUserRole role;
+    private String bridgeDomain;
+
+    private VhostUserCommand(VhostUserCommandBuilder builder) {
+        this.name = builder.getName();
+        this.operation = builder.getOperation();
+        this.socket = builder.getSocket();
+        this.role = builder.getRole();
+        this.enabled = builder.isEnabled();
+        this.description = builder.getDescription();
+        this.bridgeDomain = builder.getBridgeDomain();
+
+    }
+
+    public static VhostUserCommandBuilder builder() {
+        return new VhostUserCommandBuilder();
+    }
+
+    public String getSocket() {
+        return socket;
+    }
+
+    public VhostUserRole getRole() {
+        return role;
+    }
+
+    public String getBridgeDomain() {
+        return bridgeDomain;
+    }
+
+    @Override
+    public InterfaceBuilder getInterfaceBuilder() {
+        InterfaceBuilder interfaceBuilder =
+                new InterfaceBuilder().setKey(new InterfaceKey(name))
+                    .setEnabled(enabled)
+                    .setDescription(description)
+                    .setType(
+                            org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VhostUser.class)
+                    .setName(name)
+                    .setLinkUpDownTrapEnable(Interface.LinkUpDownTrapEnable.Enabled);
+
+        // Create the vhost augmentation
+        VppInterfaceAugmentationBuilder vppAugmentationBuilder = new VppInterfaceAugmentationBuilder()
+            .setVhostUser(new VhostUserBuilder().setRole(role).setSocket(socket).build());
+        if (!Strings.isNullOrEmpty(bridgeDomain)) {
+            vppAugmentationBuilder.setL2(new L2Builder()
+                .setInterconnection(new BridgeBasedBuilder().setBridgeDomain(bridgeDomain).build()).build());
+        }
+
+        interfaceBuilder.addAugmentation(VppInterfaceAugmentation.class, vppAugmentationBuilder.build());
+        return interfaceBuilder;
+    }
+
+    @Override
+    public String toString() {
+        return "VhostUserCommand [socket=" + socket + ", role=" + role + ", bridgeDomain=" + bridgeDomain
+                + ", operation=" + operation + ", name=" + name + ", description=" + description + ", enabled="
+                + enabled + "]";
+    }
+
+    public static class VhostUserCommandBuilder {
+
+        private String name;
+        private General.Operations operation;
+        private String socket;
+        private VhostUserRole role = VhostUserRole.Server;
+        private boolean enabled = true;
+        private String description;
+        private String bridgeDomain;
+
+        public String getName() {
+            return name;
+        }
+
+        public VhostUserCommandBuilder setName(String name) {
+            this.name = name;
+            return this;
+        }
+
+        public General.Operations getOperation() {
+            return operation;
+        }
+
+        public VhostUserCommandBuilder setOperation(General.Operations operation) {
+            this.operation = operation;
+            return this;
+        }
+
+        public String getSocket() {
+            return socket;
+        }
+
+        public VhostUserCommandBuilder setSocket(String socket) {
+            this.socket = socket;
+            return this;
+        }
+
+        public VhostUserRole getRole() {
+            return role;
+        }
+
+        public VhostUserCommandBuilder setRole(VhostUserRole role) {
+            this.role = role;
+            return this;
+        }
+
+        public boolean isEnabled() {
+            return enabled;
+        }
+
+        public VhostUserCommandBuilder setEnabled(boolean enabled) {
+            this.enabled = enabled;
+            return this;
+        }
+
+        public String getDescription() {
+            return description;
+        }
+
+        public VhostUserCommandBuilder setDescription(String description) {
+            this.description = description;
+            return this;
+        }
+
+        public String getBridgeDomain() {
+            return bridgeDomain;
+        }
+
+        public VhostUserCommandBuilder setBridgeDomain(String bridgeDomain) {
+            this.bridgeDomain = bridgeDomain;
+            return this;
+        }
+
+        /**
+         * VhostUserCommand build method.
+         *
+         * @return VhostUserCommand
+         * @throws IllegalArgumentException if name, operation or socket is null.
+         */
+        public VhostUserCommand build() {
+            Preconditions.checkArgument(this.name != null);
+            Preconditions.checkArgument(this.operation != null);
+            if (operation == Operations.PUT) {
+                Preconditions.checkArgument(this.socket != null);
+            }
+
+            return new VhostUserCommand(this);
+        }
+    }
+}