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 org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
12 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
13 import org.opendaylight.groupbasedpolicy.renderer.vpp.util.General;
14 import org.opendaylight.groupbasedpolicy.renderer.vpp.util.VppIidFactory;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.dhcp.rev170315.AddressFamily;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.dhcp.rev170315.dhcp.attributes.relays.Relay;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.dhcp.rev170315.dhcp.attributes.relays.RelayBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.dhcp.rev170315.dhcp.attributes.relays.RelayKey;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.dhcp.rev170315.relay.attributes.Server;
21 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 import com.google.common.base.Preconditions;
28 import java.util.List;
30 public class DhcpRelayCommand extends AbstractConfigCommand {
32 private static final Logger LOG = LoggerFactory.getLogger(DhcpRelayCommand.class);
34 private IpAddress gatewayIpAddress;
35 private List<Server> serverIpAddresses;
36 private Class<? extends AddressFamily> addressType;
37 private NodeId vppNodeId;
39 private DhcpRelayCommand(DhcpRelayBuilder builder) {
40 operation = builder.getOperation();
41 rxVrfId = builder.getRxVrfId();
42 gatewayIpAddress = builder.getGatewayIpAddress();
43 serverIpAddresses = builder.getServerIpAddresses();
44 addressType = builder.getAddressType();
45 vppNodeId = builder.getVppNodeId();
48 public static DhcpRelayBuilder builder() {
49 return new DhcpRelayBuilder();
56 public IpAddress getGatewayIpAddress() {
57 return gatewayIpAddress;
60 public List<Server> getServerIpAddresses() {
61 return serverIpAddresses;
64 public Class<? extends AddressFamily> getAddressType() {
68 @Override public InstanceIdentifier<Relay> getIid() {
69 return VppIidFactory.getDhcpRelayIid(getDhcpBuilder().getKey());
72 public NodeId getVppNodeId() {
76 void put(ReadWriteTransaction rwTx) {
77 rwTx.put(LogicalDatastoreType.CONFIGURATION, getIid(), getDhcpBuilder().build(), true);
80 void merge(ReadWriteTransaction rwTx) {
81 rwTx.merge(LogicalDatastoreType.CONFIGURATION, getIid(), getDhcpBuilder().build(), true);
84 void delete(ReadWriteTransaction rwTx) {
86 rwTx.delete(LogicalDatastoreType.CONFIGURATION, getIid());
87 } catch (IllegalStateException ex) {
88 LOG.debug("Routing protocol not deleted from DS {}", this, ex);
92 @Override public String toString() {
93 return "DhcpProxyCommand [ rxVrfId=" + rxVrfId + ", gatewayIpAddress=" + gatewayIpAddress
94 + ", serverIpAddresses=" + serverIpAddresses + ", addressType=" + addressType
95 + ", operations=" + operation + "]";
99 * Compares two DhcpRelayCommands without checking operation status.
100 * @param compareTo DhcpRelayCommand to compare with.
101 * @return true if commands match, false otherwise.
103 @Override public boolean equals(Object compareTo) {
104 if (compareTo == null || !compareTo.getClass().equals(this.getClass())) {
108 DhcpRelayCommand command = (DhcpRelayCommand) compareTo;
110 if (!this.getVppNodeId().equals(command.getVppNodeId())) {
112 } else if (!this.getAddressType().equals(command.getAddressType())) {
114 } else if (!this.getGatewayIpAddress().equals(command.getGatewayIpAddress())) {
116 } else if (!this.getIid().equals(command.getIid())) {
118 } else if (!this.getRxVrfId().equals(command.getRxVrfId())) {
120 } else if (this.getServerIpAddresses() != null && !this.getServerIpAddresses()
121 .containsAll(command.getServerIpAddresses())) {
123 } else if (command.getServerIpAddresses() != null && !command.getServerIpAddresses()
124 .containsAll(this.getServerIpAddresses())) {
131 public RelayBuilder getDhcpBuilder() {
132 return new RelayBuilder()
133 .setAddressType(addressType)
134 .setGatewayAddress(gatewayIpAddress)
135 .setKey(new RelayKey(addressType, rxVrfId))
137 .setServer(serverIpAddresses);
140 public static class DhcpRelayBuilder {
142 private General.Operations operation;
143 private Long rxVrfId;
144 private IpAddress gatewayIpAddress;
145 private List<Server> serverIpAddress;
146 private Class<? extends AddressFamily> addressType;
147 private NodeId VppNodeId;
149 public General.Operations getOperation() {
153 public DhcpRelayBuilder setOperation(General.Operations operation) {
154 this.operation = operation;
158 public Long getRxVrfId() {
162 public DhcpRelayBuilder setRxVrfId(Long rxVrfId) {
163 this.rxVrfId = rxVrfId;
167 public IpAddress getGatewayIpAddress() {
168 return gatewayIpAddress;
171 public DhcpRelayBuilder setGatewayIpAddress(IpAddress gatewayIpAddress) {
172 this.gatewayIpAddress = gatewayIpAddress;
176 public List<Server> getServerIpAddresses() {
177 return serverIpAddress;
180 public DhcpRelayBuilder setServerIpAddresses(List<Server> serverIpAddress) {
181 this.serverIpAddress = serverIpAddress;
185 public Class<? extends AddressFamily> getAddressType() {
189 public DhcpRelayBuilder setAddressType(Class<? extends AddressFamily> addressType) {
190 this.addressType = addressType;
194 public NodeId getVppNodeId() {
198 public DhcpRelayBuilder setVppNodeId(NodeId vppNodeId) {
199 VppNodeId = vppNodeId;
204 * RoutingCommand build method.
206 * @return RoutingCommand
207 * @throws IllegalArgumentException if routerProtocol, operation or rxVrfId is null.
209 public DhcpRelayCommand build() {
210 Preconditions.checkArgument(this.operation != null);
211 Preconditions.checkArgument(this.rxVrfId != null);
212 Preconditions.checkArgument(this.addressType != null);
214 return new DhcpRelayCommand(this);