Cleanup of Lisp in VPP renderer
[groupbasedpolicy.git] / renderers / vpp / src / main / java / org / opendaylight / groupbasedpolicy / renderer / vpp / commands / UnnumberedInterfaceCommand.java
1 /*
2  * Copyright (c) 2017 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
13 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
14 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
15 import org.opendaylight.groupbasedpolicy.renderer.vpp.util.General;
16 import org.opendaylight.groupbasedpolicy.renderer.vpp.util.VppIidFactory;
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.opendaylight.params.xml.ns.yang.unnumbered.interfaces.rev170510.unnumbered.config.attributes.Unnumbered;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unnumbered.interfaces.rev170510.unnumbered.config.attributes.UnnumberedBuilder;
20 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
21
22 public class UnnumberedInterfaceCommand extends AbstractConfigCommand {
23     private String useInterface;
24     private String interfaceName;
25
26     public UnnumberedInterfaceCommand(UnnumberedInterfaceCommandBuilder builder) {
27         this.operation = builder.getOperation();
28         this.useInterface = builder.getUseInterface();
29         this.interfaceName = builder.getInterfaceName();
30     }
31
32     public static UnnumberedInterfaceCommandBuilder builder() {
33         return new UnnumberedInterfaceCommandBuilder();
34     }
35
36     @Override
37     public InstanceIdentifier<Unnumbered> getIid() {
38         return VppIidFactory.getUnnumberedIid(new InterfaceKey(interfaceName));
39     }
40
41     public String getUseInterface() {
42         return useInterface;
43     }
44
45     public String getInterfaceName() {
46         return interfaceName;
47     }
48
49     @Override
50     void put(ReadWriteTransaction rwTx) {
51         rwTx.put(LogicalDatastoreType.CONFIGURATION, getIid(), getUnnumberedBuilder().build(), true);
52     }
53
54     @Override
55     void merge(ReadWriteTransaction rwTx) {
56         rwTx.merge(LogicalDatastoreType.CONFIGURATION, getIid(), getUnnumberedBuilder().build(), true);
57     }
58
59     @Override
60     void delete(ReadWriteTransaction rwTx) {
61         rwTx.delete(LogicalDatastoreType.CONFIGURATION, getIid());
62     }
63
64     private UnnumberedBuilder getUnnumberedBuilder() {
65         return new UnnumberedBuilder().setUse(this.useInterface);
66     }
67
68     @Override public String toString() {
69         return "UnnumberedInterfaceCommand{" + "useInterface='" + useInterface + ", With='" + interfaceName + '}';
70     }
71
72     public static class UnnumberedInterfaceCommandBuilder {
73         private General.Operations operation;
74         private String useInterface;
75         private String interfaceName;
76
77         public General.Operations getOperation() {
78             return operation;
79         }
80
81         public UnnumberedInterfaceCommandBuilder setOperation(General.Operations operation) {
82             this.operation = operation;
83             return this;
84         }
85
86         public String getUseInterface() {
87             return useInterface;
88         }
89
90         public UnnumberedInterfaceCommandBuilder setUseInterface(String useInterface) {
91             this.useInterface = useInterface;
92             return this;
93         }
94
95         public String getInterfaceName() {
96             return interfaceName;
97         }
98
99         public UnnumberedInterfaceCommandBuilder setInterfaceName(String interfaceName) {
100             this.interfaceName = interfaceName;
101             return this;
102         }
103
104         /**
105          * UnnumberedInterfaceCommand build method.
106          *
107          * @return UnnumberedInterfaceCommand
108          * @throws IllegalArgumentException if useInterface or interfaceName is null.
109          */
110         public UnnumberedInterfaceCommand build() {
111             Preconditions.checkNotNull(operation, "Operation must not be null!");
112             Preconditions.checkNotNull(useInterface, "Field useInterface must not be null!");
113             Preconditions.checkNotNull(interfaceName, "Field interfaceName must not be null!");
114
115             return new UnnumberedInterfaceCommand(this);
116         }
117     }
118 }