Tap Port implementation in VPP renderer
[groupbasedpolicy.git] / renderers / vpp / src / main / java / org / opendaylight / groupbasedpolicy / renderer / vpp / commands / VhostUserCommand.java
1 /*
2  * Copyright (c) 2016 Cisco Systems. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.groupbasedpolicy.renderer.vpp.commands;
10
11 import org.opendaylight.groupbasedpolicy.renderer.vpp.util.General;
12 import org.opendaylight.groupbasedpolicy.renderer.vpp.util.General.Operations;
13 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VhostUserRole;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceAugmentation;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceAugmentationBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.L2Builder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.VhostUserBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.base.attributes.interconnection.BridgeBasedBuilder;
22
23 import com.google.common.base.Preconditions;
24 import com.google.common.base.Strings;
25
26 public class VhostUserCommand extends AbstractInterfaceCommand<VhostUserCommand> {
27
28     private String socket;
29     private VhostUserRole role;
30     private String bridgeDomain;
31
32     private VhostUserCommand(VhostUserCommandBuilder builder) {
33         this.name = builder.getName();
34         this.operation = builder.getOperation();
35         this.socket = builder.getSocket();
36         this.role = builder.getRole();
37         this.enabled = builder.isEnabled();
38         this.description = builder.getDescription();
39         this.bridgeDomain = builder.getBridgeDomain();
40
41     }
42
43     public static VhostUserCommandBuilder builder() {
44         return new VhostUserCommandBuilder();
45     }
46
47     public String getSocket() {
48         return socket;
49     }
50
51     public VhostUserRole getRole() {
52         return role;
53     }
54
55     public String getBridgeDomain() {
56         return bridgeDomain;
57     }
58
59     @Override
60     public InterfaceBuilder getInterfaceBuilder() {
61         InterfaceBuilder interfaceBuilder =
62                 new InterfaceBuilder().setKey(new InterfaceKey(name))
63                     .setEnabled(enabled)
64                     .setDescription(description)
65                     .setType(
66                             org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VhostUser.class)
67                     .setName(name)
68                     .setLinkUpDownTrapEnable(Interface.LinkUpDownTrapEnable.Enabled);
69
70         // Create the vhost augmentation
71         VppInterfaceAugmentationBuilder vppAugmentationBuilder = new VppInterfaceAugmentationBuilder()
72             .setVhostUser(new VhostUserBuilder().setRole(role).setSocket(socket).build());
73         if (!Strings.isNullOrEmpty(bridgeDomain)) {
74             vppAugmentationBuilder.setL2(new L2Builder()
75                 .setInterconnection(new BridgeBasedBuilder().setBridgeDomain(bridgeDomain).build()).build());
76         }
77
78         interfaceBuilder.addAugmentation(VppInterfaceAugmentation.class, vppAugmentationBuilder.build());
79         return interfaceBuilder;
80     }
81
82     @Override
83     public String toString() {
84         return "VhostUserCommand [socket=" + socket + ", role=" + role + ", bridgeDomain=" + bridgeDomain
85                 + ", operation=" + operation + ", name=" + name + ", description=" + description + ", enabled="
86                 + enabled + "]";
87     }
88
89     public static class VhostUserCommandBuilder {
90
91         private String name;
92         private General.Operations operation;
93         private String socket;
94         private VhostUserRole role = VhostUserRole.Server;
95         private boolean enabled = true;
96         private String description;
97         private String bridgeDomain;
98
99         public String getName() {
100             return name;
101         }
102
103         public VhostUserCommandBuilder setName(String name) {
104             this.name = name;
105             return this;
106         }
107
108         public General.Operations getOperation() {
109             return operation;
110         }
111
112         public VhostUserCommandBuilder setOperation(General.Operations operation) {
113             this.operation = operation;
114             return this;
115         }
116
117         public String getSocket() {
118             return socket;
119         }
120
121         public VhostUserCommandBuilder setSocket(String socket) {
122             this.socket = socket;
123             return this;
124         }
125
126         public VhostUserRole getRole() {
127             return role;
128         }
129
130         public VhostUserCommandBuilder setRole(VhostUserRole role) {
131             this.role = role;
132             return this;
133         }
134
135         public boolean isEnabled() {
136             return enabled;
137         }
138
139         public VhostUserCommandBuilder setEnabled(boolean enabled) {
140             this.enabled = enabled;
141             return this;
142         }
143
144         public String getDescription() {
145             return description;
146         }
147
148         public VhostUserCommandBuilder setDescription(String description) {
149             this.description = description;
150             return this;
151         }
152
153         public String getBridgeDomain() {
154             return bridgeDomain;
155         }
156
157         public VhostUserCommandBuilder setBridgeDomain(String bridgeDomain) {
158             this.bridgeDomain = bridgeDomain;
159             return this;
160         }
161
162         /**
163          * VhostUserCommand build method.
164          *
165          * @return VhostUserCommand
166          * @throws IllegalArgumentException if name, operation or socket is null.
167          */
168         public VhostUserCommand build() {
169             Preconditions.checkArgument(this.name != null);
170             Preconditions.checkArgument(this.operation != null);
171             if (operation == Operations.PUT) {
172                 Preconditions.checkArgument(this.socket != null);
173             }
174
175             return new VhostUserCommand(this);
176         }
177     }
178 }