Policy exclusions & parallel netconf transactions
[groupbasedpolicy.git] / renderers / vpp / src / main / java / org / opendaylight / groupbasedpolicy / renderer / vpp / commands / TapPortCommand.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.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.Tap;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.VppInterfaceAugmentation;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.VppInterfaceAugmentationBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.interfaces._interface.L2Builder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.interfaces._interface.RoutingBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.interfaces._interface.TapBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.l2.config.attributes.interconnection.BridgeBasedBuilder;
24
25 import com.google.common.base.Preconditions;
26 import com.google.common.base.Strings;
27
28 public class TapPortCommand extends AbstractInterfaceCommand {
29
30     private String tapName;
31     private PhysAddress physAddress;
32     private Long deviceInstance;
33
34     private TapPortCommand(TapPortCommandBuilder builder) {
35         this.name = builder.getInterfaceName();
36         this.tapName = builder.getTapName();
37         this.operation = builder.getOperation();
38         this.physAddress = builder.getPhysAddress();
39         this.enabled = builder.isEnabled();
40         this.description = builder.getDescription();
41         this.bridgeDomain = builder.getBridgeDomain();
42         this.deviceInstance = builder.getDeviceInstance();
43         this.enableProxyArp = builder.getEnableProxyArp();
44     }
45
46     public static TapPortCommandBuilder builder() {
47         return new TapPortCommandBuilder();
48     }
49
50     public PhysAddress getPhysAddress() {
51         return physAddress;
52     }
53
54     public Long getDeviceInstance() {
55         return deviceInstance;
56     }
57
58     public String getTapName() {
59         return tapName;
60     }
61
62     @Override
63     public InterfaceBuilder getInterfaceBuilder() {
64         InterfaceBuilder interfaceBuilder = new InterfaceBuilder().setKey(new InterfaceKey(name))
65                 .setEnabled(enabled)
66                 .setDescription(description)
67                 .setType(Tap.class)
68                 .setName(name)
69                 .setLinkUpDownTrapEnable(Interface.LinkUpDownTrapEnable.Enabled);
70
71         // Create the Tap augmentation
72         VppInterfaceAugmentationBuilder vppAugmentationBuilder =
73                 new VppInterfaceAugmentationBuilder().setTap(new TapBuilder().setMac(this.physAddress)
74                         .setTapName(this.tapName)
75                         .setMac(this.physAddress)
76                         .setDeviceInstance(this.deviceInstance)
77                         .build());
78
79         if (getVrfId() != null) {
80             vppAugmentationBuilder.setRouting(new RoutingBuilder().setIpv4VrfId(getVrfId()).build());
81         }
82
83         if (!Strings.isNullOrEmpty(bridgeDomain)) {
84             vppAugmentationBuilder.setL2(new L2Builder()
85                     .setInterconnection(new BridgeBasedBuilder().setBridgeDomain(bridgeDomain).build()).build());
86         }
87
88         interfaceBuilder.addAugmentation(VppInterfaceAugmentation.class, vppAugmentationBuilder.build());
89         addEnableProxyArpAugmentation(interfaceBuilder);
90         return interfaceBuilder;
91     }
92
93     @Override
94     public String toString() {
95         return "TapPortUserCommand [physAddress=" + physAddress + ", bridgeDomain=" + bridgeDomain + ", operations="
96                 + operation + ", name=" + name + ", tapName=" + tapName + ", description=" + description + ", enabled="
97                 + enabled + "]";
98     }
99
100     public static class TapPortCommandBuilder {
101
102         private String interfaceName;
103         private String tapName;
104         private Operations operation;
105         private PhysAddress physAddress;
106         private String bridgeDomain;
107         private String description;
108         private Long deviceInstance = null;
109         private boolean enabled = true;
110         private Boolean enableProxyArp;
111         private Long vrfId;
112
113         String getInterfaceName() {
114             return interfaceName;
115         }
116
117         public TapPortCommandBuilder setInterfaceName(String interfaceName) {
118             this.interfaceName = interfaceName;
119             return this;
120         }
121
122         String getTapName() {
123             return tapName;
124         }
125
126         public TapPortCommandBuilder setTapName(String tapName) {
127             this.tapName = tapName;
128             return this;
129         }
130
131         public General.Operations getOperation() {
132             return operation;
133         }
134
135         public TapPortCommandBuilder setOperation(Operations operation) {
136             this.operation = operation;
137             return this;
138         }
139
140         PhysAddress getPhysAddress() {
141             return physAddress;
142         }
143
144         public TapPortCommandBuilder setPhysAddress(PhysAddress physAddress) {
145             this.physAddress = physAddress;
146             return this;
147         }
148
149         String getBridgeDomain() {
150             return bridgeDomain;
151         }
152
153         TapPortCommandBuilder setBridgeDomain(String bridgeDomain) {
154             this.bridgeDomain = bridgeDomain;
155             return this;
156         }
157
158         public String getDescription() {
159             return description;
160         }
161
162         public TapPortCommandBuilder setDescription(String description) {
163             this.description = description;
164             return this;
165         }
166
167         Long getDeviceInstance() {
168             return deviceInstance;
169         }
170
171         TapPortCommandBuilder setDeviceInstance(Long deviceInstance) {
172             this.deviceInstance = deviceInstance;
173             return this;
174         }
175
176         boolean isEnabled() {
177             return enabled;
178         }
179
180         TapPortCommandBuilder setEnabled(boolean enabled) {
181             this.enabled = enabled;
182             return this;
183         }
184
185         public Boolean getEnableProxyArp() {
186             return enableProxyArp;
187         }
188
189         public void setEnableProxyArp(Boolean enableProxyArp) {
190             this.enableProxyArp = enableProxyArp;
191         }
192
193         public Long getVrfId() {
194             return vrfId;
195         }
196
197         public void setVrfId(Long vrfId) {
198             this.vrfId = vrfId;
199         }
200
201         /**
202          * TapPortCommand build method.
203          *
204          * @return TapPortCommand
205          * @throws IllegalArgumentException if interfaceName, tapName or operation is null.
206          */
207         public TapPortCommand build() {
208             Preconditions.checkArgument(this.interfaceName != null);
209             Preconditions.checkArgument(this.tapName != null);
210             Preconditions.checkArgument(this.operation != null);
211
212             return new TapPortCommand(this);
213         }
214     }
215 }