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