2 * Copyright (c) 2017 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 org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
13 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
14 import org.opendaylight.groupbasedpolicy.renderer.vpp.util.General;
15 import org.opendaylight.groupbasedpolicy.renderer.vpp.util.VppIidFactory;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
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.ip.rev140616.interfaces._interface.ipv4.Neighbor;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.NeighborBuilder;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.NeighborKey;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
27 * Created by Shakib Ahmed on 5/3/17.
29 public class StaticArpCommand extends AbstractConfigCommand{
30 private static final Logger LOG = LoggerFactory.getLogger(StaticArpCommand.class);
32 private Ipv4AddressNoZone ip;
33 private PhysAddress linkLayerAddress;
34 private InterfaceKey interfaceKey;
36 public StaticArpCommand(NeighborCommandBuilder builder) {
37 this.operation = builder.getOperation();
38 this.ip = builder.getIp();
39 this.linkLayerAddress = builder.getLinkLayerAddress();
40 this.interfaceKey = builder.getInterfaceKey();
43 public static NeighborCommandBuilder builder() {
44 return new NeighborCommandBuilder();
48 public InstanceIdentifier getIid() {
49 return VppIidFactory.getNeighborIid(interfaceKey, new NeighborKey(ip));
53 void put(ReadWriteTransaction rwTx) {
54 InstanceIdentifier<Neighbor> iid = VppIidFactory.getNeighborIid(interfaceKey, new NeighborKey(ip));
55 rwTx.put(LogicalDatastoreType.CONFIGURATION, iid, getNeighborBuilder().build());
59 void merge(ReadWriteTransaction rwTx) {
60 InstanceIdentifier<Neighbor> iid = VppIidFactory.getNeighborIid(interfaceKey, new NeighborKey(ip));
61 rwTx.merge(LogicalDatastoreType.CONFIGURATION, iid, getNeighborBuilder().build());
65 void delete(ReadWriteTransaction rwTx) {
67 InstanceIdentifier<Neighbor> iid = VppIidFactory.getNeighborIid(interfaceKey, new NeighborKey(ip));
68 rwTx.delete(LogicalDatastoreType.CONFIGURATION, iid);
69 } catch (IllegalStateException ex) {
70 LOG.debug("Proxy Range not deleted from DS {}", this, ex);
74 private NeighborBuilder getNeighborBuilder() {
75 return new NeighborBuilder()
76 .setKey(new NeighborKey(this.ip))
78 .setLinkLayerAddress(this.linkLayerAddress);
81 public static class NeighborCommandBuilder {
82 private General.Operations operation;
83 private Ipv4AddressNoZone ip;
84 private PhysAddress linkLayerAddress;
85 private InterfaceKey interfaceKey;
87 public General.Operations getOperation() {
91 public void setOperation(General.Operations operation) {
92 this.operation = operation;
95 public Ipv4AddressNoZone getIp() {
99 public void setIp(Ipv4AddressNoZone ip) {
103 public PhysAddress getLinkLayerAddress() {
104 return linkLayerAddress;
107 public void setLinkLayerAddress(PhysAddress linkLayerAddress) {
108 this.linkLayerAddress = linkLayerAddress;
111 public InterfaceKey getInterfaceKey() {
115 public void setInterfaceKey(InterfaceKey interfaceKey) {
116 this.interfaceKey = interfaceKey;
120 * StaticArpCommand build method.
122 * @return StaticArpCommand
123 * @throws IllegalArgumentException if ip or operation is null.
125 public StaticArpCommand build() {
126 Preconditions.checkNotNull(operation, "Operation must not be null!");
127 Preconditions.checkNotNull(ip, "ip must not be null!");
129 return new StaticArpCommand(this);