@Override
protected void customValidation() {
- JmxAttributeValidationException.checkNotNull(getHost(), "value is not set.", hostJmxAttribute);
+ final IpAddress host = getHost();
+ JmxAttributeValidationException.checkNotNull(host, "value is not set.", hostJmxAttribute);
+ JmxAttributeValidationException.checkCondition(host.getIpv4Address() != null || host.getIpv6Address() != null,
+ "Unexpected host", hostJmxAttribute);
+
JmxAttributeValidationException.checkNotNull(getPort(), "value is not set.", portJmxAttribute);
if (getOptionaPassword(getPassword()).isPresent()) {
final AsNumber remoteAs = getAsOrDefault(r);
final BGPSessionPreferences prefs = new BGPSessionPreferences(r.getLocalAs(), getHoldtimer(), r.getBgpIdentifier(), remoteAs, tlvs);
final BGPPeer bgpClientPeer;
-
+ final IpAddress host = getNormalizedHost();
if (getPeerRole() != null) {
- bgpClientPeer = new BGPPeer(peerName(getHostWithoutValue()), r, getPeerRole());
+ bgpClientPeer = new BGPPeer(peerName(host), r, getPeerRole());
} else {
- bgpClientPeer = new BGPPeer(peerName(getHostWithoutValue()), r, PeerRole.Ibgp);
+ bgpClientPeer = new BGPPeer(peerName(host), r, PeerRole.Ibgp);
}
bgpClientPeer.registerRootRuntimeBean(getRootRuntimeBeanRegistratorWrapper());
- getPeerRegistryBackwards().addPeer(getHostWithoutValue(), bgpClientPeer, prefs);
+ getPeerRegistryBackwards().addPeer(host, bgpClientPeer, prefs);
final BGPPeerModuleTracker moduleTracker = new BGPPeerModuleTracker(r.getOpenConfigProvider());
moduleTracker.onInstanceCreate();
@Override
public void close() {
bgpClientPeer.close();
- getPeerRegistryBackwards().removePeer(getHostWithoutValue());
+ getPeerRegistryBackwards().removePeer(host);
moduleTracker.onInstanceClose();
}
};
return tlvs;
}
- public IpAddress getHostWithoutValue() {
- // FIXME we need to remove field "value" from IpAddress since equals does not work as expected when value being present
- // Remove after this bug is fixed https://bugs.opendaylight.org/show_bug.cgi?id=1276
- final IpAddress host = super.getHost();
- Preconditions.checkArgument(host.getIpv4Address() != null || host.getIpv6Address() != null, "Unexpected host %s", host);
- if(host.getIpv4Address() != null) {
- return new IpAddress(host.getIpv4Address());
- } else if(host.getIpv6Address() != null){
+ public IpAddress getNormalizedHost() {
+ final IpAddress host = getHost();
+ if(host.getIpv6Address() != null){
return new IpAddress(Ipv6Util.getFullForm(host.getIpv6Address()));
}
- throw new IllegalArgumentException("Unexpected host " + host);
+ return host;
}
private io.netty.util.concurrent.Future<Void> initiateConnection(final InetSocketAddress address, final Optional<Rfc2385Key> password, final BGPPeerRegistry registry) {
@Override
public void onInstanceCreate() {
if (neighborProvider != null) {
- neighborProvider.writeConfiguration(new BGPPeerInstanceConfiguration(identifier, Rev130715Uitl.getIpvAddress(getHostWithoutValue()),
+ neighborProvider.writeConfiguration(new BGPPeerInstanceConfiguration(identifier, Rev130715Uitl.getIpvAddress(getNormalizedHost()),
Rev130715Uitl.getPort(getPort().getValue()), getHoldtimer(), getPeerRole(), getInitiateConnection(),
getAdvertizedTableDependency(), Rev130715Uitl.getASNumber(getAsOrDefault(getRibDependency()).getValue()),
getOptionaPassword(getPassword())));
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
public class BGPPeerAcceptorModuleTest extends AbstractConfigTest {
@Test
public void testCreateBeanDefaultAddress() throws InstanceAlreadyExistsException, ConflictingVersionException, ValidationException {
try {
- final CommitStatus status = createRegistryInstance(Optional.<String>absent(), Optional.<Integer>absent(), true, true);
+ final CommitStatus status = createRegistryInstance(Optional.<IpAddress>absent(), Optional.<Integer>absent(), true, true);
assertBeanCount(1, FACTORY_NAME);
assertStatus(status, 3, 0, 0);
verify(dispatcher).createServer(any(BGPPeerRegistry.class), any(InetSocketAddress.class));
@Test
public void testCreateBean() throws Exception {
- final CommitStatus status = createRegistryInstance(Optional.of("127.0.0.1"), Optional.of(1790), true, true);
+ final IpAddress ipAdress = new IpAddress(new Ipv4Address("127.0.0.1"));
+ final CommitStatus status = createRegistryInstance(Optional.of(ipAdress), Optional.of(1790), true, true);
assertBeanCount(1, FACTORY_NAME);
assertStatus(status, 3, 0, 0);
verify(dispatcher).createServer(any(BGPPeerRegistry.class), any(InetSocketAddress.class));
}
- private CommitStatus createRegistryInstance(final Optional<String> address, final Optional<Integer> port, final boolean addRegistry, final boolean addDispatcher ) throws InstanceAlreadyExistsException, ValidationException, ConflictingVersionException {
+ private CommitStatus createRegistryInstance(final Optional<IpAddress> address, final Optional<Integer> port, final boolean addRegistry, final boolean addDispatcher ) throws InstanceAlreadyExistsException, ValidationException, ConflictingVersionException {
final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
final ObjectName module = transaction.createModule(FACTORY_NAME, INSTANCE_NAME);
final BGPPeerAcceptorModuleMXBean proxy = transaction.newMXBeanProxy(module, BGPPeerAcceptorModuleMXBean.class);
- // FIXME JMX crashes if union was not created via artificial constructor - Bug:1276
if(address.isPresent()) {
- proxy.setBindingAddress(new IpAddress(address.get().toCharArray()));
+ proxy.setBindingAddress(address.get());
}
if(port.isPresent()) {
proxy.setBindingPort(new PortNumber(port.get()));
import org.opendaylight.controller.config.yang.tcpmd5.netty.cfg.MD5ClientChannelFactoryModuleMXBean;
import org.opendaylight.tcpmd5.jni.NativeTestSupport;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
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.rib.rev130925.PeerRole;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
private static final String INSTANCE_NAME = "bgp-peer-module-impl";
private static final String FACTORY_NAME = BGPPeerModuleFactory.NAME;
- private static final String HOST = "127.0.0.1";
+ private static final IpAddress HOST = new IpAddress(new Ipv4Address("127.0.0.1"));
private static final PortNumber portNumber = new PortNumber(1);
@Override
assertStatus(status, 0, 1, 15);
}
- private ObjectName createBgpPeerInstance(final ConfigTransactionJMXClient transaction, final String host,
+ private ObjectName createBgpPeerInstance(final ConfigTransactionJMXClient transaction, final IpAddress host,
final PortNumber port, final boolean md5, final boolean internalPeerRole) throws Exception {
final ObjectName nameCreated = transaction.createModule(FACTORY_NAME, INSTANCE_NAME);
final BGPPeerModuleMXBean mxBean = transaction.newMXBeanProxy(nameCreated, BGPPeerModuleMXBean.class);
mxBean.setPeerRegistry(createPeerRegistry(transaction));
-
- // FIXME JMX crashes if union was not created via artificial constructor - Bug:1276
- // annotated for JMX as value
- // IpAddress host1 = new IpAddress(new Ipv4Address(host));
- mxBean.setHost(host == null ? null : new IpAddress(host.toCharArray()));
+ mxBean.setHost(host);
mxBean.setPort(port);
mxBean.setAdvertizedTable(Collections.<ObjectName>emptyList());
{
return createBgpPeerInstance(HOST, portNumber, md5);
}
- private CommitStatus createBgpPeerInstance(final String host, final PortNumber port, final boolean md5) throws Exception {
+ private CommitStatus createBgpPeerInstance(final IpAddress host, final PortNumber port, final boolean md5) throws Exception {
final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
createBgpPeerInstance(transaction, host, port, md5, false);
return transaction.commit();