protected DOMMountPointService mountPointService = null;
BaseCallHomeTopology(String topologyId, NetconfClientDispatcher clientDispatcher,
- BindingAwareBroker bindingAwareBroker,
- Broker domBroker,
- EventExecutor eventExecutor,
- ScheduledThreadPool keepaliveExecutor,
- ThreadPool processingExecutor,
- SchemaRepositoryProvider schemaRepositoryProvider,
- DataBroker dataBroker,
- DOMMountPointService mountPointService) {
+ BindingAwareBroker bindingAwareBroker,
+ Broker domBroker,
+ EventExecutor eventExecutor,
+ ScheduledThreadPool keepaliveExecutor,
+ ThreadPool processingExecutor,
+ SchemaRepositoryProvider schemaRepositoryProvider,
+ DataBroker dataBroker,
+ DOMMountPointService mountPointService) {
super(topologyId, clientDispatcher, bindingAwareBroker, domBroker, eventExecutor, keepaliveExecutor,
processingExecutor, schemaRepositoryProvider, dataBroker);
this.mountPointService = mountPointService;
import com.google.common.base.Objects;
import com.google.common.net.InetAddresses;
-
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
-import java.security.PublicKey;
-import java.security.spec.InvalidKeySpecException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
+import java.security.PublicKey;
+import java.security.spec.InvalidKeySpecException;
import java.util.Collection;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
final Credentials credentials = deviceCred != null ? deviceCred : globalConfig.getCredentials();
if (credentials == null) {
- LOG.info("No credentials found for {}, rejecting.",remoteAddress);
+ LOG.info("No credentials found for {}, rejecting.", remoteAddress);
return CallHomeAuthorization.rejected();
}
try {
skey = AuthorizedKeysDecoder.encodePublicKey(serverKey);
return byPublicKey.get(skey);
- }
- catch (IOException | IllegalArgumentException e) {
+ } catch (IOException | IllegalArgumentException e) {
LOG.error("Unable to encode server key: {}", skey, e);
return null;
}
private final ContextKey key;
CallHomeMountSessionContext(String nodeId, CallHomeProtocolSessionContext protocol,
- CallHomeChannelActivator activator, CloseCallback callback) {
+ CallHomeChannelActivator activator, CloseCallback callback) {
this.nodeId = new NodeId(Preconditions.checkNotNull(nodeId, "nodeId"));
this.key = ContextKey.from(protocol.getRemoteAddress());
}
@SuppressWarnings("unchecked")
- <V> Promise<V> activateNetconfChannel(NetconfClientSessionListener sessionListener) {
+ <V> Promise<V> activateNetconfChannel(NetconfClientSessionListener sessionListener) {
return (Promise<V>) activator.activate(wrap(sessionListener));
}
}
CallHomeMountSessionContext createSession(CallHomeProtocolSessionContext session,
- CallHomeChannelActivator activator, final CloseCallback onCloseHandler) {
+ CallHomeChannelActivator activator, final CloseCallback onCloseHandler) {
String name = session.getSessionName();
CallHomeMountSessionContext deviceContext = new CallHomeMountSessionContext(name,
session, activator, devCtxt -> {
- CallHomeMountSessionManager.this.onClosed(devCtxt);
- onCloseHandler.onClosed(devCtxt);
- });
+ CallHomeMountSessionManager.this.onClosed(devCtxt);
+ onCloseHandler.onClosed(devCtxt);
+ });
contextByAddress.put(deviceContext.getRemoteAddress(), deviceContext);
contextByPublicKey.put(deviceContext.getRemoteServerKey(), deviceContext);
@Override
public synchronized void onClosed(CallHomeMountSessionContext deviceContext) {
contextByAddress.remove(deviceContext.getRemoteAddress());
- contextByPublicKey.remove(deviceContext.getRemoteServerKey(),deviceContext);
+ contextByPublicKey.remove(deviceContext.getRemoteServerKey(), deviceContext);
}
}
import com.google.common.base.Optional;
import com.google.common.util.concurrent.CheckedFuture;
-
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
-
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
@Override
public void onDataChanged(AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
for (InstanceIdentifier<?> removedPath : change.getRemovedPaths()) {
- if(removedPath.getTargetType() != NetconfNode.class)
+ if (removedPath.getTargetType() != NetconfNode.class)
continue;
final NodeId nodeId = getNodeId(removedPath);
LOG.warn("No corresponding callhome device found - exiting.");
} else {
Device modifiedDevice = withConnectedStatus(opDev);
- if(modifiedDevice == null)
- return ;
+ if (modifiedDevice == null)
+ return;
LOG.info("Setting successful status for callhome device id:{}.", nodeId);
writeDevice(nodeId, modifiedDevice);
}
LOG.warn("No corresponding callhome device found - exiting.");
} else {
Device modifiedDevice = withDisconnectedStatus(opDev);
- if(modifiedDevice == null)
+ if (modifiedDevice == null)
return;
LOG.info("Setting disconnected status for callhome device id:{}.", nodeId);
writeDevice(nodeId, modifiedDevice);
LOG.warn("No corresponding callhome device found - exiting.");
} else {
Device modifiedDevice = withFailedStatus(opDev);
- if(modifiedDevice == null)
+ if (modifiedDevice == null)
return;
LOG.info("Setting failed status for callhome device id:{}.", nodeId);
writeDevice(nodeId, modifiedDevice);
private Device withConnectedStatus(Device opDev) {
Device1 status = new Device1Builder().setDeviceStatus(Device1.DeviceStatus.CONNECTED).build();
return new DeviceBuilder().addAugmentation(Device1.class, status).setUniqueId(opDev.getUniqueId())
- .setSshHostKey(opDev.getSshHostKey()).build();
+ .setSshHostKey(opDev.getSshHostKey()).build();
}
private Device withFailedStatus(Device opDev) {
private Device withFailedAuthStatus(Device opDev) {
Device1 status = new Device1Builder().setDeviceStatus(Device1.DeviceStatus.FAILEDAUTHFAILURE).build();
return new DeviceBuilder().addAugmentation(Device1.class, status).setUniqueId(opDev.getUniqueId())
- .setSshHostKey(opDev.getSshHostKey()).build();
+ .setSshHostKey(opDev.getSshHostKey()).build();
}
private void setDeviceStatus(Device device) {
PublicKey pubKey = decoder.decodePublicKey(keyString);
if (sshKey.getAlgorithm().equals(pubKey.getAlgorithm()) && sshKey.equals(pubKey)) {
Device failedDevice = withFailedAuthStatus(device);
- if(failedDevice==null)
+ if (failedDevice == null)
return;
LOG.info("Setting auth failed status for callhome device id:{}.", failedDevice.getUniqueId());
setDeviceStatus(failedDevice);
result = prime * result + port.hashCode();
return result;
}
+
@Override
public boolean equals(Object obj) {
if (this == obj)
InetAddress ipAddress = inetSocketAddr.getAddress();
final IpAddress yangIp;
- if(ipAddress instanceof Inet4Address) {
+ if (ipAddress instanceof Inet4Address) {
yangIp = new IpAddress(IetfInetUtil.INSTANCE.ipv4AddressFor(ipAddress));
} else {
Preconditions.checkArgument(ipAddress instanceof Inet6Address);
@Override
public String toString() {
- if(address.getIpv4Address() != null) {
+ if (address.getIpv4Address() != null) {
return address.getIpv4Address().getValue() + ":" + port.getValue();
}
return address.getIpv6Address().getValue() + ":" + port.getValue();
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Optional;
import com.google.common.util.concurrent.CheckedFuture;
-import java.io.IOException;
import java.io.File;
+import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.Iterator;
import org.slf4j.LoggerFactory;
-public class IetfZeroTouchCallHomeServerProvider implements AutoCloseable, DataChangeListener
-{
+public class IetfZeroTouchCallHomeServerProvider implements AutoCloseable, DataChangeListener {
private static final String APPNAME = "CallHomeServer";
static final InstanceIdentifier<AllowedDevices> ALL_DEVICES = InstanceIdentifier.create(NetconfCallhomeServer.class).child(AllowedDevices.class);
private final DataBroker dataBroker;
private final CallHomeMountDispatcher mountDispacher;
- private CallHomeAuthProviderImpl authProvider ;
+ private CallHomeAuthProviderImpl authProvider;
protected NetconfCallHomeServer server;
private ListenerRegistration<IetfZeroTouchCallHomeServerProvider> listenerReg = null;
private static final String CALL_HOME_PORT_KEY = "DefaultCallHomePort";
- private static String configurationPath = "etc"+File.pathSeparator+"ztp-callhome-config.cfg";
+ private static String configurationPath = "etc" + File.pathSeparator + "ztp-callhome-config.cfg";
private int port = 0; // 0 = use default in NetconfCallHomeBuilder
private CallhomeStatusReporter statusReporter;
LOG.info("Initializing provider for {}", APPNAME);
loadConfigurableValues(configurationPath);
initializeServer();
- dataBroker.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION,ALL_DEVICES,this, AsyncDataBroker.DataChangeScope.SUBTREE);
- LOG.info( "Initialization complete for {}", APPNAME);
- }
- catch(IOException | Configuration.ConfigurationException e) {
+ dataBroker.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION, ALL_DEVICES, this, AsyncDataBroker.DataChangeScope.SUBTREE);
+ LOG.info("Initialization complete for {}", APPNAME);
+ } catch (IOException | Configuration.ConfigurationException e) {
LOG.error("Unable to successfully initialize", e);
}
}
try {
Configuration configuration = new Configuration(configurationPath);
port = configuration.getAsPort(CALL_HOME_PORT_KEY);
- }
- catch(Configuration.ConfigurationException e) {
+ } catch (Configuration.ConfigurationException e) {
LOG.error("Problem trying to load configuration values from {}", configurationPath, e);
}
}
}
private void initializeServer() throws IOException {
- LOG.info( "Initializing Call Home server instance");
+ LOG.info("Initializing Call Home server instance");
CallHomeAuthorizationProvider provider = this.getCallHomeAuthorization();
NetconfCallHomeServerBuilder builder = new NetconfCallHomeServerBuilder(
provider, mountDispacher, statusReporter);
server = builder.build();
server.bind();
mountDispacher.createTopology();
- LOG.info( "Initialization complete for Call Home server instance");
+ LOG.info("Initialization complete for Call Home server instance");
}
@VisibleForTesting
statusReporter.close();
// FIXME unbind the server
- if ( this.listenerReg != null ) {
+ if (this.listenerReg != null) {
listenerReg.close();
}
- if(server != null ) {
+ if (server != null) {
server.close();
}
handleDeletedDevices(change);
try {
- for(Device confDevice : getReadDevices(devicesFuture)) {
+ for (Device confDevice : getReadDevices(devicesFuture)) {
readAndUpdateStatus(confDevice);
}
- }
- catch(ReadFailedException e) {
+ } catch (ReadFailedException e) {
LOG.error("Error trying to read the whitelist devices: {}", e);
}
}
int numRemoved = removedDevices.size();
Iterator<InstanceIdentifier<?>> iterator = removedDevices.iterator();
- while(iterator.hasNext()){
+ while (iterator.hasNext()) {
InstanceIdentifier<?> removedIID = iterator.next();
- LOG.info("Deleting the entry for callhome device {}",removedIID);
+ LOG.info("Deleting the entry for callhome device {}", removedIID);
opTx.delete(LogicalDatastoreType.OPERATIONAL, removedIID);
}
}
private void readAndUpdateStatus(Device cfgDevice) throws ReadFailedException {
- InstanceIdentifier<Device> deviceIID = InstanceIdentifier.create(NetconfCallhomeServer.class)
+ InstanceIdentifier<Device> deviceIID = InstanceIdentifier.create(NetconfCallhomeServer.class)
.child(AllowedDevices.class)
.child(Device.class, new DeviceKey(cfgDevice.getUniqueId()));
Optional<Device> opDevGet = deviceFuture.checkedGet();
Device1 devStatus = new Device1Builder().setDeviceStatus(Device1.DeviceStatus.DISCONNECTED).build();
- if(opDevGet.isPresent()) {
+ if (opDevGet.isPresent()) {
Device opDevice = opDevGet.get();
devStatus = opDevice.getAugmentation(Device1.class);
}