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