2 * Copyright (c) 2016 Cisco Systems. All rights reserved.
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
9 package org.opendaylight.groupbasedpolicy.renderer.vpp.commands;
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;
27 public class TapPortCommand extends AbstractInterfaceCommand {
29 private String tapName;
30 private PhysAddress physAddress;
31 private Long deviceInstance;
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();
45 public static TapPortCommandBuilder builder() {
46 return new TapPortCommandBuilder();
49 public PhysAddress getPhysAddress() {
53 public Long getDeviceInstance() {
54 return deviceInstance;
57 public String getTapName() {
62 public InterfaceBuilder getInterfaceBuilder() {
63 InterfaceBuilder interfaceBuilder = new InterfaceBuilder().setKey(new InterfaceKey(name))
65 .setDescription(description)
68 .setLinkUpDownTrapEnable(Interface.LinkUpDownTrapEnable.Enabled);
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)
78 if (getVrfId() != null) {
79 vppAugmentationBuilder.setRouting(new RoutingBuilder().setIpv4VrfId(getVrfId()).build());
82 if (!Strings.isNullOrEmpty(bridgeDomain)) {
83 vppAugmentationBuilder.setL2(new L2Builder()
84 .setInterconnection(new BridgeBasedBuilder().setBridgeDomain(bridgeDomain).build()).build());
87 interfaceBuilder.addAugmentation(VppInterfaceAugmentation.class, vppAugmentationBuilder.build());
88 addEnableProxyArpAugmentation(interfaceBuilder);
89 return interfaceBuilder;
93 public String toString() {
94 return "TapPortUserCommand [physAddress=" + physAddress + ", bridgeDomain=" + bridgeDomain + ", operations="
95 + operation + ", name=" + name + ", tapName=" + tapName + ", description=" + description + ", enabled="
99 public static class TapPortCommandBuilder {
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;
112 String getInterfaceName() {
113 return interfaceName;
116 public TapPortCommandBuilder setInterfaceName(String interfaceName) {
117 this.interfaceName = interfaceName;
121 String getTapName() {
125 public TapPortCommandBuilder setTapName(String tapName) {
126 this.tapName = tapName;
130 public General.Operations getOperation() {
134 public TapPortCommandBuilder setOperation(Operations operation) {
135 this.operation = operation;
139 PhysAddress getPhysAddress() {
143 public TapPortCommandBuilder setPhysAddress(PhysAddress physAddress) {
144 this.physAddress = physAddress;
148 String getBridgeDomain() {
152 TapPortCommandBuilder setBridgeDomain(String bridgeDomain) {
153 this.bridgeDomain = bridgeDomain;
157 public String getDescription() {
161 public TapPortCommandBuilder setDescription(String description) {
162 this.description = description;
166 Long getDeviceInstance() {
167 return deviceInstance;
170 TapPortCommandBuilder setDeviceInstance(Long deviceInstance) {
171 this.deviceInstance = deviceInstance;
175 boolean isEnabled() {
179 TapPortCommandBuilder setEnabled(boolean enabled) {
180 this.enabled = enabled;
184 public Boolean getEnableProxyArp() {
185 return enableProxyArp;
188 public void setEnableProxyArp(Boolean enableProxyArp) {
189 this.enableProxyArp = enableProxyArp;
192 public Long getVrfId() {
196 public void setVrfId(Long vrfId) {
201 * TapPortCommand build method.
203 * @return TapPortCommand
204 * @throws IllegalArgumentException if interfaceName, tapName or operation is null.
206 public TapPortCommand build() {
207 Preconditions.checkArgument(this.interfaceName != null);
208 Preconditions.checkArgument(this.tapName != null);
209 Preconditions.checkArgument(this.operation != null);
211 return new TapPortCommand(this);