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.yangtools.yang.binding.InstanceIdentifier;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
25 import com.google.common.base.Preconditions;
27 import java.util.List;
29 public class DhcpRelayCommand extends AbstractConfigCommand {
31 private static final Logger LOG = LoggerFactory.getLogger(DhcpRelayCommand.class);
33 private IpAddress gatewayIpAddress;
34 private List<Server> serverIpAddresses;
35 private Class<? extends AddressFamily> addressType;
37 private DhcpRelayCommand(DhcpRelayBuilder builder) {
38 operation = builder.getOperation();
39 rxVrfId = builder.getRxVrfId();
40 gatewayIpAddress = builder.getGatewayIpAddress();
41 serverIpAddresses = builder.getServerIpAddresses();
42 addressType = builder.getAddressType();
45 public static DhcpRelayBuilder builder() {
46 return new DhcpRelayBuilder();
53 public IpAddress getGatewayIpAddress() {
54 return gatewayIpAddress;
57 public List<Server> getServerIpAddresses() {
58 return serverIpAddresses;
61 public Class<? extends AddressFamily> getAddressType() {
65 @Override public InstanceIdentifier<Relay> getIid() {
66 return VppIidFactory.getDhcpRelayIid(getDhcpBuilder().getKey());
69 void put(ReadWriteTransaction rwTx) {
70 rwTx.put(LogicalDatastoreType.CONFIGURATION, getIid(), getDhcpBuilder().build(), true);
73 void merge(ReadWriteTransaction rwTx) {
74 rwTx.merge(LogicalDatastoreType.CONFIGURATION, getIid(), getDhcpBuilder().build(), true);
77 void delete(ReadWriteTransaction rwTx) {
79 rwTx.delete(LogicalDatastoreType.CONFIGURATION, getIid());
80 } catch (IllegalStateException ex) {
81 LOG.debug("Routing protocol not deleted from DS {}", this, ex);
85 @Override public String toString() {
86 return "DhcpProxyCommand [ rxVrfId=" + rxVrfId + ", gatewayIpAddress=" + gatewayIpAddress
87 + ", serverIpAddresses=" + serverIpAddresses + ", addressType=" + addressType
88 + ", operations=" + operation + "]";
91 public RelayBuilder getDhcpBuilder() {
92 return new RelayBuilder()
93 .setAddressType(addressType)
94 .setGatewayAddress(gatewayIpAddress)
95 .setKey(new RelayKey(addressType, rxVrfId))
97 .setServer(serverIpAddresses);
100 public static class DhcpRelayBuilder {
102 private General.Operations operation;
103 private Long rxVrfId;
104 private IpAddress gatewayIpAddress;
105 private List<Server> serverIpAddress;
106 private Class<? extends AddressFamily> addressType;
108 public General.Operations getOperation() {
112 public DhcpRelayBuilder setOperation(General.Operations operation) {
113 this.operation = operation;
117 public Long getRxVrfId() {
121 public DhcpRelayBuilder setRxVrfId(Long rxVrfId) {
122 this.rxVrfId = rxVrfId;
126 public IpAddress getGatewayIpAddress() {
127 return gatewayIpAddress;
130 public DhcpRelayBuilder setGatewayIpAddress(IpAddress gatewayIpAddress) {
131 this.gatewayIpAddress = gatewayIpAddress;
135 public List<Server> getServerIpAddresses() {
136 return serverIpAddress;
139 public DhcpRelayBuilder setServerIpAddresses(List<Server> serverIpAddress) {
140 this.serverIpAddress = serverIpAddress;
144 public Class<? extends AddressFamily> getAddressType() {
148 public DhcpRelayBuilder setAddressType(Class<? extends AddressFamily> addressType) {
149 this.addressType = addressType;
154 * RoutingCommand build method.
156 * @return RoutingCommand
157 * @throws IllegalArgumentException if routerProtocol, operation or rxVrfId is null.
159 public DhcpRelayCommand build() {
160 Preconditions.checkArgument(this.operation != null);
161 Preconditions.checkArgument(this.rxVrfId != null);
162 Preconditions.checkArgument(this.addressType != null);
164 return new DhcpRelayCommand(this);