/*
- * Copyright (c) 2014, 2015 Red Hat, Inc. and others. All rights reserved.
+ * Copyright © 2014, 2017 Red Hat, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
// insert the service if not already there. The list is ordered based of table ID.
if (!staticPipeline.contains(service) && !isTableInPipeline(service.getTable())) {
staticPipeline.add(service);
- Collections.sort(staticPipeline, Service.insertComparator);
+ staticPipeline.sort(Service.insertComparator);
}
LOG.info("registerService: {}", staticPipeline);
}
/*
- * Copyright (c) 2014 - 2016 Red Hat, Inc. and others. All rights reserved.
+ * Copyright © 2014, 2017 Red Hat, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
portSecurityRule.setSecurityRuleProtocol(null);
}
} else {
- if (portSecurityRule.getSecurityRuleProtocol().equals(MatchUtils.TCP_PROTOCOL)) {
- portSecurityRule.setSecurityRulePortMin(PORT_RANGE_MIN);
- portSecurityRule.setSecurityRulePortMax(PORT_RANGE_MAX);
- egressAclTcp(dpidLong, segmentationId, srcMac,
- portSecurityRule,dstAddress, write,
- Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false);
- } else if (portSecurityRule.getSecurityRuleProtocol().equals(MatchUtils.UDP_PROTOCOL)) {
- portSecurityRule.setSecurityRulePortMin(PORT_RANGE_MIN);
- portSecurityRule.setSecurityRulePortMax(PORT_RANGE_MAX);
- egressAclUdp(dpidLong, segmentationId, srcMac,
- portSecurityRule, dstAddress, write,
- Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false);
- } else if (portSecurityRule.getSecurityRuleProtocol().equals(MatchUtils.ICMP_PROTOCOL)) {
- egressAclIcmp(dpidLong, segmentationId, srcMac,
- portSecurityRule, dstAddress,write,
- Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false);
- } else {
- MatchBuilder matchBuilder = new MatchBuilder();
- String flowId = "Egress_Other_" + segmentationId + "_" + srcMac + "_";
- matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder,srcMac,null,MatchUtils.ETHERTYPE_IPV4);
- short proto = 0;
- try {
- Integer protocol = new Integer(portSecurityRule.getSecurityRuleProtocol());
- proto = protocol.shortValue();
- flowId = flowId + proto;
- } catch (NumberFormatException e) {
- LOG.error("Protocol vlaue conversion failure", e);
- }
- matchBuilder = MatchUtils.createIpProtocolAndEthMatch(matchBuilder, proto, srcMac, null);
- if (null != dstAddress) {
- flowId = flowId + dstAddress;
- matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder, null,
- MatchUtils.iPv4PrefixFromIPv4Address(dstAddress));
- } else if (null != portSecurityRule.getSecurityRuleRemoteIpPrefix()) {
- flowId = flowId + portSecurityRule.getSecurityRuleRemoteIpPrefix();
- if(isIpv6) {
- matchBuilder = MatchUtils.addRemoteIpv6Prefix(matchBuilder,null,
- new Ipv6Prefix(portSecurityRule.getSecurityRuleRemoteIpPrefix()));
- } else {
- if (!portSecurityRule.getSecurityRuleRemoteIpPrefix().contains("/0")) {
- matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder, null,
- new Ipv4Prefix(portSecurityRule.getSecurityRuleRemoteIpPrefix()));
+ switch (portSecurityRule.getSecurityRuleProtocol()) {
+ case MatchUtils.TCP_PROTOCOL:
+ portSecurityRule.setSecurityRulePortMin(PORT_RANGE_MIN);
+ portSecurityRule.setSecurityRulePortMax(PORT_RANGE_MAX);
+ egressAclTcp(dpidLong, segmentationId, srcMac,
+ portSecurityRule, dstAddress, write,
+ Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false);
+ break;
+ case MatchUtils.UDP_PROTOCOL:
+ portSecurityRule.setSecurityRulePortMin(PORT_RANGE_MIN);
+ portSecurityRule.setSecurityRulePortMax(PORT_RANGE_MAX);
+ egressAclUdp(dpidLong, segmentationId, srcMac,
+ portSecurityRule, dstAddress, write,
+ Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false);
+ break;
+ case MatchUtils.ICMP_PROTOCOL:
+ egressAclIcmp(dpidLong, segmentationId, srcMac,
+ portSecurityRule, dstAddress, write,
+ Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false);
+ break;
+ default:
+ MatchBuilder matchBuilder = new MatchBuilder();
+ String flowId = "Egress_Other_" + segmentationId + "_" + srcMac + "_";
+ matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder, srcMac, null,
+ MatchUtils.ETHERTYPE_IPV4);
+ short proto = 0;
+ try {
+ Integer protocol = new Integer(portSecurityRule.getSecurityRuleProtocol());
+ proto = protocol.shortValue();
+ flowId = flowId + proto;
+ } catch (NumberFormatException e) {
+ LOG.error("Protocol vlaue conversion failure", e);
+ }
+ matchBuilder = MatchUtils.createIpProtocolAndEthMatch(matchBuilder, proto, srcMac, null);
+ if (null != dstAddress) {
+ flowId = flowId + dstAddress;
+ matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder, null,
+ MatchUtils.iPv4PrefixFromIPv4Address(dstAddress));
+ } else if (null != portSecurityRule.getSecurityRuleRemoteIpPrefix()) {
+ flowId = flowId + portSecurityRule.getSecurityRuleRemoteIpPrefix();
+ if (isIpv6) {
+ matchBuilder = MatchUtils.addRemoteIpv6Prefix(matchBuilder, null,
+ new Ipv6Prefix(portSecurityRule.getSecurityRuleRemoteIpPrefix()));
+ } else {
+ if (!portSecurityRule.getSecurityRuleRemoteIpPrefix().contains("/0")) {
+ matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder, null,
+ new Ipv4Prefix(portSecurityRule.getSecurityRuleRemoteIpPrefix()));
+ }
}
}
- }
- flowId = flowId + "_Permit";
- NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
- FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowId, priority, matchBuilder, getTable());
- addInstructionWithConntrackCommit(flowBuilder, false);
- syncFlow(flowBuilder ,nodeBuilder, write);
+ flowId = flowId + "_Permit";
+ NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
+ FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowId, priority, matchBuilder, getTable());
+ addInstructionWithConntrackCommit(flowBuilder, false);
+ syncFlow(flowBuilder, nodeBuilder, write);
+ break;
}
}
}
/*
- * Copyright (c) 2014 - 2016 Red Hat, Inc. and others. All rights reserved.
+ * Copyright © 2014, 2017 Red Hat, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
portSecurityRule.setSecurityRuleProtocol(null);
}
} else {
- if (portSecurityRule.getSecurityRuleProtocol().equals(MatchUtils.TCP_PROTOCOL)) {
- portSecurityRule.setSecurityRulePortMin(PORT_RANGE_MIN);
- portSecurityRule.setSecurityRulePortMax(PORT_RANGE_MAX);
- ingressAclTcp(dpidLong, segmentationId, dstMac, portSecurityRule, srcAddress,
- write, Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false);
- } else if (portSecurityRule.getSecurityRuleProtocol().equals(MatchUtils.UDP_PROTOCOL)) {
- portSecurityRule.setSecurityRulePortMin(PORT_RANGE_MIN);
- portSecurityRule.setSecurityRulePortMax(PORT_RANGE_MAX);
- ingressAclUdp(dpidLong, segmentationId, dstMac, portSecurityRule, srcAddress,
- write, Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false);
- } else if (portSecurityRule.getSecurityRuleProtocol().equals(MatchUtils.ICMP_PROTOCOL)) {
- ingressAclIcmp(dpidLong, segmentationId, dstMac, portSecurityRule, srcAddress,
- write, Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false);
- } else {
- MatchBuilder matchBuilder = new MatchBuilder();
- String flowId = "Ingress_Other_" + segmentationId + "_" + dstMac + "_";
- matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder,null,dstMac,MatchUtils.ETHERTYPE_IPV4);
- short proto = 0;
- try {
- Integer protocol = new Integer(portSecurityRule.getSecurityRuleProtocol());
- proto = protocol.shortValue();
- flowId = flowId + proto;
- } catch (NumberFormatException e) {
- LOG.error("Protocol vlaue conversion failure", e);
- }
- matchBuilder = MatchUtils.createIpProtocolAndEthMatch(matchBuilder, proto, null, dstMac);
- if (null != srcAddress) {
- flowId = flowId + srcAddress;
- matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder,
- MatchUtils.iPv4PrefixFromIPv4Address(srcAddress), null);
- } else if (null != portSecurityRule.getSecurityRuleRemoteIpPrefix()) {
- flowId = flowId + portSecurityRule.getSecurityRuleRemoteIpPrefix();
- if(isIpv6) {
- matchBuilder = MatchUtils.addRemoteIpv6Prefix(matchBuilder,null,
- new Ipv6Prefix(portSecurityRule.getSecurityRuleRemoteIpPrefix()));
- } else {
- if (!portSecurityRule.getSecurityRuleRemoteIpPrefix().contains("/0")) {
- matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder,
- new Ipv4Prefix(portSecurityRule.getSecurityRuleRemoteIpPrefix()),null);
+ switch (portSecurityRule.getSecurityRuleProtocol()) {
+ case MatchUtils.TCP_PROTOCOL:
+ portSecurityRule.setSecurityRulePortMin(PORT_RANGE_MIN);
+ portSecurityRule.setSecurityRulePortMax(PORT_RANGE_MAX);
+ ingressAclTcp(dpidLong, segmentationId, dstMac, portSecurityRule, srcAddress,
+ write, Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false);
+ break;
+ case MatchUtils.UDP_PROTOCOL:
+ portSecurityRule.setSecurityRulePortMin(PORT_RANGE_MIN);
+ portSecurityRule.setSecurityRulePortMax(PORT_RANGE_MAX);
+ ingressAclUdp(dpidLong, segmentationId, dstMac, portSecurityRule, srcAddress,
+ write, Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false);
+ break;
+ case MatchUtils.ICMP_PROTOCOL:
+ ingressAclIcmp(dpidLong, segmentationId, dstMac, portSecurityRule, srcAddress,
+ write, Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false);
+ break;
+ default:
+ MatchBuilder matchBuilder = new MatchBuilder();
+ String flowId = "Ingress_Other_" + segmentationId + "_" + dstMac + "_";
+ matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder, null, dstMac,
+ MatchUtils.ETHERTYPE_IPV4);
+ short proto = 0;
+ try {
+ Integer protocol = new Integer(portSecurityRule.getSecurityRuleProtocol());
+ proto = protocol.shortValue();
+ flowId = flowId + proto;
+ } catch (NumberFormatException e) {
+ LOG.error("Protocol vlaue conversion failure", e);
+ }
+ matchBuilder = MatchUtils.createIpProtocolAndEthMatch(matchBuilder, proto, null, dstMac);
+ if (null != srcAddress) {
+ flowId = flowId + srcAddress;
+ matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder,
+ MatchUtils.iPv4PrefixFromIPv4Address(srcAddress), null);
+ } else if (null != portSecurityRule.getSecurityRuleRemoteIpPrefix()) {
+ flowId = flowId + portSecurityRule.getSecurityRuleRemoteIpPrefix();
+ if (isIpv6) {
+ matchBuilder = MatchUtils.addRemoteIpv6Prefix(matchBuilder, null,
+ new Ipv6Prefix(portSecurityRule.getSecurityRuleRemoteIpPrefix()));
+ } else {
+ if (!portSecurityRule.getSecurityRuleRemoteIpPrefix().contains("/0")) {
+ matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder,
+ new Ipv4Prefix(portSecurityRule.getSecurityRuleRemoteIpPrefix()), null);
+ }
}
}
- }
- flowId = flowId + "_Permit";
- NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
- FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowId, protoPortMatchPriority,
- matchBuilder, getTable());
- addInstructionWithConntrackCommit(flowBuilder, false);
- syncFlow(flowBuilder ,nodeBuilder, write);
+ flowId = flowId + "_Permit";
+ NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong);
+ FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowId, protoPortMatchPriority,
+ matchBuilder, getTable());
+ addInstructionWithConntrackCommit(flowBuilder, false);
+ syncFlow(flowBuilder, nodeBuilder, write);
+ break;
}
}
}
/*
- * Copyright (c) 2014, 2015 HP, Inc. and others. All rights reserved.
+ * Copyright © 2014, 2017 HP, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.HashMap;
@Override
public void addToCache(String remoteSgUuid, String portUuid, NodeId nodeId) {
LOG.debug("In addToCache remoteSgUuid:" + remoteSgUuid + " portUuid:" + portUuid);
- Map<String, NodeId> remoteSgPorts = securityGroupCache.get(remoteSgUuid);
- if (null == remoteSgPorts) {
- remoteSgPorts = new HashMap<>();
- securityGroupCache.put(remoteSgUuid, remoteSgPorts);
- }
+ Map<String, NodeId> remoteSgPorts = securityGroupCache.computeIfAbsent(remoteSgUuid, k -> new HashMap<>());
remoteSgPorts.put(portUuid, nodeId);
}
LOG.debug("The port list is empty for security group:" + securityGroupUuid);
return;
}
- Set portSet = portList.entrySet();
- Iterator itr = portSet.iterator();
- while(itr.hasNext()) {
- Map.Entry<String, NodeId> portEntry = (Map.Entry)itr.next();
+ for (Map.Entry<String, NodeId> portEntry : portList.entrySet()) {
String cachedportUuid = portEntry.getKey();
NodeId nodeId = portEntry.getValue();
if (cachedportUuid.equals(port.getID())) {
cachedport = neutronL3Adapter.getPortFromCleanupCache(cachedportUuid);
if (null == cachedport) {
LOG.error("In processPortRemoved cachedport port not found in neuton cache:"
- + " cachedportUuid:" + cachedportUuid);
+ + " cachedportUuid:" + cachedportUuid);
continue;
}
}
LOG.debug("The port list is empty for security group:" + securityGroupUuid);
return;
}
- Set portSet = portList.entrySet();
- Iterator itr = portSet.iterator();
- while(itr.hasNext()) {
- Map.Entry<String, NodeId> portEntry = (Map.Entry)itr.next();
+ for (Map.Entry<String, NodeId> portEntry : portList.entrySet()) {
String cachedportUuid = portEntry.getKey();
NodeId nodeId = portEntry.getValue();
if (cachedportUuid.equals(port.getID())) {
cachedport = neutronL3Adapter.getPortFromCleanupCache(cachedportUuid);
if (null == cachedport) {
LOG.error("In processPortRemoved cachedport port not found in neuton cache:"
- + " cachedportUuid:" + cachedportUuid);
+ + " cachedportUuid:" + cachedportUuid);
continue;
}
}
/*
- * Copyright (c) 2016 Red Hat, Inc. and others. All rights reserved.
+ * Copyright © 2016, 2017 Red Hat, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
*/
public static <T extends DataObject> Optional<T> read(
DataBroker broker, LogicalDatastoreType datastoreType, InstanceIdentifier<T> path) {
-
- Optional<T> result = Optional.absent();
- ReadOnlyTransaction tx = broker.newReadOnlyTransaction();
- try {
- result = tx.read(datastoreType, path).checkedGet();
+ try (ReadOnlyTransaction tx = broker.newReadOnlyTransaction()) {
+ return tx.read(datastoreType, path).checkedGet();
} catch (ReadFailedException e) {
LOG.warn("Failed to read InstanceIdentifier {} from {}", path, datastoreType, e);
- } finally {
- tx.close();
+ return Optional.absent();
}
- return result;
}
/**
/*
- * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright © 2015, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
public Map<String, String> retrieveCounterMap() {
LOGGER.trace("Polled retrieveCounterMap");
Map<String, String> countersVal = new HashMap<>(bgpCountersMap);
- Iterator<Map.Entry<String, String>> entries = countersVal.entrySet().iterator();
- while (entries.hasNext()) {
- Map.Entry<String, String> entry = entries.next();
+ for (Map.Entry<String, String> entry : countersVal.entrySet()) {
LOGGER.trace(entry.getKey() + ", Value from MBean= " + entry.getValue());
}
return countersVal;
/*
- * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright © 2015, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;
-import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
return;
}
ByteArrayOutputStream result = new ByteArrayOutputStream();
- Iterator<HostRoutes> iter = hostRoutes.iterator();
- while (iter.hasNext()) {
- HostRoutes hostRoute = iter.next();
+ for (HostRoutes hostRoute : hostRoutes) {
if (hostRoute.getNexthop().getIpv4Address() == null
- || hostRoute.getDestination().getIpv4Prefix() == null ) {
+ || hostRoute.getDestination().getIpv4Prefix() == null) {
// we only deal with IPv4 addresses
return;
}
/*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright © 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
ConcurrentMap<String, L2GatewayDevice> deviceMap = cachedMap.get(elanName);
if (deviceMap == null) {
synchronized (ElanL2GwCacheUtils.class) {
- deviceMap = cachedMap.get(elanName);
- if (deviceMap == null) {
- deviceMap = new ConcurrentHashMap<>();
- cachedMap.put(elanName, deviceMap);
- }
+ deviceMap = cachedMap.computeIfAbsent(elanName, k -> new ConcurrentHashMap<>());
}
}
deviceMap.put(l2GwDevice.getHwvtepNodeId(), l2GwDevice);
/*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright © 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* @return child Switches
*/
public static Set<InstanceIdentifier<Node>> getPSChildrenIdsForHAPSNode(String psNodId) {
- if (psNodId.indexOf(PHYSICALSWITCH) < 0) {
+ if (!psNodId.contains(PHYSICALSWITCH)) {
return Collections.emptySet();
}
String nodeId = convertToGlobalNodeId(psNodId);
/*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright © 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
Node original = HwvtepHAUtil.getOriginal(mod);
if (updated != null && original != null) {
if (updated != null && original != null) {
- if (nodeId.indexOf(HwvtepHAUtil.PHYSICALSWITCH) < 0) {
+ if (!nodeId.contains(HwvtepHAUtil.PHYSICALSWITCH)) {
onGlobalNodeUpdate(key, updated, original, tx);
} else {
onPsNodeUpdate(key, updated, original, tx);
Node deleted = HwvtepHAUtil.getRemoved(mod);
String nodeId = key.firstKeyOf(Node.class).getNodeId().getValue();
if (deleted != null) {
- if (nodeId.indexOf(HwvtepHAUtil.PHYSICALSWITCH) < 0) {
+ if (!nodeId.contains(HwvtepHAUtil.PHYSICALSWITCH)) {
LOG.info("Handle global node delete {}", deleted.getNodeId().getValue());
onGlobalNodeDelete(key, deleted, tx);
} else {
Node node = HwvtepHAUtil.getCreated(mod);
String nodeId = key.firstKeyOf(Node.class).getNodeId().getValue();
if (node != null) {
- if (nodeId.indexOf(HwvtepHAUtil.PHYSICALSWITCH) < 0) {
+ if (!nodeId.contains(HwvtepHAUtil.PHYSICALSWITCH)) {
LOG.info("Handle global node add {}", node.getNodeId().getValue());
onGlobalNodeAdd(key, node, tx);
} else {
/*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright © 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
return;
}
synchronized (HwvtepTerminationPointListener.class) {
- List<Runnable> list = waitingJobsList.get(key);
- if (list == null) {
- list = new ArrayList<>();
- waitingJobsList.put(key, list);
- }
- list.add(runnable);
+ waitingJobsList.computeIfAbsent(key, k -> new ArrayList<>()).add(runnable);
LOG.debug("added the job to wait list of physical locator {}", key);
}
}
/*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright © 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
@SuppressWarnings("checkstyle:IllegalCatch")
public <T extends DataObject> Optional<T> read(DataBroker broker, LogicalDatastoreType datastoreType,
InstanceIdentifier<T> path) {
- ReadOnlyTransaction tx = broker != null ? broker.newReadOnlyTransaction()
- : this.broker.newReadOnlyTransaction();
- Optional<T> result = Optional.absent();
- try {
- CheckedFuture<Optional<T>, ReadFailedException> checkedFuture = tx.read(datastoreType, path);
- result = checkedFuture.get();
+ try (ReadOnlyTransaction tx = broker != null ? broker.newReadOnlyTransaction()
+ : this.broker.newReadOnlyTransaction()) {
+ return tx.read(datastoreType, path).get();
} catch (Exception e) {
throw new RuntimeException(e);
- } finally {
- tx.close();
}
-
- return result;
}
public <T extends DataObject> Optional<T> read2(LogicalDatastoreType datastoreType, InstanceIdentifier<T> path)
throws ReadFailedException {
- ReadOnlyTransaction tx = broker.newReadOnlyTransaction();
- try {
+ try (ReadOnlyTransaction tx = broker.newReadOnlyTransaction()) {
CheckedFuture<Optional<T>, ReadFailedException> checkedFuture = tx.read(datastoreType, path);
return checkedFuture.checkedGet();
- } finally {
- tx.close();
}
}
/*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright © 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
import java.util.ArrayList;
import java.util.List;
+import java.util.stream.Collectors;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentationBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalSwitchRef;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.SwitchesKey;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
/**
//physicallocators
public static void addGlobalTerminationPoints(NodeBuilder nodeBuilder, InstanceIdentifier<Node> nodeIid,
List<String> globalTerminationPointIp) {
- List<TerminationPoint> terminationPoints = new ArrayList<>();
- for (int i = 0; i < globalTerminationPointIp.size(); i++) {
- terminationPoints.add(TestBuilders.buildTerminationPoint(nodeIid, globalTerminationPointIp.get(i)));
- }
- nodeBuilder.setTerminationPoint(terminationPoints);
+ nodeBuilder.setTerminationPoint(
+ globalTerminationPointIp.stream()
+ .map(ip -> TestBuilders.buildTerminationPoint(nodeIid, ip))
+ .collect(Collectors.toList()));
}
public static void addSwitches(HwvtepGlobalAugmentationBuilder augmentationBuilder, InstanceIdentifier<Node> psId) {
/*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright © 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.OPERATIONAL;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
}
public List<String> getData(String data) {
- String[] dataArray = data.split(",");
- List<String> logicalSwitch = new ArrayList<>();
- for (int i = 0; i < dataArray.length; i++) {
- logicalSwitch.add(dataArray[i]);
- }
- return logicalSwitch;
+ return Arrays.asList(data.split(","));
}
public static Uuid getUUid(String key) {
/*
- * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright © 2015, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
private ConfTransportTypeL3vpn createConfTransportType(String type) {
ConfTransportTypeL3vpn confTransType;
- if (type.equals(ITMConstants.TUNNEL_TYPE_GRE)) {
- confTransType = new ConfTransportTypeL3vpnBuilder().setTransportType(TunnelTypeGre.class).build();
- LOG.trace("Setting the confTransportType to GRE.");
- } else if (type.equals(ITMConstants.TUNNEL_TYPE_VXLAN)) {
- confTransType = new ConfTransportTypeL3vpnBuilder().setTransportType(TunnelTypeVxlan.class).build();
- LOG.trace("Setting the confTransportType to VxLAN.");
- } else {
- LOG.trace("Invalid transport type {} passed to Config DS ", type);
- confTransType = null;
+ switch (type) {
+ case ITMConstants.TUNNEL_TYPE_GRE:
+ confTransType = new ConfTransportTypeL3vpnBuilder().setTransportType(TunnelTypeGre.class).build();
+ LOG.trace("Setting the confTransportType to GRE.");
+ break;
+ case ITMConstants.TUNNEL_TYPE_VXLAN:
+ confTransType = new ConfTransportTypeL3vpnBuilder().setTransportType(TunnelTypeVxlan.class).build();
+ LOG.trace("Setting the confTransportType to VxLAN.");
+ break;
+ default:
+ LOG.trace("Invalid transport type {} passed to Config DS ", type);
+ confTransType = null;
+ break;
}
return confTransType;
}
public Class<? extends TunnelTypeBase> getReqTunType(String transportType) {
- if (transportType.equals("VXLAN")) {
- return TunnelTypeVxlan.class;
- } else if (transportType.equals("GRE")) {
- return TunnelTypeGre.class;
- } else {
- return TunnelTypeMplsOverGre.class;
+ switch (transportType) {
+ case "VXLAN":
+ return TunnelTypeVxlan.class;
+ case "GRE":
+ return TunnelTypeGre.class;
+ default:
+ return TunnelTypeMplsOverGre.class;
}
}
/*
- * Copyright (c) 2015 Dell Inc. and others. All rights reserved.
+ * Copyright © 2015, 2017 Dell Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
package org.opendaylight.netvirt.ipv6service;
-import java.util.Collection;
import java.util.HashMap;
-import java.util.Iterator;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
}
public void removeSelf() {
- Collection<VirtualPort> intfs = interfaces.values();
-
- Iterator itr = intfs.iterator();
- while (itr.hasNext()) {
- VirtualPort intf = (VirtualPort) itr.next();
+ for (VirtualPort intf : interfaces.values()) {
if (intf != null) {
intf.setRouter(null);
}
}
- Collection<VirtualSubnet> snets = subnets.values();
-
- Iterator itr2 = snets.iterator();
- while (itr2.hasNext()) {
- VirtualSubnet snet = (VirtualSubnet) itr2.next();
+ for (VirtualSubnet snet : subnets.values()) {
if (snet != null) {
snet.setRouter(null);
}
}
- return;
}
}
/*
- * Copyright (c) 2015 Dell Inc. and others. All rights reserved.
+ * Copyright © 2015, 2017 Dell Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
package org.opendaylight.netvirt.ipv6service;
-import java.util.Collection;
import java.util.HashMap;
-import java.util.Iterator;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
}
public void removeSelf() {
- Collection<VirtualPort> intfs = interfaces.values();
-
- Iterator itr = intfs.iterator();
- while (itr.hasNext()) {
- VirtualPort intf = (VirtualPort) itr.next();
+ for (VirtualPort intf : interfaces.values()) {
if (intf != null) {
intf.removeSubnetInfo(subnetUUID);
}
if (router != null) {
router.removeSubnet(this);
}
- return;
}
}
/*
- * Copyright (c) 2016 Red Hat, Inc. and others. All rights reserved.
+ * Copyright © 2016, 2017 Red Hat, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
*/
public static <T extends DataObject> Optional<T> read(DataBroker broker, LogicalDatastoreType datastoreType,
InstanceIdentifier<T> path) {
- ReadOnlyTransaction tx = broker.newReadOnlyTransaction();
- Optional<T> result = Optional.absent();
- try {
- result = tx.read(datastoreType, path).get();
+ try (ReadOnlyTransaction tx = broker.newReadOnlyTransaction()) {
+ return tx.read(datastoreType, path).get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
- } finally {
- tx.close();
}
- return result;
}
/**
/*
- * Copyright (c) 2016 Red Hat, Inc. and others. All rights reserved.
+ * Copyright © 2016, 2017 Red Hat, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
}
public PortIp allocateFixedIp(int ipVersion, String ipPfx, String subnetId) {
- PortIp portIp = fixedIpList.get(ipPfx);
- if (portIp == null) {
- portIp = new PortIp(ipVersion, ipPfx, subnetId);
- fixedIpList.put(ipPfx, portIp);
- }
+ PortIp portIp = fixedIpList.computeIfAbsent(ipPfx, k -> new PortIp(ipVersion, ipPfx, subnetId));
if (NetvirtITConstants.IPV4 == ipVersion) {
portIp.setFixedIp(ipFor(ipPfx, ofPort));
/*
- * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright © 2015, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
import com.google.common.base.Optional;
import com.google.common.util.concurrent.ListenableFuture;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
List<FixedIps> oldIPs = (original.getFixedIps() != null) ? original.getFixedIps() : new ArrayList<>();
List<FixedIps> newIPs = (update.getFixedIps() != null) ? update.getFixedIps() : new ArrayList<>();
if (!oldIPs.equals(newIPs)) {
- Iterator<FixedIps> iterator = newIPs.iterator();
- while (iterator.hasNext()) {
- FixedIps ip = iterator.next();
- if (oldIPs.remove(ip)) {
- iterator.remove();
- }
- }
+ newIPs.removeIf(oldIPs::remove);
handleNeutronPortUpdated(original, update);
}
if (NeutronConstants.DEVICE_OWNER_GATEWAY_INF.equals(update.getDeviceOwner())) {
/*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright © 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
import com.google.common.base.Optional;
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
List<Routes> oldRoutes = (original.getRoutes() != null) ? original.getRoutes() : new ArrayList<>();
List<Routes> newRoutes = (update.getRoutes() != null) ? update.getRoutes() : new ArrayList<>();
if (!oldRoutes.equals(newRoutes)) {
- Iterator<Routes> iterator = newRoutes.iterator();
- while (iterator.hasNext()) {
- Routes route = iterator.next();
- if (oldRoutes.remove(route)) {
- iterator.remove();
- }
- }
+ newRoutes.removeIf(oldRoutes::remove);
handleChangedRoutes(vpnId, newRoutes, NwConstants.ADD_FLOW);
/*
- * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright © 2015, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
}
LOG.trace("Adding extra route for destination {} onto vpn {} with nexthop {} ", destination,
vpnId.getValue(), nextHop);
- List<String> hops = adjMap.get(destination);
- if (hops == null) {
- hops = new ArrayList<>();
- adjMap.put(destination, hops);
- }
+ List<String> hops = adjMap.computeIfAbsent(destination, k -> new ArrayList<>());
if (!hops.contains(nextHop)) {
hops.add(nextHop);
}
/*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright © 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
subnetMap.put(subnet.getUuid(), subnet);
IpAddress gatewayIp = subnet.getGatewayIp();
if (gatewayIp != null) {
- Set<Uuid> gwIps = subnetGwIpMap.get(gatewayIp);
- if (gwIps == null) {
- gwIps = Sets.newConcurrentHashSet();
- subnetGwIpMap.put(gatewayIp, gwIps);
- }
- gwIps.add(subnet.getUuid());
+ subnetGwIpMap.computeIfAbsent(gatewayIp, k -> Sets.newConcurrentHashSet()).add(subnet.getUuid());
}
}
/*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright © 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
final List<ListenableFuture<Void>> futures = new ArrayList<>();
WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
java.util.Optional<Long> monitorIdOptional = AlivenessMonitorUtils.getMonitorIdFromInterface(macEntry);
- if (monitorIdOptional.isPresent()) {
- AlivenessMonitorUtils.stopArpMonitoring(alivenessManager, monitorIdOptional.get());
- }
+ monitorIdOptional.ifPresent(aLong -> AlivenessMonitorUtils.stopArpMonitoring(alivenessManager, aLong));
removeMipAdjacency(macEntry.getIpAddress().getHostAddress(),
macEntry.getVpnName(), macEntry.getInterfaceName(), tx);
VpnUtil.removeLearntVpnVipToPort(dataBroker, macEntry.getVpnName(),
/*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright © 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
}
//Iterate over the VpnId-to-Rd map.
- Iterator<Map.Entry<Long, String>> entries = vpnIdRdMap.entrySet().iterator();
- while (entries.hasNext()) {
- Map.Entry<Long, String> entry = entries.next();
+ for (Map.Entry<Long, String> entry : vpnIdRdMap.entrySet()) {
Long vpnId = entry.getKey();
rd = entry.getValue();
if ((tunnelAction == TunnelAction.TUNNEL_EP_ADD)
/*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright © 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
List<Runnable> notifieeList = null;
try {
synchronized (listenerMap) {
- notifieeList = listenerMap.get(vpnName);
- if (notifieeList == null) {
- notifieeList = new ArrayList<>();
- listenerMap.put(vpnName, notifieeList);
- }
- notifieeList.add(notifyTask);
+ listenerMap.computeIfAbsent(vpnName, k -> new ArrayList<>()).add(notifyTask);
}
synchronized (notifyTask) {
/*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright © 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
};
public static <T extends DataObject> Optional<T> read(DataBroker broker, LogicalDatastoreType datastoreType,
- InstanceIdentifier<T> path) {
-
- ReadOnlyTransaction tx = broker.newReadOnlyTransaction();
-
- Optional<T> result = Optional.absent();
- try {
- result = tx.read(datastoreType, path).get();
+ InstanceIdentifier<T> path) {
+ try (ReadOnlyTransaction tx = broker.newReadOnlyTransaction()) {
+ return tx.read(datastoreType, path).get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
- } finally {
- tx.close();
}
-
- return result;
}
public static <T extends DataObject> void asyncUpdate(DataBroker broker, LogicalDatastoreType datastoreType,