package org.opendaylight.netvirt.sfc.classifier.service.domain.impl;
-import java.util.AbstractMap;
+import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
public List<Acl> readAcls() {
InstanceIdentifier<AccessLists> aclsIID = InstanceIdentifier.builder(AccessLists.class).build();
- AccessLists acls = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, aclsIID).orNull();
+ com.google.common.base.Optional<AccessLists> acls =
+ MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, aclsIID);
LOG.trace("Acls read from datastore: {}", acls);
- return Optional.ofNullable(acls).map(AccessLists::getAcl).orElse(Collections.emptyList());
+ return acls.transform(AccessLists::getAcl).or(Collections.emptyList());
}
public Set<ClassifierRenderableEntry> getEntries(Ace ace) {
Matches matches = ace.getMatches();
- if (Objects.isNull(matches)) {
+ if (matches == null) {
LOG.trace("Ace has no matches");
return Collections.emptySet();
}
- RenderedServicePath rsp = Optional.ofNullable(ace.getActions())
+ RenderedServicePath rsp = Optional.ofNullable(ace.getActions())
.map(actions -> actions.getAugmentation(RedirectToSfc.class))
.map(NetvirtsfcAclActions::getRspName)
.flatMap(sfcProvider::getRenderedServicePath)
.orElse(null);
- if (Objects.isNull(rsp)) {
+ if (rsp == null) {
LOG.trace("Ace has no valid SFC redirect action");
return Collections.emptySet();
}
Long nsp = rsp.getPathId();
Short nsi = rsp.getStartingIndex();
- if (Objects.isNull(nsp) || Objects.isNull(nsi)) {
+ if (nsp == null || nsi == null) {
LOG.trace("RSP has no valid NSI or NSP");
return Collections.emptySet();
}
.flatMap(geniusProvider::getIpFromInterfaceName)
.orElse(null);
- if (Objects.isNull(firstHopIp)) {
+ if (firstHopIp == null) {
LOG.trace("Could not acquire a valid first RSP hop destination ip");
return Collections.emptySet();
}
- Map<NodeId, List<InterfaceKey>> nodeToInterfaces = Optional.ofNullable(matches.getAugmentation(NeutronNetwork
- .class))
- .map(netvirtProvider::getLogicalInterfacesFromNeutronNetwork)
- .orElse(Collections.emptyList())
- .stream()
- .map(iface -> new AbstractMap.SimpleEntry<>(
- new InterfaceKey(iface),
- geniusProvider.getNodeIdFromLogicalInterface(iface).orElse(null)))
- .filter(entry -> Objects.nonNull(entry.getValue()))
- .collect(Collectors.groupingBy(
- AbstractMap.Entry::getValue,
- Collectors.mapping(Map.Entry::getKey, Collectors.toList())));
+ Map<NodeId, List<InterfaceKey>> nodeToInterfaces = new HashMap<>();
+ NeutronNetwork neutronNetwork = matches.getAugmentation(NeutronNetwork.class);
+ if (neutronNetwork != null) {
+ for (String iface : netvirtProvider.getLogicalInterfacesFromNeutronNetwork(neutronNetwork)) {
+ geniusProvider.getNodeIdFromLogicalInterface(iface).ifPresent(
+ nodeId -> nodeToInterfaces.computeIfAbsent(nodeId, key -> new ArrayList<>()).add(
+ new InterfaceKey(iface)));
+ }
+ }
LOG.trace("Got classifier nodes and interfaces: {}", nodeToInterfaces);
List<String> interfaceUuidStrList = geniusProvider.getInterfacesFromNode(nodeId);
interfaceUuidStrList.forEach(interfaceUuidStr -> {
InterfaceKey interfaceKey = new InterfaceKey(interfaceUuidStr);
- String remoteIp = geniusProvider.getRemoteIpAddress(interfaceUuidStr);
- entries.add(ClassifierEntry.buildEgressEntry(interfaceKey, remoteIp == null ? nodeIp : remoteIp));
+ Optional<String> remoteIp = geniusProvider.getRemoteIpAddress(interfaceUuidStr);
+ entries.add(ClassifierEntry.buildEgressEntry(interfaceKey, remoteIp.orElse(nodeIp)));
});
});