import org.opendaylight.tcpmd5.api.KeyMapping;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev150512.MonitorId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.tcpmd5.cfg.rev140427.Rfc2385Key;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaContextProvider;
import org.osgi.framework.BundleContext;
LOG.warn("Monitored router {} does not have an address skipping it", mr);
continue;
}
- if (mr.getPassword() != null) {
+ final Rfc2385Key rfc2385KeyPassword = mr.getPassword();
+ String password;
+ if (rfc2385KeyPassword != null && !(password = rfc2385KeyPassword.getValue()).isEmpty()) {
final String s = getAddressString(mr.getAddress());
- ret.put(InetAddresses.forString(s), mr.getPassword().getValue().getBytes(Charsets.US_ASCII));
+ ret.put(InetAddresses.forString(s), password.getBytes(Charsets.US_ASCII));
}
}
}
final String s = mr.getAddress().getIpv4Address().getValue();
final InetAddress addr = InetAddresses.forString(s);
KeyMapping ret = null;
- final Rfc2385Key passwords = mr.getPassword();
- if (passwords != null) {
+ final Rfc2385Key rfc2385KeyPassword = mr.getPassword();
+ String password;
+ if (rfc2385KeyPassword != null && !(password = rfc2385KeyPassword.getValue()).isEmpty()) {
ret = new KeyMapping();
- ret.put(addr, passwords.getValue().getBytes(Charsets.US_ASCII));
+ ret.put(addr, password.getBytes(Charsets.US_ASCII));
}
try {
clientChannels.add(dispatcher.createClient(
private final boolean active;
private final List<BgpTableType> advertizedTables;
private final AsNumber asNumber;
- private final Rfc2385Key password;
+ private final Optional<Rfc2385Key> password;
public BGPPeerInstanceConfiguration(final InstanceConfigurationIdentifier identifier, final IpAddress host, final PortNumber port, final short holdTimer, final PeerRole peerRole,
- final boolean active, final List<BgpTableType> advertizedTables, final AsNumber asNumber, final Rfc2385Key password) {
+ final boolean active, final List<BgpTableType> advertizedTables, final AsNumber asNumber, final Optional<Rfc2385Key> password) {
super(identifier);
this.host = Preconditions.checkNotNull(host);
this.port = Preconditions.checkNotNull(port);
this.active = Preconditions.checkNotNull(active);
this.advertizedTables = Preconditions.checkNotNull(advertizedTables);
this.asNumber = Preconditions.checkNotNull(asNumber);
- this.password = password;
+ this.password = Preconditions.checkNotNull(password);
}
public IpAddress getHost() {
}
public Optional<Rfc2385Key> getPassword() {
- return Optional.fromNullable(password);
+ return password;
}
}
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.BgpTableType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerRole;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.tcpmd5.cfg.rev140427.Rfc2385Key;
public class BGPPeerInstanceConfigurationTest {
private static final AsNumber AS_NUMBER = new AsNumber(72L);
private final BGPPeerInstanceConfiguration config = new BGPPeerInstanceConfiguration(INSTANCE_NAME, HOST, PORT, HOLD_TIMER, PeerRole.Ibgp,
- Boolean.FALSE, Collections.<BgpTableType>emptyList(), AS_NUMBER, null);
+ Boolean.FALSE, Collections.<BgpTableType>emptyList(), AS_NUMBER, Optional.<Rfc2385Key>absent());
@Test
public final void testGetHost() {
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.open.bgp.parameters.optional.capabilities.c.parameters.GracefulRestartCapabilityBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.open.bgp.parameters.optional.capabilities.c.parameters.MultiprotocolCapabilityBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerRole;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.tcpmd5.cfg.rev140427.Rfc2385Key;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
JmxAttributeValidationException.checkNotNull(getHost(), "value is not set.", hostJmxAttribute);
JmxAttributeValidationException.checkNotNull(getPort(), "value is not set.", portJmxAttribute);
- if (getPassword() != null) {
+ if (getOptionaPassword(getPassword()).isPresent()) {
/*
* This is a nasty hack, but we don't have another clean solution. We cannot allow
* password being set if the injected dispatcher does not have the optional
final List<BgpParameters> tlvs = getTlvs(r);
final AsNumber remoteAs = getAsOrDefault(r);
- final String password = getPasswordOrNull();
final BGPSessionPreferences prefs = new BGPSessionPreferences(r.getLocalAs(), getHoldtimer(), r.getBgpIdentifier(), remoteAs, tlvs);
final BGPPeer bgpClientPeer;
// Initiate connection
if(getInitiateConnection()) {
- final Future<Void> cf = initiateConnection(createAddress(), password, getPeerRegistryBackwards());
+ final Future<Void> cf = initiateConnection(createAddress(), getOptionaPassword(getPassword()), getPeerRegistryBackwards());
return new CloseableNoEx() {
@Override
public void close() {
void close();
}
- private String getPasswordOrNull() {
- final String password;
- if (getPassword() != null) {
- password = getPassword().getValue();
- } else {
- password = null;
- }
- return password;
- }
-
private AsNumber getAsOrDefault(final RIB r) {
// Remote AS number defaults to our local AS
final AsNumber remoteAs;
return new IpAddress(host.getIpv6Address());
}
- private io.netty.util.concurrent.Future<Void> initiateConnection(final InetSocketAddress address, final String password, final BGPPeerRegistry registry) {
+ private io.netty.util.concurrent.Future<Void> initiateConnection(final InetSocketAddress address, final Optional<Rfc2385Key> password, final BGPPeerRegistry registry) {
KeyMapping keys = null;
- if (password != null) {
+ if (password.isPresent()) {
keys = new KeyMapping();
- keys.put(address.getAddress(), password.getBytes(Charsets.US_ASCII));
+ keys.put(address.getAddress(), password.get().getValue().getBytes(Charsets.US_ASCII));
}
final RIB rib = getRibDependency();
if (neighborProvider != null) {
neighborProvider.writeConfiguration(new BGPPeerInstanceConfiguration(identifier,
getHostWithoutValue(), getPort(), getHoldtimer(), getPeerRole(), getInitiateConnection(),
- getAdvertizedTableDependency(), getAsOrDefault(getRibDependency()), getPassword()));
+ getAdvertizedTableDependency(), getAsOrDefault(getRibDependency()), getOptionaPassword(getPassword())));
}
}
}
+ private Optional<Rfc2385Key> getOptionaPassword(Rfc2385Key password) {
+ return password != null && ! password.getValue().isEmpty() ? Optional.of(password) : Optional.<Rfc2385Key>absent();
+ }
+
}
package org.opendaylight.protocol.pcep.pcc.mock;
+import static com.google.common.base.Strings.isNullOrEmpty;
+
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.LoggerContext;
import com.google.common.base.Charsets;
}
private static KeyMapping getKeyMapping(final InetAddress inetAddress, final String password) {
- if (password != null) {
+ if (!isNullOrEmpty(password)) {
final KeyMapping keyMapping = new KeyMapping();
keyMapping.put(inetAddress, password.getBytes(Charsets.US_ASCII));
return keyMapping;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.tcpmd5.api.KeyMapping;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.tcpmd5.cfg.rev140427.Rfc2385Key;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
LOG.warn("Client {} does not have an address skipping it", c);
continue;
}
- if (c.getPassword() != null) {
+ final Rfc2385Key rfc2385KeyPassword = c.getPassword();
+ String password;
+ if (rfc2385KeyPassword != null && !(password = rfc2385KeyPassword.getValue()).isEmpty()) {
final String s = getAddressString(c.getAddress());
- ret.put(InetAddresses.forString(s), c.getPassword().getValue().getBytes(Charsets.US_ASCII));
+ ret.put(InetAddresses.forString(s), password.getBytes(Charsets.US_ASCII));
}
}
}