*/
package org.opendaylight.openflowplugin.openflow.md.core.sal;
+import com.google.common.base.Preconditions;
import java.math.BigInteger;
import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.InetSocketAddress;
-
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
import org.opendaylight.openflowplugin.api.openflow.md.core.session.SessionListener;
import org.opendaylight.openflowplugin.api.openflow.md.core.session.SessionManager;
import org.opendaylight.openflowplugin.api.openflow.md.core.session.SwitchSessionKeyOF;
-import org.opendaylight.openflowplugin.openflow.md.lldp.LLDPSpeaker;
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.Ipv6Address;
NodeRef nodeRef = new NodeRef(identifier);
NodeId nodeId = nodeIdFromDatapathId(datapathId);
ModelDrivenSwitchImpl ofSwitch = new ModelDrivenSwitchImpl(nodeId, identifier, context);
- LLDPSpeaker.getInstance().addModelDrivenSwitch(identifier, ofSwitch);
CompositeObjectRegistration<ModelDrivenSwitch> registration = ofSwitch.register(providerContext);
context.setProviderRegistration(registration);
LOG.debug("ModelDrivenSwitch for {} registered to MD-SAL.", datapathId.toString());
NotificationQueueWrapper wrappedNotification = new NotificationQueueWrapper(
- nodeAdded(ofSwitch, features, nodeRef),
+ nodeAdded(ofSwitch, features, nodeRef),
context.getFeatures().getVersion());
context.getNotificationEnqueuer().enqueueNotification(wrappedNotification);
}
InstanceIdentifier<Node> identifier = identifierFromDatapathId(datapathId);
NodeRef nodeRef = new NodeRef(identifier);
NodeRemoved nodeRemoved = nodeRemoved(nodeRef);
- LLDPSpeaker.getInstance().removeModelDrivenSwitch(identifier);
- if (context.isValid()) {
- CompositeObjectRegistration<ModelDrivenSwitch> registration = context.getProviderRegistration();
+
+ CompositeObjectRegistration<ModelDrivenSwitch> registration = context.getProviderRegistration();
+ if (null != registration) {
registration.close();
+ context.setProviderRegistration(null);
}
-
LOG.debug("ModelDrivenSwitch for {} unregistered from MD-SAL.", datapathId.toString());
-
+
NotificationQueueWrapper wrappedNotification = new NotificationQueueWrapper(
nodeRemoved, context.getFeatures().getVersion());
context.getNotificationEnqueuer().enqueueNotification(wrappedNotification);
builder.setNodeRef(nodeRef);
FlowCapableNodeUpdatedBuilder builder2 = new FlowCapableNodeUpdatedBuilder();
- builder2.setIpAddress(getIpAddressOf(sw));
+ try {
+ builder2.setIpAddress(getIpAddressOf(sw));
+ } catch (Exception e) {
+ LOG.warn("IP address of the node {} cannot be obtained: {}", sw.getNodeId(), e.getMessage());
+ }
builder2.setSwitchFeatures(swFeaturesUtil.buildSwitchFeatures(features));
builder.addAugmentation(FlowCapableNodeUpdated.class, builder2.build());
return builder.build();
}
- private IpAddress getIpAddressOf(ModelDrivenSwitch sw) {
+ private static IpAddress getIpAddressOf(ModelDrivenSwitch sw) {
SessionContext sessionContext = sw.getSessionContext();
- if (!sessionContext.isValid()) {
- LOG.warn("IP address of the node {} cannot be obtained. Session is not valid.", sw.getNodeId());
- return null;
- }
+// if (!sessionContext.isValid()) {
+// LOG.warn("IP address of the node {} cannot be obtained. Session is not valid.", sw.getNodeId());
+// return null;
+// }
+ Preconditions.checkNotNull(sessionContext.getPrimaryConductor(),
+ "primary conductor must not be NULL -> " + sw.getNodeId());
+ Preconditions.checkNotNull(sessionContext.getPrimaryConductor().getConnectionAdapter(),
+ "connection adapter of primary conductor must not be NULL -> " + sw.getNodeId());
InetSocketAddress remoteAddress = sessionContext.getPrimaryConductor().getConnectionAdapter()
.getRemoteAddress();
if (remoteAddress == null) {
sessionListenerRegistration.close();
}
}
+
+ /**
+ * @param providerContext the providerContext to set
+ */
+ public void setProviderContext(ProviderContext providerContext) {
+ this.providerContext = providerContext;
+ }
}