From 0219b27a51742f538e4e6eac9fc56e7b2e7030e9 Mon Sep 17 00:00:00 2001 From: David Date: Mon, 27 Mar 2017 11:51:17 +0200 Subject: [PATCH] Fix issues related to checkstyle enforcement for module interfacemanager-impl - Dates - Line lengths - Formatting - Exception catching - Order imports - Change variable names - JavaDoc - Move variables closer to their declaration - Shorten type declarations - Remove redundant modifiers - Group overloaded methods - Checkstyle enforcement in pom.xml Change-Id: Ia24783974ae39ef872a627f475d3c80571dba534 Signed-off-by: David --- .../interfacemanager-impl/pom.xml | 10 +- .../genius/interfacemanager/IfmUtil.java | 324 +++++++------ .../InterfacemgrProvider.java | 221 +++++---- .../commons/InterfaceManagerCommonUtils.java | 10 +- .../listeners/InterfaceStateListener.java | 5 +- .../InterfaceTopologyStateListener.java | 14 +- .../TerminationPointStateListener.java | 10 +- .../listeners/VlanMemberConfigListener.java | 4 +- .../pmcounters/NodeConnectorStatsImpl.java | 1 - .../ovs/utilities/SouthboundUtils.java | 4 +- .../InterfaceManagerRpcService.java | 100 ++-- ...lowBasedEgressServicesRendererFactory.java | 7 +- ...owBasedEgressServicesConfigBindHelper.java | 94 ++-- ...BasedEgressServicesConfigUnbindHelper.java | 8 +- ...wBasedIngressServicesConfigBindHelper.java | 58 +-- ...asedIngressServicesConfigUnbindHelper.java | 48 +- .../FlowBasedServicesConfigListener.java | 42 +- ...owBasedServicesInterfaceStateListener.java | 53 ++- ...lowBasedEgressServicesStateBindHelper.java | 54 ++- ...wBasedEgressServicesStateUnbindHelper.java | 40 +- ...owBasedIngressServicesStateBindHelper.java | 74 +-- ...BasedIngressServicesStateUnbindHelper.java | 55 +-- .../utilities/ActionConverterUtil.java | 195 ++++---- .../utilities/FlowBasedServicesUtils.java | 431 ++++++++++-------- .../InterfaceStatusMonitorMBean.java | 4 +- .../interfacemanager/test/IfmUtilTest.java | 11 +- .../InterfaceManagerConfigurationTest.java | 198 ++++---- .../test/InterfaceManagerTestModule.java | 19 +- .../test/InterfaceManagerTestUtil.java | 93 ++-- .../test/OvsdbSouthboundTestUtil.java | 218 ++++----- 30 files changed, 1306 insertions(+), 1099 deletions(-) diff --git a/interfacemanager/interfacemanager-impl/pom.xml b/interfacemanager/interfacemanager-impl/pom.xml index 8b5e4543f..c33e2890a 100644 --- a/interfacemanager/interfacemanager-impl/pom.xml +++ b/interfacemanager/interfacemanager-impl/pom.xml @@ -6,7 +6,8 @@ This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html --> - + 4.0.0 @@ -120,6 +121,13 @@ and is available at http://www.eclipse.org/legal/epl-v10.html org.apache.aries.blueprint blueprint-maven-plugin + + org.apache.maven.plugins + maven-checkstyle-plugin + + checkstyle.violationSeverity=error + + diff --git a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/IfmUtil.java b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/IfmUtil.java index 6e3b28ab9..8ed7448d7 100755 --- a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/IfmUtil.java +++ b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/IfmUtil.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * Copyright (c) 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, @@ -48,7 +48,6 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types. import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action; @@ -101,13 +100,11 @@ public class IfmUtil { private static final Logger LOG = LoggerFactory.getLogger(IfmUtil.class); private static final int INVALID_ID = 0; - private static final ImmutableMap, InterfaceInfo.InterfaceType> TUNNEL_TYPE_MAP = - new ImmutableMap.Builder, InterfaceInfo.InterfaceType>() - .put(TunnelTypeGre.class, GRE_TRUNK_INTERFACE) - .put(TunnelTypeMplsOverGre.class, MPLS_OVER_GRE) - .put(TunnelTypeVxlan.class, VXLAN_TRUNK_INTERFACE) - .put(TunnelTypeVxlanGpe.class, VXLAN_TRUNK_INTERFACE) - .build(); + private static final ImmutableMap, InterfaceInfo.InterfaceType> + TUNNEL_TYPE_MAP = new ImmutableMap.Builder, InterfaceInfo.InterfaceType>() + .put(TunnelTypeGre.class, GRE_TRUNK_INTERFACE).put(TunnelTypeMplsOverGre.class, MPLS_OVER_GRE) + .put(TunnelTypeVxlan.class, VXLAN_TRUNK_INTERFACE).put(TunnelTypeVxlanGpe.class, VXLAN_TRUNK_INTERFACE) + .build(); public static BigInteger getDpnFromNodeConnectorId(NodeConnectorId portId) { /* @@ -117,19 +114,23 @@ public class IfmUtil { return new BigInteger(split[1]); } - public static BigInteger getDpnFromInterface(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifState){ + public static BigInteger getDpnFromInterface( + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang + .ietf.interfaces.rev140508.interfaces.state.Interface ifState) { NodeConnectorId ncId = getNodeConnectorIdFromInterface(ifState); - if(ncId != null){ + if (ncId != null) { return getDpnFromNodeConnectorId(ncId); } return null; } + public static String getPortNoFromInterfaceName(String ifaceName, DataBroker broker) { - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifState = - InterfaceManagerCommonUtils.getInterfaceStateFromOperDS(ifaceName, broker); + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang + .ietf.interfaces.rev140508.interfaces.state.Interface ifState = InterfaceManagerCommonUtils + .getInterfaceStateFromOperDS(ifaceName, broker); - if(ifState == null){ - throw new NullPointerException("Interface information not present in oper DS for " +ifaceName); + if (ifState == null) { + throw new NullPointerException("Interface information not present in oper DS for " + ifaceName); } String lowerLayerIf = ifState.getLowerLayerIf().get(0); NodeConnectorId nodeConnectorId = new NodeConnectorId(lowerLayerIf); @@ -148,9 +149,9 @@ public class IfmUtil { public static Long getPortNumberFromNodeConnectorId(NodeConnectorId portId) { String portNo = getPortNoFromNodeConnectorId(portId); - try{ + try { return Long.valueOf(portNo); - }catch(NumberFormatException ex){ + } catch (NumberFormatException ex) { LOG.trace("Unable to retrieve port number from nodeconnector id for {}", portId); } return IfmConstants.INVALID_PORT_NO; @@ -161,32 +162,41 @@ public class IfmUtil { } public static InstanceIdentifier buildId(String interfaceName) { - //TODO Make this generic and move to AbstractDataChangeListener or Utils. - InstanceIdentifierBuilder idBuilder = - InstanceIdentifier.builder(Interfaces.class).child(Interface.class, new InterfaceKey(interfaceName)); - InstanceIdentifier id = idBuilder.build(); - return id; - } - - public static InstanceIdentifier buildStateInterfaceId(String interfaceName) { - InstanceIdentifierBuilder idBuilder = - InstanceIdentifier.builder(InterfacesState.class) - .child(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.class, - new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey(interfaceName)); - InstanceIdentifier id = idBuilder.build(); + // TODO Make this generic and move to AbstractDataChangeListener or + // Utils. + InstanceIdentifierBuilder idBuilder = InstanceIdentifier.builder(Interfaces.class) + .child(Interface.class, new InterfaceKey(interfaceName)); + return idBuilder.build(); + } + + public static InstanceIdentifier buildStateInterfaceId( + String interfaceName) { + InstanceIdentifierBuilder idBuilder = InstanceIdentifier + .builder(InterfacesState.class) + .child(org.opendaylight.yang.gen.v1.urn + .ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.class, + new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang + .ietf.interfaces.rev140508.interfaces.state.InterfaceKey( + interfaceName)); + InstanceIdentifier id = idBuilder + .build(); return id; } - public static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey getStateInterfaceKeyFromName( + public static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang + .ietf.interfaces.rev140508.interfaces.state.InterfaceKey getStateInterfaceKeyFromName( String name) { - return new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey(name); + return new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang + .ietf.interfaces.rev140508.interfaces.state.InterfaceKey( + name); } - public static InstanceIdentifier getPoolId(String poolName){ - InstanceIdentifier.InstanceIdentifierBuilder idBuilder = - InstanceIdentifier.builder(IdPools.class).child(IdPool.class, new IdPoolKey(poolName)); - InstanceIdentifier id = idBuilder.build(); - return id; + public static InstanceIdentifier getPoolId(String poolName) { + return InstanceIdentifier.builder(IdPools.class).child(IdPool.class, new IdPoolKey(poolName)).build(); } public static List getPortNameAndSuffixFromInterfaceName(String intfName) { @@ -202,8 +212,7 @@ public class IfmUtil { public static long getGroupId(long ifIndex, InterfaceInfo.InterfaceType infType) { if (infType == InterfaceInfo.InterfaceType.LOGICAL_GROUP_INTERFACE) { return ifIndex + IfmConstants.LOGICAL_GROUP_START; - } - else if (infType == VLAN_INTERFACE) { + } else if (infType == VLAN_INTERFACE) { return ifIndex + IfmConstants.VLAN_GROUP_START; } else { return ifIndex + IfmConstants.TRUNK_GROUP_START; @@ -214,7 +223,7 @@ public class IfmUtil { List strList = new ArrayList<>(3); int index1 = intfName.indexOf(":"); if (index1 != -1) { - int index2 = intfName.indexOf(":", index1 + 1 ); + int index2 = intfName.indexOf(":", index1 + 1); strList.add(0, intfName.substring(0, index1)); if (index2 != -1) { strList.add(1, intfName.substring(index1, index2)); @@ -228,17 +237,19 @@ public class IfmUtil { } public static Optional read(LogicalDatastoreType datastoreType, - InstanceIdentifier path, DataBroker broker) { + InstanceIdentifier path, DataBroker broker) { try (ReadOnlyTransaction tx = broker.newReadOnlyTransaction()) { return tx.read(datastoreType, path).get(); - } catch (Exception e) { + } catch (InterruptedException | ExecutionException e) { + LOG.error("Cannot read identifier", e); throw new RuntimeException(e); } } public static List getEgressActionsForInterface(String interfaceName, Long tunnelKey, Integer actionKey, - DataBroker dataBroker, Boolean isDefaultEgress) { - List listActionInfo = getEgressActionInfosForInterface(interfaceName, tunnelKey, actionKey==null?0:actionKey, dataBroker, isDefaultEgress); + DataBroker dataBroker, Boolean isDefaultEgress) { + List listActionInfo = getEgressActionInfosForInterface(interfaceName, tunnelKey, + actionKey == null ? 0 : actionKey, dataBroker, isDefaultEgress); List actionsList = new ArrayList<>(); for (ActionInfo actionInfo : listActionInfo) { actionsList.add(actionInfo.buildAction()); @@ -247,55 +258,55 @@ public class IfmUtil { } public static List getEgressInstructionsForInterface(String interfaceName, Long tunnelKey, - DataBroker dataBroker, Boolean isDefaultEgress) { + DataBroker dataBroker, Boolean isDefaultEgress) { List instructions = new ArrayList<>(); - List actionList = MDSALUtil.buildActions(getEgressActionInfosForInterface( - interfaceName, tunnelKey, 0, dataBroker, isDefaultEgress)); + List actionList = MDSALUtil.buildActions( + getEgressActionInfosForInterface(interfaceName, tunnelKey, 0, dataBroker, isDefaultEgress)); instructions.add(MDSALUtil.buildApplyActionsInstruction(actionList)); - return instructions; + return instructions; } public static List getEgressInstructionsForInterface(Interface interfaceInfo, String portNo, - Long tunnelKey, boolean isDefaultEgress, int ifIndex) { + Long tunnelKey, boolean isDefaultEgress, int ifIndex) { List instructions = new ArrayList<>(); InterfaceInfo.InterfaceType ifaceType = getInterfaceType(interfaceInfo); - List actionList = MDSALUtil.buildActions( - getEgressActionInfosForInterface(interfaceInfo, portNo, ifaceType, tunnelKey, 0, isDefaultEgress, ifIndex)); + List actionList = MDSALUtil.buildActions(getEgressActionInfosForInterface(interfaceInfo, portNo, + ifaceType, tunnelKey, 0, isDefaultEgress, ifIndex)); instructions.add(MDSALUtil.buildApplyActionsInstruction(actionList)); - return instructions; + return instructions; } - - public static List getEgressActionInfosForInterface(String interfaceName, - int actionKeyStart, - DataBroker dataBroker, - Boolean isDefaultEgress) { + public static List getEgressActionInfosForInterface(String interfaceName, int actionKeyStart, + DataBroker dataBroker, Boolean isDefaultEgress) { return getEgressActionInfosForInterface(interfaceName, null, actionKeyStart, dataBroker, isDefaultEgress); } /** - * Returns a list of Actions to be taken when sending a packet over an interface + * Returns a list of Actions to be taken when sending a packet over an + * interface. * * @param interfaceName - * @param tunnelKey Optional. + * name of the interface + * @param tunnelKey + * Optional. * @param actionKeyStart + * action key * @param dataBroker - * @return + * databroker + * @return list of actions */ - public static List getEgressActionInfosForInterface(String interfaceName, - Long tunnelKey, - int actionKeyStart, - DataBroker dataBroker, - Boolean isDefaultEgress) { + public static List getEgressActionInfosForInterface(String interfaceName, Long tunnelKey, + int actionKeyStart, DataBroker dataBroker, Boolean isDefaultEgress) { Interface interfaceInfo = InterfaceManagerCommonUtils.getInterfaceFromConfigDS(new InterfaceKey(interfaceName), dataBroker); - if(interfaceInfo == null){ - throw new NullPointerException("Interface information not present in config DS for " +interfaceName); + if (interfaceInfo == null) { + throw new NullPointerException("Interface information not present in config DS for " + interfaceName); } - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifState = - InterfaceManagerCommonUtils.getInterfaceStateFromOperDS(interfaceName, dataBroker); - if(ifState == null){ - throw new NullPointerException("Interface information not present in oper DS for " +interfaceName); + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang + .ietf.interfaces.rev140508.interfaces.state.Interface ifState = InterfaceManagerCommonUtils + .getInterfaceStateFromOperDS(interfaceName, dataBroker); + if (ifState == null) { + throw new NullPointerException("Interface information not present in oper DS for " + interfaceName); } String lowerLayerIf = ifState.getLowerLayerIf().get(0); NodeConnectorId nodeConnectorId = new NodeConnectorId(lowerLayerIf); @@ -306,27 +317,39 @@ public class IfmUtil { isDefaultEgress, ifState.getIfIndex()); } - - public static List getEgressActionInfosForInterface(Interface interfaceInfo, - String portNo, - InterfaceInfo.InterfaceType ifaceType, - Long tunnelKey, - int actionKeyStart, - boolean isDefaultEgress, - int ifIndex) { + /** + * Returns the list of egress actions for a given interface. + * + * @param interfaceInfo the interface to look up + * @param portNo port number + * @param ifaceType the type of the interface + * @param tunnelKey the tunnel key + * @param actionKeyStart the start for the first key assigned for the new actions + * @param isDefaultEgress if it is the default egress + * @param ifIndex interface index + * @return list of actions for the interface + */ + // The following suppression is for javac, not for checkstyle + @SuppressWarnings("fallthrough") + public static List getEgressActionInfosForInterface(Interface interfaceInfo, String portNo, + InterfaceInfo.InterfaceType ifaceType, Long tunnelKey, int actionKeyStart, boolean isDefaultEgress, + int ifIndex) { List result = new ArrayList<>(); switch (ifaceType) { case MPLS_OVER_GRE: + // fall through case GRE_TRUNK_INTERFACE: - if(!isDefaultEgress) { - //TODO tunnel_id to encode GRE key, once it is supported - // Until then, tunnel_id should be "cleaned", otherwise it stores the value coming from a VXLAN tunnel + if (!isDefaultEgress) { + // TODO tunnel_id to encode GRE key, once it is supported + // Until then, tunnel_id should be "cleaned", otherwise it + // stores the value coming from a VXLAN tunnel if (tunnelKey == null) { tunnelKey = 0L; } } + // fall through case VXLAN_TRUNK_INTERFACE: - if(!isDefaultEgress) { + if (!isDefaultEgress) { if (tunnelKey != null) { result.add(new ActionSetFieldTunnelId(actionKeyStart++, BigInteger.valueOf(tunnelKey))); } @@ -339,8 +362,9 @@ public class IfmUtil { result.add(new ActionSetTunnelSourceIp(actionKeyStart++, ifTunnel.getTunnelSource())); } } + // fall through case VLAN_INTERFACE: - if(isDefaultEgress) { + if (isDefaultEgress) { IfL2vlan vlanIface = interfaceInfo.getAugmentation(IfL2vlan.class); LOG.trace("L2Vlan: {}", vlanIface); boolean isVlanTransparent = false; @@ -354,8 +378,9 @@ public class IfmUtil { result.add(new ActionSetFieldVlanVid(actionKeyStart++, vlanVid)); } result.add(new ActionOutput(actionKeyStart++, new Uri(portNo))); - }else{ - long regValue = MetaDataUtil.getReg6ValueForLPortDispatcher(ifIndex, NwConstants.DEFAULT_SERVICE_INDEX); + } else { + long regValue = + MetaDataUtil.getReg6ValueForLPortDispatcher(ifIndex, NwConstants.DEFAULT_SERVICE_INDEX); result.add(new ActionRegLoad(actionKeyStart++, NxmNxReg6.class, IfmConstants.REG6_START_INDEX, IfmConstants.REG6_END_INDEX, regValue)); result.add(new ActionNxResubmit(actionKeyStart++, NwConstants.EGRESS_LPORT_DISPATCHER_TABLE)); @@ -369,7 +394,7 @@ public class IfmUtil { } public static NodeId getNodeIdFromNodeConnectorId(NodeConnectorId ncId) { - return new NodeId(ncId.getValue().substring(0,ncId.getValue().lastIndexOf(":"))); + return new NodeId(ncId.getValue().substring(0, ncId.getValue().lastIndexOf(":"))); } public static BigInteger[] mergeOpenflowMetadataWriteInstructions(List instructions) { @@ -378,9 +403,11 @@ public class IfmUtil { if (instructions != null && !instructions.isEmpty()) { // check if metadata write instruction is present for (Instruction instruction : instructions) { - org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction actualInstruction = instruction.getInstruction(); + org.opendaylight.yang.gen.v1.urn.opendaylight.flow + .types.rev131026.instruction.Instruction actualInstruction = instruction + .getInstruction(); if (actualInstruction instanceof WriteMetadataCase) { - WriteMetadataCase writeMetaDataInstruction = (WriteMetadataCase) actualInstruction ; + WriteMetadataCase writeMetaDataInstruction = (WriteMetadataCase) actualInstruction; WriteMetadata availableMetaData = writeMetaDataInstruction.getWriteMetadata(); metadata = metadata.or(availableMetaData.getMetadata()); metadataMask = metadataMask.or(availableMetaData.getMetadataMask()); @@ -391,45 +418,40 @@ public class IfmUtil { } public static Integer allocateId(IdManagerService idManager, String poolName, String idKey) { - AllocateIdInput getIdInput = new AllocateIdInputBuilder() - .setPoolName(poolName) - .setIdKey(idKey).build(); + AllocateIdInput getIdInput = new AllocateIdInputBuilder().setPoolName(poolName).setIdKey(idKey).build(); try { Future> result = idManager.allocateId(getIdInput); RpcResult rpcResult = result.get(); - if(rpcResult.isSuccessful()) { + if (rpcResult.isSuccessful()) { return rpcResult.getResult().getIdValue().intValue(); } else { LOG.warn("RPC Call to Get Unique Id returned with Errors {}", rpcResult.getErrors()); } } catch (InterruptedException | ExecutionException e) { - LOG.warn("Exception when getting Unique Id",e); + LOG.warn("Exception when getting Unique Id", e); } return INVALID_ID; } public static void releaseId(IdManagerService idManager, String poolName, String idKey) { - ReleaseIdInput idInput = new ReleaseIdInputBuilder() - .setPoolName(poolName) - .setIdKey(idKey).build(); + ReleaseIdInput idInput = new ReleaseIdInputBuilder().setPoolName(poolName).setIdKey(idKey).build(); try { Future> result = idManager.releaseId(idInput); RpcResult rpcResult = result.get(); - if(!rpcResult.isSuccessful()) { - LOG.warn("RPC Call to release Id {} with Key {} returned with Errors {}", - idKey, rpcResult.getErrors()); + if (!rpcResult.isSuccessful()) { + LOG.warn("RPC Call to release Id {} with Key {} returned with Errors {}", idKey, rpcResult.getErrors()); } } catch (InterruptedException | ExecutionException e) { LOG.warn("Exception when releasing Id for key {}", idKey, e); } } - public static BigInteger getDpnId(DatapathId datapathId){ + public static BigInteger getDpnId(DatapathId datapathId) { if (datapathId != null) { - // Adding logs for a random issue spotted during datapath id conversion + // Adding logs for a random issue spotted during datapath id + // conversion String dpIdStr = datapathId.getValue().replace(":", ""); - BigInteger dpnId = new BigInteger(dpIdStr, 16); - return dpnId; + return new BigInteger(dpIdStr, 16); } return null; } @@ -438,33 +460,37 @@ public class IfmUtil { return FlowBasedServicesUtils.getNodeConnectorIdFromInterface(interfaceName, dataBroker); } - public static String getPortName(DataBroker dataBroker, NodeConnectorId ncId){ - InstanceIdentifier ncIdentifier = - InstanceIdentifier.builder(Nodes.class) - .child(Node.class, new NodeKey(getNodeIdFromNodeConnectorId(ncId))) - .child(NodeConnector.class, new NodeConnectorKey(ncId)).build(); - return read(LogicalDatastoreType.OPERATIONAL, ncIdentifier, dataBroker).transform( - nc -> nc.getAugmentation(FlowCapableNodeConnector.class).getName()).orNull(); - } - - public static NodeConnectorId getNodeConnectorIdFromInterface(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifState){ - if(ifState != null) { + public static NodeConnectorId getNodeConnectorIdFromInterface( + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang + .ietf.interfaces.rev140508.interfaces.state.Interface ifState) { + if (ifState != null) { List ofportIds = ifState.getLowerLayerIf(); return new NodeConnectorId(ofportIds.get(0)); } return null; } + public static String getPortName(DataBroker dataBroker, NodeConnectorId ncId) { + InstanceIdentifier ncIdentifier = InstanceIdentifier.builder(Nodes.class) + .child(Node.class, new NodeKey(getNodeIdFromNodeConnectorId(ncId))) + .child(NodeConnector.class, new NodeConnectorKey(ncId)).build(); + return read(LogicalDatastoreType.OPERATIONAL, ncIdentifier, dataBroker) + .transform(nc -> nc.getAugmentation(FlowCapableNodeConnector.class).getName()).orNull(); + } + public static InterfaceInfo.InterfaceType getInterfaceType(Interface iface) { - InterfaceInfo.InterfaceType interfaceType = org.opendaylight.genius.interfacemanager.globals.InterfaceInfo.InterfaceType.UNKNOWN_INTERFACE; - Class ifType = iface + InterfaceInfo.InterfaceType interfaceType = org.opendaylight + .genius.interfacemanager.globals.InterfaceInfo.InterfaceType.UNKNOWN_INTERFACE; + Class ifType = iface .getType(); if (ifType.isAssignableFrom(L2vlan.class)) { interfaceType = VLAN_INTERFACE; } else if (ifType.isAssignableFrom(Tunnel.class)) { IfTunnel ifTunnel = iface.getAugmentation(IfTunnel.class); - Class tunnelType = ifTunnel + Class tunnelType = ifTunnel .getTunnelInterfaceType(); interfaceType = TUNNEL_TYPE_MAP.get(tunnelType); } @@ -472,14 +498,13 @@ public class IfmUtil { } public static VlanInterfaceInfo getVlanInterfaceInfo(String interfaceName, Interface iface, BigInteger dpId) { - short vlanId = 0; String portName = null; IfL2vlan vlanIface = iface.getAugmentation(IfL2vlan.class); ParentRefs parentRefs = iface.getAugmentation(ParentRefs.class); if (parentRefs != null && parentRefs.getParentInterface() != null) { portName = parentRefs.getParentInterface(); - }else { + } else { LOG.warn("Portname set to null since parentRef is Null"); } VlanInterfaceInfo vlanInterfaceInfo = new VlanInterfaceInfo(dpId, portName, vlanId); @@ -508,58 +533,59 @@ public class IfmUtil { return new BigInteger("FFFF", 16).and(BigInteger.valueOf(portNumber)); } - public static String generateMacAddress(long portNo){ + public static String generateMacAddress(long portNo) { String unformattedMAC = getDeadBeefBytesForMac().or(fillPortNumberToMac(portNo)).toString(16); - return unformattedMAC.replaceAll("(.{2})", "$1"+IfmConstants.MAC_SEPARATOR). - substring(0, IfmConstants.MAC_STRING_LENGTH); + return unformattedMAC.replaceAll("(.{2})", "$1" + IfmConstants.MAC_SEPARATOR).substring(0, + IfmConstants.MAC_STRING_LENGTH); } - public static PhysAddress getPhyAddress(long portNo, FlowCapableNodeConnector flowCapableNodeConnector){ + public static PhysAddress getPhyAddress(long portNo, FlowCapableNodeConnector flowCapableNodeConnector) { String southboundMacAddress = flowCapableNodeConnector.getHardwareAddress().getValue(); - if(IfmConstants.INVALID_MAC.equals(southboundMacAddress)){ - LOG.debug("Invalid MAC Address received for {}, generating MAC Address", flowCapableNodeConnector.getName()); + if (IfmConstants.INVALID_MAC.equals(southboundMacAddress)) { + LOG.debug("Invalid MAC Address received for {}, generating MAC Address", + flowCapableNodeConnector.getName()); southboundMacAddress = generateMacAddress(portNo); } return new PhysAddress(southboundMacAddress); } - public static void updateInterfaceParentRef(WriteTransaction t, String interfaceName, String parentInterface) { + public static void updateInterfaceParentRef(WriteTransaction writeTransaction, String interfaceName, + String parentInterface) { InstanceIdentifier parentRefIdentifier = InstanceIdentifier.builder(Interfaces.class) .child(Interface.class, new InterfaceKey(interfaceName)).augmentation(ParentRefs.class).build(); ParentRefs parentRefs = new ParentRefsBuilder().setParentInterface(parentInterface).build(); - t.merge(LogicalDatastoreType.CONFIGURATION, parentRefIdentifier, parentRefs); - LOG.debug("Updating parentRefInterface for interfaceName {}. interfaceKey {}, with parentRef augmentation pointing to {}", + writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, parentRefIdentifier, parentRefs); + LOG.debug( + "Updating parentRefInterface for interfaceName {}. " + + "interfaceKey {}, with parentRef augmentation pointing to {}", interfaceName, new InterfaceKey(interfaceName), parentInterface); } public static InstanceIdentifier buildBoundServicesIId(short servicePriority, String interfaceName, - Class serviceMode) { + Class serviceMode) { return InstanceIdentifier.builder(ServiceBindings.class) - .child(ServicesInfo.class, new ServicesInfoKey(interfaceName, serviceMode)) - .child(BoundServices.class, new BoundServicesKey(servicePriority)) - .build(); + .child(ServicesInfo.class, new ServicesInfoKey(interfaceName, serviceMode)) + .child(BoundServices.class, new BoundServicesKey(servicePriority)).build(); } - public static void bindService(WriteTransaction t, String interfaceName, BoundServices serviceInfo, - Class serviceMode) { + public static void bindService(WriteTransaction writeTransaction, String interfaceName, BoundServices serviceInfo, + Class serviceMode) { LOG.info("Binding Service {} for : {}", serviceInfo.getServiceName(), interfaceName); - InstanceIdentifier boundServicesInstanceIdentifier = - buildBoundServicesIId(serviceInfo.getServicePriority(), interfaceName, serviceMode); - t.put(LogicalDatastoreType.CONFIGURATION, boundServicesInstanceIdentifier, serviceInfo, true); + InstanceIdentifier boundServicesInstanceIdentifier = buildBoundServicesIId( + serviceInfo.getServicePriority(), interfaceName, serviceMode); + writeTransaction.put(LogicalDatastoreType.CONFIGURATION, boundServicesInstanceIdentifier, serviceInfo, true); } - public static void unbindService(DataBroker dataBroker, String interfaceName, InstanceIdentifier - boundServicesInstanceIdentifier){ + public static void unbindService(DataBroker dataBroker, String interfaceName, + InstanceIdentifier boundServicesInstanceIdentifier) { LOG.info("Unbinding Service from : {}", interfaceName); DataStoreJobCoordinator dataStoreJobCoordinator = DataStoreJobCoordinator.getInstance(); - dataStoreJobCoordinator.enqueueJob(interfaceName, - () -> { - WriteTransaction t = dataBroker.newWriteOnlyTransaction(); - t.delete(LogicalDatastoreType.CONFIGURATION, boundServicesInstanceIdentifier); - List> futures = new ArrayList<>(); - futures.add(t.submit()); - return futures; - } - ); + dataStoreJobCoordinator.enqueueJob(interfaceName, () -> { + WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction(); + writeTransaction.delete(LogicalDatastoreType.CONFIGURATION, boundServicesInstanceIdentifier); + List> futures = new ArrayList<>(); + futures.add(writeTransaction.submit()); + return futures; + }); } } diff --git a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/InterfacemgrProvider.java b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/InterfacemgrProvider.java index 3404be89c..b6000987e 100644 --- a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/InterfacemgrProvider.java +++ b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/InterfacemgrProvider.java @@ -7,10 +7,8 @@ */ package org.opendaylight.genius.interfacemanager; - import com.google.common.util.concurrent.CheckedFuture; import com.google.common.util.concurrent.ListenableFuture; - import java.math.BigInteger; import java.util.ArrayList; import java.util.Collections; @@ -53,10 +51,6 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces. import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.AdminStatus; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress; -import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.ServiceModeBase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.service.bindings.services.info.BoundServices; import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.CreateIdPoolInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.CreateIdPoolInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService; @@ -77,7 +71,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpc import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetPortFromInterfaceInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetPortFromInterfaceInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetPortFromInterfaceOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.OdlInterfaceRpcService; import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.ServiceModeBase; import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.ServiceModeEgress; import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.ServiceModeIngress; @@ -94,9 +87,8 @@ import org.slf4j.LoggerFactory; @Singleton public class InterfacemgrProvider implements AutoCloseable, IInterfaceManager { - private static final Logger LOG = LoggerFactory.getLogger(InterfacemgrProvider.class); - private static final InterfaceStatusMonitor interfaceStatusMonitor = InterfaceStatusMonitor.getInstance(); + private static final InterfaceStatusMonitor INTERFACE_STATUS_MONITOR = InterfaceStatusMonitor.getInstance(); private final DataBroker dataBroker; private final IdManagerService idManager; private final InterfaceManagerRpcService interfaceManagerRpcService; @@ -107,8 +99,7 @@ public class InterfacemgrProvider implements AutoCloseable, IInterfaceManager { @Inject public InterfacemgrProvider(final DataBroker dataBroker, final EntityOwnershipService entityOwnershipService, - final IdManagerService idManager, - final InterfaceManagerRpcService interfaceManagerRpcService){ + final IdManagerService idManager, final InterfaceManagerRpcService interfaceManagerRpcService) { this.dataBroker = dataBroker; this.entityOwnershipService = entityOwnershipService; this.idManager = idManager; @@ -117,19 +108,19 @@ public class InterfacemgrProvider implements AutoCloseable, IInterfaceManager { @PostConstruct @SuppressWarnings("checkstyle:IllegalCatch") - public void start() throws Exception { + public void start() { try { - interfaceStatusMonitor.registerMbean(); + INTERFACE_STATUS_MONITOR.registerMbean(); createIdPool(); IfmClusterUtils.registerEntityForOwnership(this, this.entityOwnershipService); - BatchingUtils.registerWithBatchManager( this.dataBroker); + BatchingUtils.registerWithBatchManager(this.dataBroker); this.ifaceToTpMap = new ConcurrentHashMap<>(); this.ifaceToNodeIidMap = new ConcurrentHashMap<>(); this.nodeIidToBridgeMap = new ConcurrentHashMap<>(); - interfaceStatusMonitor.reportStatus("OPERATIONAL"); + INTERFACE_STATUS_MONITOR.reportStatus("OPERATIONAL"); } catch (Exception e) { - interfaceStatusMonitor.reportStatus("ERROR"); + INTERFACE_STATUS_MONITOR.reportStatus("ERROR"); throw e; } LOG.info("InterfacemgrProvider Started"); @@ -145,17 +136,14 @@ public class InterfacemgrProvider implements AutoCloseable, IInterfaceManager { return entityOwnershipService; } - public DataBroker getDataBroker(){ + public DataBroker getDataBroker() { return this.dataBroker; } private void createIdPool() { - CreateIdPoolInput createPool = new CreateIdPoolInputBuilder() - .setPoolName(IfmConstants.IFM_IDPOOL_NAME) - .setLow(IfmConstants.IFM_ID_POOL_START) - .setHigh(IfmConstants.IFM_ID_POOL_END) - .build(); - //TODO: Error handling + CreateIdPoolInput createPool = new CreateIdPoolInputBuilder().setPoolName(IfmConstants.IFM_IDPOOL_NAME) + .setLow(IfmConstants.IFM_ID_POOL_START).setHigh(IfmConstants.IFM_ID_POOL_END).build(); + // TODO: Error handling Future> result = idManager.createIdPool(createPool); try { if (result != null && result.get().isSuccessful()) { @@ -199,16 +187,17 @@ public class InterfacemgrProvider implements AutoCloseable, IInterfaceManager { @Override public InterfaceInfo getInterfaceInfo(String interfaceName) { - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface - ifState = InterfaceManagerCommonUtils.getInterfaceStateFromOperDS(interfaceName, dataBroker); + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang + .ietf.interfaces.rev140508.interfaces.state.Interface ifState = InterfaceManagerCommonUtils + .getInterfaceStateFromOperDS(interfaceName, dataBroker); if (ifState == null) { LOG.error("Interface {} is not present", interfaceName); return null; } - Integer lportTag = ifState.getIfIndex(); - Interface intf = InterfaceManagerCommonUtils.getInterfaceFromConfigDS(new InterfaceKey(interfaceName), dataBroker); + Interface intf = InterfaceManagerCommonUtils.getInterfaceFromConfigDS(new InterfaceKey(interfaceName), + dataBroker); if (intf == null) { LOG.error("Interface {} doesn't exist in config datastore", interfaceName); return null; @@ -225,32 +214,29 @@ public class InterfacemgrProvider implements AutoCloseable, IInterfaceManager { } if (interfaceType == InterfaceInfo.InterfaceType.VLAN_INTERFACE) { interfaceInfo = IfmUtil.getVlanInterfaceInfo(interfaceName, intf, dpId); - } else if (interfaceType == InterfaceInfo.InterfaceType.VXLAN_TRUNK_INTERFACE || - interfaceType == InterfaceInfo.InterfaceType.GRE_TRUNK_INTERFACE) { - // TODO : since there is no logical grouping for tunnel interfaces, there is no need + } else if (interfaceType == InterfaceInfo.InterfaceType.VXLAN_TRUNK_INTERFACE + || interfaceType == InterfaceInfo.InterfaceType.GRE_TRUNK_INTERFACE) { + // TODO : since there is no logical grouping for tunnel interfaces, + // there is no need // for this code as of now. will be revisited once the support comes } else { LOG.error("Type of Interface {} is unknown", interfaceName); return null; } - InterfaceInfo.InterfaceOpState opState ; - if(ifState.getOperStatus() == OperStatus.Up) - { + InterfaceInfo.InterfaceOpState opState; + if (ifState.getOperStatus() == OperStatus.Up) { opState = InterfaceInfo.InterfaceOpState.UP; - } - else if (ifState.getOperStatus() == OperStatus.Down) - { + } else if (ifState.getOperStatus() == OperStatus.Down) { opState = InterfaceInfo.InterfaceOpState.DOWN; - } - else - { + } else { opState = InterfaceInfo.InterfaceOpState.UNKNOWN; } interfaceInfo.setDpId(dpId); interfaceInfo.setPortNo(portNo); interfaceInfo.setAdminState(intf.isEnabled() ? InterfaceAdminState.ENABLED : InterfaceAdminState.DISABLED); interfaceInfo.setInterfaceName(interfaceName); + Integer lportTag = ifState.getIfIndex(); interfaceInfo.setInterfaceTag(lportTag); interfaceInfo.setInterfaceType(interfaceType); interfaceInfo.setGroupId(IfmUtil.getGroupId(lportTag, interfaceType)); @@ -265,35 +251,34 @@ public class InterfacemgrProvider implements AutoCloseable, IInterfaceManager { } @Override - public InterfaceInfo getInterfaceInfoFromOperationalDataStore(String interfaceName, InterfaceInfo.InterfaceType interfaceType) { + public InterfaceInfo getInterfaceInfoFromOperationalDataStore(String interfaceName, + InterfaceInfo.InterfaceType interfaceType) { InterfaceInfo interfaceInfo = new InterfaceInfo(interfaceName); - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifState = InterfaceManagerCommonUtils + org.opendaylight.yang.gen.v1.urn + .ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifState = + InterfaceManagerCommonUtils .getInterfaceStateFromOperDS(interfaceName, dataBroker); if (ifState == null) { LOG.error("Interface {} is not present", interfaceName); return null; } - Integer lportTag = ifState.getIfIndex(); NodeConnectorId ncId = IfmUtil.getNodeConnectorIdFromInterface(ifState); if (ncId != null) { interfaceInfo.setDpId(IfmUtil.getDpnFromNodeConnectorId(ncId)); interfaceInfo.setPortNo(Integer.parseInt(IfmUtil.getPortNoFromNodeConnectorId(ncId))); } - InterfaceInfo.InterfaceOpState opState ; - if(ifState.getOperStatus() == OperStatus.Up) - { + InterfaceInfo.InterfaceOpState opState; + if (ifState.getOperStatus() == OperStatus.Up) { opState = InterfaceInfo.InterfaceOpState.UP; - } - else if (ifState.getOperStatus() == OperStatus.Down) - { + } else if (ifState.getOperStatus() == OperStatus.Down) { opState = InterfaceInfo.InterfaceOpState.DOWN; - } - else - { + } else { opState = InterfaceInfo.InterfaceOpState.UNKNOWN; } - interfaceInfo.setAdminState(ifState.getAdminStatus() == AdminStatus.Up ? InterfaceAdminState.ENABLED : InterfaceAdminState.DISABLED); + interfaceInfo.setAdminState(ifState.getAdminStatus() == AdminStatus.Up ? InterfaceAdminState.ENABLED + : InterfaceAdminState.DISABLED); interfaceInfo.setInterfaceName(interfaceName); + Integer lportTag = ifState.getIfIndex(); interfaceInfo.setInterfaceTag(lportTag); interfaceInfo.setInterfaceType(interfaceType); interfaceInfo.setGroupId(IfmUtil.getGroupId(lportTag, interfaceType)); @@ -302,14 +287,14 @@ public class InterfacemgrProvider implements AutoCloseable, IInterfaceManager { if (phyAddress != null) { interfaceInfo.setMacAddress(ifState.getPhysAddress().getValue()); } - return interfaceInfo; } @Override public InterfaceInfo getInterfaceInfoFromOperationalDataStore(String interfaceName) { - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface - ifState = InterfaceManagerCommonUtils.getInterfaceStateFromOperDS(interfaceName, dataBroker); + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang + .ietf.interfaces.rev140508.interfaces.state.Interface ifState = InterfaceManagerCommonUtils + .getInterfaceStateFromOperDS(interfaceName, dataBroker); if (ifState == null) { LOG.error("Interface {} is not present", interfaceName); return null; @@ -318,10 +303,9 @@ public class InterfacemgrProvider implements AutoCloseable, IInterfaceManager { return populateInterfaceInfo(interfaceName, ifState); } - - public InterfaceInfo populateInterfaceInfo(String interfaceName, org.opendaylight.yang.gen.v1.urn.ietf.params.xml - .ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifState) { - Integer lportTag = ifState.getIfIndex(); + public InterfaceInfo populateInterfaceInfo(String interfaceName, + org.opendaylight.yang.gen.v1.urn + .ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifState) { InterfaceInfo interfaceInfo = new InterfaceInfo(interfaceName); NodeConnectorId ncId = IfmUtil.getNodeConnectorIdFromInterface(ifState); if (ncId != null) { @@ -335,7 +319,7 @@ public class InterfacemgrProvider implements AutoCloseable, IInterfaceManager { interfaceInfo.setDpId(IfmUtil.getDpnFromNodeConnectorId(ncId)); interfaceInfo.setPortNo(Integer.parseInt(IfmUtil.getPortNoFromNodeConnectorId(ncId))); } - InterfaceInfo.InterfaceOpState opState ; + InterfaceInfo.InterfaceOpState opState; if (ifState.getOperStatus() == OperStatus.Up) { opState = InterfaceInfo.InterfaceOpState.UP; } else if (ifState.getOperStatus() == OperStatus.Down) { @@ -344,8 +328,9 @@ public class InterfacemgrProvider implements AutoCloseable, IInterfaceManager { opState = InterfaceInfo.InterfaceOpState.UNKNOWN; } interfaceInfo.setAdminState(ifState.getAdminStatus() == AdminStatus.Up ? InterfaceAdminState.ENABLED - : InterfaceAdminState.DISABLED); + : InterfaceAdminState.DISABLED); interfaceInfo.setInterfaceName(interfaceName); + Integer lportTag = ifState.getIfIndex(); if (lportTag != null) { interfaceInfo.setInterfaceTag(lportTag); } @@ -357,11 +342,11 @@ public class InterfacemgrProvider implements AutoCloseable, IInterfaceManager { return interfaceInfo; } - @Override public InterfaceInfo getInterfaceInfoFromOperationalDSCache(String interfaceName) { - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface - ifState = InterfaceManagerCommonUtils.getInterfaceStateFromCache(interfaceName); + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang + .ietf.interfaces.rev140508.interfaces.state.Interface ifState = InterfaceManagerCommonUtils + .getInterfaceStateFromCache(interfaceName); if (ifState == null) { LOG.warn("Interface {} is not present", interfaceName); return null; @@ -371,22 +356,25 @@ public class InterfacemgrProvider implements AutoCloseable, IInterfaceManager { @Override public Interface getInterfaceInfoFromConfigDataStore(String interfaceName) { - Interface intf = InterfaceManagerCommonUtils.getInterfaceFromConfigDS(new InterfaceKey(interfaceName), dataBroker); + Interface intf = InterfaceManagerCommonUtils.getInterfaceFromConfigDS(new InterfaceKey(interfaceName), + dataBroker); return intf; } @Override public void createVLANInterface(String interfaceName, String portName, BigInteger dpId, Integer vlanId, - String description, IfL2vlan.L2vlanMode l2vlanMode) throws InterfaceAlreadyExistsException { + String description, IfL2vlan.L2vlanMode l2vlanMode) throws InterfaceAlreadyExistsException { createVLANInterface(interfaceName, portName, dpId, vlanId, description, l2vlanMode, false); } + @Override public void createVLANInterface(String interfaceName, String portName, BigInteger dpId, Integer vlanId, - String description, IfL2vlan.L2vlanMode l2vlanMode, boolean isExternal) throws InterfaceAlreadyExistsException { + String description, IfL2vlan.L2vlanMode l2vlanMode, boolean isExternal) + throws InterfaceAlreadyExistsException { LOG.info("Create VLAN interface : {}", interfaceName); - InstanceIdentifier interfaceInstanceIdentifier = InterfaceManagerCommonUtils.getInterfaceIdentifier(new InterfaceKey(interfaceName)); - Interface interfaceOptional = InterfaceManagerCommonUtils.getInterfaceFromConfigDS(new InterfaceKey(interfaceName), dataBroker); + Interface interfaceOptional = InterfaceManagerCommonUtils + .getInterfaceFromConfigDS(new InterfaceKey(interfaceName), dataBroker); if (interfaceOptional != null) { LOG.debug("VLAN interface is already exist", interfaceOptional.getDescription()); throw new InterfaceAlreadyExistsException(interfaceOptional.getName()); @@ -396,25 +384,27 @@ public class InterfacemgrProvider implements AutoCloseable, IInterfaceManager { l2vlanBuilder.setVlanId(new VlanId(vlanId)); } ParentRefs parentRefs = new ParentRefsBuilder().setParentInterface(portName).build(); - InterfaceBuilder interfaceBuilder = new InterfaceBuilder().setEnabled(true).setName(interfaceName).setType(L2vlan.class). - addAugmentation(IfL2vlan.class, l2vlanBuilder.build()).addAugmentation(ParentRefs.class, parentRefs). - setDescription(description); + InterfaceBuilder interfaceBuilder = new InterfaceBuilder().setEnabled(true).setName(interfaceName) + .setType(L2vlan.class).addAugmentation(IfL2vlan.class, l2vlanBuilder.build()) + .addAugmentation(ParentRefs.class, parentRefs).setDescription(description); if (isExternal) { interfaceBuilder.addAugmentation(IfExternal.class, new IfExternalBuilder().setExternal(true).build()); } - WriteTransaction t = dataBroker.newWriteOnlyTransaction(); - t.put(LogicalDatastoreType.CONFIGURATION, interfaceInstanceIdentifier, interfaceBuilder.build(), true); - t.submit(); + InstanceIdentifier interfaceInstanceIdentifier = InterfaceManagerCommonUtils + .getInterfaceIdentifier(new InterfaceKey(interfaceName)); + WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction(); + writeTransaction.put(LogicalDatastoreType.CONFIGURATION, interfaceInstanceIdentifier, interfaceBuilder.build(), + true); + writeTransaction.submit(); } private boolean isServiceBoundOnInterface(short servicePriority, String interfaceName, - Class serviceMode) { - InstanceIdentifier boundServicesIId = - IfmUtil.buildBoundServicesIId(servicePriority, interfaceName, serviceMode); + Class serviceMode) { + InstanceIdentifier boundServicesIId = IfmUtil.buildBoundServicesIId(servicePriority, + interfaceName, serviceMode); try { - return SingleTransactionDataBroker.syncReadOptional(dataBroker, - LogicalDatastoreType.CONFIGURATION, boundServicesIId) - .isPresent(); + return SingleTransactionDataBroker + .syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, boundServicesIId).isPresent(); } catch (ReadFailedException e) { LOG.warn("Error while reading [{}]", boundServicesIId, e); return false; @@ -433,26 +423,32 @@ public class InterfacemgrProvider implements AutoCloseable, IInterfaceManager { @Override public void bindService(String interfaceName, Class serviceMode, - BoundServices serviceInfo) { - bindService(interfaceName, serviceMode, serviceInfo, /*WriteTransaction*/ null); + BoundServices serviceInfo) { + bindService(interfaceName, serviceMode, serviceInfo, /* WriteTransaction */ null); } @Override public void bindService(String interfaceName, Class serviceMode, - BoundServices serviceInfo, WriteTransaction tx) { - WriteTransaction t = tx != null ? tx : dataBroker.newWriteOnlyTransaction(); - IfmUtil.bindService(t, interfaceName, serviceInfo, serviceMode); + BoundServices serviceInfo, WriteTransaction tx) { + WriteTransaction writeTransaction = tx != null ? tx : dataBroker.newWriteOnlyTransaction(); + IfmUtil.bindService(writeTransaction, interfaceName, serviceInfo, serviceMode); if (tx == null) { - t.submit(); + writeTransaction.submit(); } } @Override - public void unbindService(String interfaceName, Class serviceMode, BoundServices serviceInfo) { + public void unbindService(String interfaceName, Class serviceMode, + BoundServices serviceInfo) { IfmUtil.unbindService(dataBroker, interfaceName, FlowBasedServicesUtils.buildServiceId(interfaceName, serviceInfo.getServicePriority(), serviceMode)); } + @Override + public BigInteger getDpnForInterface(Interface intrf) { + return getDpnForInterface(intrf.getName()); + } + @Override public BigInteger getDpnForInterface(String ifName) { GetDpidFromInterfaceInput input = new GetDpidFromInterfaceInputBuilder().setIntfName(ifName).build(); @@ -491,11 +487,6 @@ public class InterfacemgrProvider implements AutoCloseable, IInterfaceManager { return IfmUtil.getEgressActionInfosForInterface(ifName, 0, dataBroker, false); } - @Override - public BigInteger getDpnForInterface(Interface intrf) { - return getDpnForInterface(intrf.getName()); - } - @Override public List getVlanInterfaces() { return InterfaceManagerCommonUtils.getAllVlanInterfacesFromCache(); @@ -573,31 +564,32 @@ public class InterfacemgrProvider implements AutoCloseable, IInterfaceManager { } public void removeTerminationPointForInterface(String interfaceName) { - if(interfaceName != null) { + if (interfaceName != null) { ifaceToTpMap.remove(interfaceName); } } public void addNodeIidForInterface(String interfaceName, InstanceIdentifier nodeIid) { - if(interfaceName != null && nodeIid != null) { - ifaceToNodeIidMap.put(interfaceName, nodeIid); + if (interfaceName != null && nodeIid != null) { + ifaceToNodeIidMap.put(interfaceName, nodeIid); } } public void removeNodeIidForInterface(String interfaceName) { - if(interfaceName != null) { + if (interfaceName != null) { ifaceToNodeIidMap.remove(interfaceName); } } public InstanceIdentifier getNodeIidForInterface(String interfaceName) { - if(interfaceName != null) { + if (interfaceName != null) { return ifaceToNodeIidMap.get(interfaceName); } return null; } - private OvsdbBridgeAugmentation getBridgeForInterface(String interfaceName, InstanceIdentifier nodeInstanceId) { + private OvsdbBridgeAugmentation getBridgeForInterface(String interfaceName, + InstanceIdentifier nodeInstanceId) { InstanceIdentifier nodeIid = nodeInstanceId; if (nodeIid == null) { nodeIid = getNodeIidForInterface(interfaceName); @@ -620,20 +612,20 @@ public class InterfacemgrProvider implements AutoCloseable, IInterfaceManager { return null; } - public void addBridgeForNodeIid(InstanceIdentifiernodeIid, OvsdbBridgeAugmentation bridge) { + public void addBridgeForNodeIid(InstanceIdentifier nodeIid, OvsdbBridgeAugmentation bridge) { if (nodeIid != null && bridge != null) { nodeIidToBridgeMap.put(nodeIid, bridge); } } - public void removeBridgeForNodeIid(InstanceIdentifiernodeIid) { + public void removeBridgeForNodeIid(InstanceIdentifier nodeIid) { if (nodeIid != null) { nodeIidToBridgeMap.remove(nodeIid); } } - public OvsdbBridgeAugmentation getBridgeForNodeIid(InstanceIdentifiernodeIid) { - if(nodeIid != null) { + public OvsdbBridgeAugmentation getBridgeForNodeIid(InstanceIdentifier nodeIid) { + if (nodeIid != null) { return nodeIidToBridgeMap.get(nodeIid); } return null; @@ -663,20 +655,23 @@ public class InterfacemgrProvider implements AutoCloseable, IInterfaceManager { @Override public void updateInterfaceParentRef(String interfaceName, String parentInterface) { - // This should generally be called by EOS Owner for INTERFACE_CONFIG_ENTITY - runOnlyInLeaderNode() + // This should generally be called by EOS Owner for + // INTERFACE_CONFIG_ENTITY - runOnlyInLeaderNode() updateInterfaceParentRef(interfaceName, parentInterface, true); } @Override - public void updateInterfaceParentRef(String interfaceName, String parentInterface, boolean readInterfaceBeforeWrite) { - // This should generally be called by EOS Owner for INTERFACE_CONFIG_ENTITY - runOnlyInLeaderNode() + public void updateInterfaceParentRef(String interfaceName, String parentInterface, + boolean readInterfaceBeforeWrite) { + // This should generally be called by EOS Owner for + // INTERFACE_CONFIG_ENTITY - runOnlyInLeaderNode() if (interfaceName == null) { return; } DataStoreJobCoordinator jobCoordinator = DataStoreJobCoordinator.getInstance(); - ParentRefUpdateWorker parentRefUpdateWorker = - new ParentRefUpdateWorker(interfaceName, parentInterface, readInterfaceBeforeWrite); + ParentRefUpdateWorker parentRefUpdateWorker = new ParentRefUpdateWorker(interfaceName, parentInterface, + readInterfaceBeforeWrite); jobCoordinator.enqueueJob(interfaceName, parentRefUpdateWorker, IfmConstants.JOB_MAX_RETRIES); } @@ -685,7 +680,8 @@ public class InterfacemgrProvider implements AutoCloseable, IInterfaceManager { String parentInterfaceName; Boolean readInterfaceBeforeWrite; - public ParentRefUpdateWorker(String interfaceName, String parentInterfaceName, boolean readInterfaceBeforeWrite) { + public ParentRefUpdateWorker(String interfaceName, String parentInterfaceName, + boolean readInterfaceBeforeWrite) { this.interfaceName = interfaceName; this.parentInterfaceName = parentInterfaceName; this.readInterfaceBeforeWrite = readInterfaceBeforeWrite; @@ -700,13 +696,12 @@ public class InterfacemgrProvider implements AutoCloseable, IInterfaceManager { return null; } } - WriteTransaction t = dataBroker.newWriteOnlyTransaction(); - IfmUtil.updateInterfaceParentRef(t, interfaceName, parentInterfaceName); - CheckedFuture submitFuture = t.submit(); + WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction(); + IfmUtil.updateInterfaceParentRef(writeTransaction, interfaceName, parentInterfaceName); + CheckedFuture submitFuture = writeTransaction.submit(); List> futures = new ArrayList<>(); futures.add(submitFuture); return futures; } } - } diff --git a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/commons/InterfaceManagerCommonUtils.java b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/commons/InterfaceManagerCommonUtils.java index 22b84abf0..36497cf07 100644 --- a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/commons/InterfaceManagerCommonUtils.java +++ b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/commons/InterfaceManagerCommonUtils.java @@ -152,8 +152,11 @@ public final class InterfaceManagerCommonUtils { /** * Searches for an interface by its name. - * @param interfaceName name of the interface to search for - * @param dataBroker data tree store to start searching for the interface + * + * @param interfaceName + * name of the interface to search for + * @param dataBroker + * data tree store to start searching for the interface * @return the Interface object */ public static Interface getInterfaceFromConfigDS(String interfaceName, DataBroker dataBroker) { @@ -448,8 +451,7 @@ public final class InterfaceManagerCommonUtils { // Update the DpnToInterfaceList OpDS createOrUpdateDpnToInterface(dpId, interfaceName, transaction); return ifState; -} - + } public static boolean checkIfBfdStateIsDown(String interfaceName) { org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang diff --git a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/listeners/InterfaceStateListener.java b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/listeners/InterfaceStateListener.java index 717e92116..c89ef45b1 100644 --- a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/listeners/InterfaceStateListener.java +++ b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/listeners/InterfaceStateListener.java @@ -10,6 +10,8 @@ package org.opendaylight.genius.interfacemanager.listeners; import com.google.common.util.concurrent.ListenableFuture; import java.util.ArrayList; import java.util.List; +import javax.inject.Inject; +import javax.inject.Singleton; import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; @@ -24,9 +26,6 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.inject.Inject; -import javax.inject.Singleton; - @Singleton public class InterfaceStateListener extends AsyncClusteredDataTreeChangeListenerBase { diff --git a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/listeners/InterfaceTopologyStateListener.java b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/listeners/InterfaceTopologyStateListener.java index 3b35c62d6..e45b47613 100644 --- a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/listeners/InterfaceTopologyStateListener.java +++ b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/listeners/InterfaceTopologyStateListener.java @@ -32,7 +32,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; @Singleton -public class InterfaceTopologyStateListener extends AsyncClusteredDataTreeChangeListenerBase { +public class InterfaceTopologyStateListener + extends AsyncClusteredDataTreeChangeListenerBase { private static final Logger LOG = LoggerFactory.getLogger(InterfaceTopologyStateListener.class); private final DataBroker dataBroker; private final InterfacemgrProvider interfaceMgrProvider; @@ -86,16 +87,17 @@ public class InterfaceTopologyStateListener extends AsyncClusteredDataTreeChange IfmClusterUtils.runOnlyInLeaderNode(() -> { DatapathId oldDpid = bridgeOld.getDatapathId(); DatapathId newDpid = bridgeNew.getDatapathId(); - if(oldDpid == null && newDpid != null){ + if (oldDpid == null && newDpid != null) { DataStoreJobCoordinator jobCoordinator = DataStoreJobCoordinator.getInstance(); RendererStateAddWorker rendererStateAddWorker = new RendererStateAddWorker(identifier, bridgeNew); jobCoordinator.enqueueJob(bridgeNew.getBridgeName().getValue(), rendererStateAddWorker, - IfmConstants.JOB_MAX_RETRIES); - } else if(oldDpid != null && !oldDpid.equals(newDpid)){ + IfmConstants.JOB_MAX_RETRIES); + } else if (oldDpid != null && !oldDpid.equals(newDpid)) { DataStoreJobCoordinator jobCoordinator = DataStoreJobCoordinator.getInstance(); - RendererStateUpdateWorker rendererStateAddWorker = new RendererStateUpdateWorker(identifier, bridgeNew, bridgeOld); + RendererStateUpdateWorker rendererStateAddWorker = new RendererStateUpdateWorker(identifier, bridgeNew, + bridgeOld); jobCoordinator.enqueueJob(bridgeNew.getBridgeName().getValue(), rendererStateAddWorker, - IfmConstants.JOB_MAX_RETRIES); + IfmConstants.JOB_MAX_RETRIES); } }, IfmClusterUtils.INTERFACE_CONFIG_ENTITY); } diff --git a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/listeners/TerminationPointStateListener.java b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/listeners/TerminationPointStateListener.java index b0a4ce52c..92dbcc523 100644 --- a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/listeners/TerminationPointStateListener.java +++ b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/listeners/TerminationPointStateListener.java @@ -94,13 +94,13 @@ public class TerminationPointStateListener extends } String dpnId = interfaceMgrProvider.getDpidForInterface(newInterfaceName, identifier.firstIdentifierOf(Node.class)); - if (dpnId != null && newInterfaceName != null && - (oldInterfaceName == null || !oldInterfaceName.equals(newInterfaceName))) { + if (dpnId != null && newInterfaceName != null + && (oldInterfaceName == null || !oldInterfaceName.equals(newInterfaceName))) { String parentRefName = InterfaceManagerCommonUtils.getPortNameForInterface(dpnId, tpNew.getName()); LOG.debug( - "Detected update to termination point {} with external ID {}, updating parent ref " - + "of that interface ID to this termination point's interface-state name {}", - tpNew.getName(), newInterfaceName, parentRefName); + "Detected update to termination point {} with external ID {}, updating parent ref " + + "of that interface ID to this termination point's interface-state name {}", + tpNew.getName(), newInterfaceName, parentRefName); interfaceMgrProvider.updateInterfaceParentRef(newInterfaceName, parentRefName); } } diff --git a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/listeners/VlanMemberConfigListener.java b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/listeners/VlanMemberConfigListener.java index 0f18405b7..bb43b446c 100644 --- a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/listeners/VlanMemberConfigListener.java +++ b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/listeners/VlanMemberConfigListener.java @@ -41,11 +41,11 @@ public class VlanMemberConfigListener extends AsyncDataTreeChangeListenerBase> getDpidFromInterface(GetDpidFromInterfaceInput input) { String interfaceName = input.getIntfName(); RpcResultBuilder rpcResultBuilder; try { - BigInteger dpId = null; + BigInteger dpId; InterfaceKey interfaceKey = new InterfaceKey(interfaceName); Interface interfaceInfo = InterfaceManagerCommonUtils.getInterfaceFromConfigDS(interfaceKey, dataBroker); if (interfaceInfo == null) { @@ -93,9 +123,9 @@ public class InterfaceManagerRpcService implements OdlInterfaceRpcService { ParentRefs parentRefs = interfaceInfo.getAugmentation(ParentRefs.class); dpId = parentRefs.getDatapathNodeIdentifier(); } else { - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state - .Interface ifState - = InterfaceManagerCommonUtils.getInterfaceStateFromOperDS(interfaceName, dataBroker); + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang + .ietf.interfaces.rev140508.interfaces.state.Interface ifState = InterfaceManagerCommonUtils + .getInterfaceStateFromOperDS(interfaceName, dataBroker); if (ifState != null) { String lowerLayerIf = ifState.getLowerLayerIf().get(0); NodeConnectorId nodeConnectorId = new NodeConnectorId(lowerLayerIf); @@ -124,6 +154,7 @@ public class InterfaceManagerRpcService implements OdlInterfaceRpcService { } @Override + @SuppressWarnings("checkstyle:IllegalCatch") public Future> getEndpointIpForDpn(GetEndpointIpForDpnInput input) { RpcResultBuilder rpcResultBuilder; try { @@ -138,6 +169,7 @@ public class InterfaceManagerRpcService implements OdlInterfaceRpcService { InterfaceKey interfaceKey = new InterfaceKey(bridgeInterfaceEntry.getInterfaceName()); Interface interfaceInfo = InterfaceManagerCommonUtils.getInterfaceFromConfigDS(interfaceKey, dataBroker); IfTunnel tunnel = interfaceInfo.getAugmentation(IfTunnel.class); + GetEndpointIpForDpnOutputBuilder endpointIpForDpnOutput = new GetEndpointIpForDpnOutputBuilder() .setLocalIps(Collections.singletonList(tunnel.getTunnelSource())); rpcResultBuilder = RpcResultBuilder.success(); @@ -150,6 +182,7 @@ public class InterfaceManagerRpcService implements OdlInterfaceRpcService { } @Override + @SuppressWarnings("checkstyle:IllegalCatch") public Future> getEgressInstructionsForInterface( GetEgressInstructionsForInterfaceInput input) { RpcResultBuilder rpcResultBuilder; @@ -161,16 +194,17 @@ public class InterfaceManagerRpcService implements OdlInterfaceRpcService { rpcResultBuilder = RpcResultBuilder.success(); rpcResultBuilder.withResult(output.build()); } catch (Exception e) { - String errMsg = String.format("Retrieval of egress instructions for the key {%s} failed due to %s", input.getIntfName(), - e.getMessage()); + String errMsg = String.format("Retrieval of egress instructions for the key {%s} failed due to %s", + input.getIntfName(), e.getMessage()); LOG.debug(errMsg); - rpcResultBuilder = RpcResultBuilder - .failed().withError(RpcError.ErrorType.APPLICATION, errMsg); + rpcResultBuilder = RpcResultBuilder.failed() + .withError(RpcError.ErrorType.APPLICATION, errMsg); } return Futures.immediateFuture(rpcResultBuilder.build()); } @Override + @SuppressWarnings("checkstyle:IllegalCatch") public Future> getInterfaceType(GetInterfaceTypeInput input) { String interfaceName = input.getIntfName(); RpcResultBuilder rpcResultBuilder; @@ -197,6 +231,7 @@ public class InterfaceManagerRpcService implements OdlInterfaceRpcService { } @Override + @SuppressWarnings("checkstyle:IllegalCatch") public Future> getTunnelType(GetTunnelTypeInput input) { String interfaceName = input.getIntfName(); RpcResultBuilder rpcResultBuilder; @@ -230,6 +265,7 @@ public class InterfaceManagerRpcService implements OdlInterfaceRpcService { } @Override + @SuppressWarnings("checkstyle:IllegalCatch") public Future> getEgressActionsForInterface( GetEgressActionsForInterfaceInput input) { RpcResultBuilder rpcResultBuilder; @@ -243,24 +279,25 @@ public class InterfaceManagerRpcService implements OdlInterfaceRpcService { rpcResultBuilder.withResult(output.build()); } catch (Exception e) { String errMsg = String.format("Retrieval of egress actions for {%s} failed due to %s", input.getIntfName(), - e.getMessage()); + e.getMessage()); LOG.debug(errMsg); - rpcResultBuilder = RpcResultBuilder - .failed().withError(RpcError.ErrorType.APPLICATION, errMsg); + rpcResultBuilder = RpcResultBuilder.failed() + .withError(RpcError.ErrorType.APPLICATION, errMsg); } return Futures.immediateFuture(rpcResultBuilder.build()); } @Override + @SuppressWarnings("checkstyle:IllegalCatch") public Future> getPortFromInterface(GetPortFromInterfaceInput input) { RpcResultBuilder rpcResultBuilder; String interfaceName = input.getIntfName(); try { BigInteger dpId = null; long portNo = 0; - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state - .Interface ifState = InterfaceManagerCommonUtils.getInterfaceStateFromOperDS(interfaceName, - dataBroker); + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang + .ietf.interfaces.rev140508.interfaces.state.Interface ifState = InterfaceManagerCommonUtils + .getInterfaceStateFromOperDS(interfaceName, dataBroker); if (ifState != null) { String lowerLayerIf = ifState.getLowerLayerIf().get(0); NodeConnectorId nodeConnectorId = new NodeConnectorId(lowerLayerIf); @@ -291,13 +328,15 @@ public class InterfaceManagerRpcService implements OdlInterfaceRpcService { } @Override + @SuppressWarnings("checkstyle:IllegalCatch") public Future> getNodeconnectorIdFromInterface( GetNodeconnectorIdFromInterfaceInput input) { String interfaceName = input.getIntfName(); RpcResultBuilder rpcResultBuilder; try { - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state - .Interface ifState = InterfaceManagerCommonUtils.getInterfaceStateFromOperDS(interfaceName, dataBroker); + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang + .ietf.interfaces.rev140508.interfaces.state.Interface ifState = InterfaceManagerCommonUtils + .getInterfaceStateFromOperDS(interfaceName, dataBroker); String lowerLayerIf = ifState.getLowerLayerIf().get(0); NodeConnectorId nodeConnectorId = new NodeConnectorId(lowerLayerIf); @@ -313,6 +352,7 @@ public class InterfaceManagerRpcService implements OdlInterfaceRpcService { } @Override + @SuppressWarnings("checkstyle:IllegalCatch") public Future> getInterfaceFromIfIndex( GetInterfaceFromIfIndexInput input) { Integer ifIndex = input.getIfIndex(); @@ -337,6 +377,7 @@ public class InterfaceManagerRpcService implements OdlInterfaceRpcService { } @Override + @SuppressWarnings("checkstyle:IllegalCatch") public Future> getDpnInterfaceList(GetDpnInterfaceListInput input) { BigInteger dpnid = input.getDpid(); RpcResultBuilder rpcResultBuilder = null; @@ -373,7 +414,6 @@ public class InterfaceManagerRpcService implements OdlInterfaceRpcService { } return instructions; } - return null; } diff --git a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/config/factory/FlowBasedEgressServicesRendererFactory.java b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/config/factory/FlowBasedEgressServicesRendererFactory.java index 2e1ca671e..87054d73c 100644 --- a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/config/factory/FlowBasedEgressServicesRendererFactory.java +++ b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/config/factory/FlowBasedEgressServicesRendererFactory.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * Copyright (c) 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, @@ -12,8 +12,8 @@ import org.opendaylight.genius.interfacemanager.servicebindings.flowbased.config public class FlowBasedEgressServicesRendererFactory extends FlowBasedServicesRendererFactory { - private static final FlowBasedEgressServicesRendererFactory EGRESS_SERVICES_RENDERER_FACTORY - = new FlowBasedEgressServicesRendererFactory(); + private static final FlowBasedEgressServicesRendererFactory + EGRESS_SERVICES_RENDERER_FACTORY = new FlowBasedEgressServicesRendererFactory(); @Override public FlowBasedServicesConfigAddable getFlowBasedServicesAddRenderer() { @@ -28,5 +28,4 @@ public class FlowBasedEgressServicesRendererFactory extends FlowBasedServicesRen public static FlowBasedServicesRendererFactory getFlowBasedServicesRendererFactory() { return EGRESS_SERVICES_RENDERER_FACTORY; } - } diff --git a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/config/helpers/FlowBasedEgressServicesConfigBindHelper.java b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/config/helpers/FlowBasedEgressServicesConfigBindHelper.java index 9a14f9327..5f3caa7e9 100644 --- a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/config/helpers/FlowBasedEgressServicesConfigBindHelper.java +++ b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/config/helpers/FlowBasedEgressServicesConfigBindHelper.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * Copyright (c) 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, @@ -22,7 +22,6 @@ import org.opendaylight.genius.utils.ServiceIndex; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.L2vlan; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.Tunnel; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus; import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.ServiceModeBase; import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.service.bindings.ServicesInfo; import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.service.bindings.services.info.BoundServices; @@ -33,7 +32,7 @@ import org.slf4j.LoggerFactory; public class FlowBasedEgressServicesConfigBindHelper implements FlowBasedServicesConfigAddable { private static final Logger LOG = LoggerFactory.getLogger(FlowBasedEgressServicesConfigBindHelper.class); - private InterfacemgrProvider interfaceMgrProvider; + private final InterfacemgrProvider interfaceMgrProvider; private static volatile FlowBasedServicesConfigAddable flowBasedEgressServicesAddable; private FlowBasedEgressServicesConfigBindHelper(InterfacemgrProvider interfaceMgrProvider) { @@ -57,24 +56,26 @@ public class FlowBasedEgressServicesConfigBindHelper implements FlowBasedService return flowBasedEgressServicesAddable; } + @Override public List> bindService(InstanceIdentifier instanceIdentifier, - BoundServices boundServiceNew) { + BoundServices boundServiceNew) { List> futures = new ArrayList<>(); DataBroker dataBroker = interfaceMgrProvider.getDataBroker(); - String interfaceName = - InstanceIdentifier.keyOf(instanceIdentifier.firstIdentifierOf(ServicesInfo.class)).getInterfaceName(); - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifState = - InterfaceManagerCommonUtils.getInterfaceStateFromOperDS(interfaceName, dataBroker); + String interfaceName = InstanceIdentifier.keyOf(instanceIdentifier.firstIdentifierOf(ServicesInfo.class)) + .getInterfaceName(); + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang + .ietf.interfaces.rev140508.interfaces.state.Interface ifState = InterfaceManagerCommonUtils + .getInterfaceStateFromOperDS(interfaceName, dataBroker); if (ifState == null) { LOG.warn("Interface not operational, not binding Service for Interface: {}", interfaceName); return futures; } - Class serviceMode = InstanceIdentifier.keyOf(instanceIdentifier.firstIdentifierOf - (ServicesInfo.class)).getServiceMode(); + Class serviceMode = InstanceIdentifier + .keyOf(instanceIdentifier.firstIdentifierOf(ServicesInfo.class)).getServiceMode(); // Get the Parent ServiceInfo ServicesInfo servicesInfo = FlowBasedServicesUtils.getServicesInfoForInterface(interfaceName, serviceMode, - dataBroker); + dataBroker); if (servicesInfo == null) { LOG.error("Reached Impossible part 1 in the code during bind service for: {}", boundServiceNew); return futures; @@ -86,48 +87,58 @@ public class FlowBasedEgressServicesConfigBindHelper implements FlowBasedService return futures; } - if (L2vlan.class.equals(ifState.getType()) - || Tunnel.class.equals(ifState.getType())) { + if (L2vlan.class.equals(ifState.getType()) || Tunnel.class.equals(ifState.getType())) { bindService(boundServiceNew, allServices, ifState, dataBroker); } return futures; } - private static List> bindService(BoundServices boundServiceNew, List allServices, - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifState, DataBroker dataBroker) { + private static List> bindService(BoundServices boundServiceNew, + List allServices, + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang + .ietf.interfaces.rev140508.interfaces.state.Interface ifState, + DataBroker dataBroker) { List> futures = new ArrayList<>(); BigInteger dpId = FlowBasedServicesUtils.getDpnIdFromInterface(ifState); WriteTransaction transaction = dataBroker.newWriteOnlyTransaction(); Interface iface = InterfaceManagerCommonUtils.getInterfaceFromConfigDS(ifState.getName(), dataBroker); LOG.info("binding egress service {} for interface: {}", boundServiceNew.getServiceName(), ifState.getName()); if (allServices.size() == 1) { - //calling LportDispatcherTableForService with current service index as 0 and next service index as + // calling LportDispatcherTableForService with current service index + // as 0 and next service index as // some value since this is the only service bound. - FlowBasedServicesUtils.installEgressDispatcherFlows(dpId, boundServiceNew, ifState.getName(), - transaction, ifState.getIfIndex(), NwConstants.DEFAULT_SERVICE_INDEX, (short) (boundServiceNew.getServicePriority() + 1), iface); + FlowBasedServicesUtils.installEgressDispatcherFlows(dpId, boundServiceNew, ifState.getName(), transaction, + ifState.getIfIndex(), NwConstants.DEFAULT_SERVICE_INDEX, + (short) (boundServiceNew.getServicePriority() + 1), iface); if (transaction != null) { futures.add(transaction.submit()); } return futures; } allServices.remove(boundServiceNew); - BoundServices[] highLowPriorityService = FlowBasedServicesUtils.getHighAndLowPriorityService(allServices, boundServiceNew); + BoundServices[] highLowPriorityService = FlowBasedServicesUtils.getHighAndLowPriorityService(allServices, + boundServiceNew); BoundServices low = highLowPriorityService[0]; BoundServices high = highLowPriorityService[1]; BoundServices highest = FlowBasedServicesUtils.getHighestPriorityService(allServices); short currentServiceIndex = NwConstants.DEFAULT_SERVICE_INDEX; - short nextServiceIndex = ServiceIndex.getIndex(NwConstants.DEFAULT_EGRESS_SERVICE_NAME, NwConstants.DEFAULT_EGRESS_SERVICE_INDEX); // dummy service index + short nextServiceIndex = ServiceIndex.getIndex(NwConstants.DEFAULT_EGRESS_SERVICE_NAME, + NwConstants.DEFAULT_EGRESS_SERVICE_INDEX); // dummy service + // index if (low != null) { nextServiceIndex = low.getServicePriority(); if (low.equals(highest)) { - //In this case the match criteria of existing service should be changed. + // In this case the match criteria of existing service should be + // changed. BoundServices lower = FlowBasedServicesUtils.getHighAndLowPriorityService(allServices, low)[0]; - short lowerServiceIndex = (short) ((lower != null) ? lower.getServicePriority() : low.getServicePriority() + 1); - LOG.trace("Installing egress dispatcher table entry for existing service {} service match on " - + "service index {} update with service index {}", - low, low.getServicePriority(), lowerServiceIndex); - FlowBasedServicesUtils.installEgressDispatcherFlows(dpId, low, ifState.getName(), transaction, ifState.getIfIndex(), - low.getServicePriority(), lowerServiceIndex, iface); + short lowerServiceIndex = (short) (lower != null ? lower.getServicePriority() + : low.getServicePriority() + 1); + LOG.trace( + "Installing egress dispatcher table entry for existing service {} service match on " + + "service index {} update with service index {}", + low, low.getServicePriority(), lowerServiceIndex); + FlowBasedServicesUtils.installEgressDispatcherFlows(dpId, low, ifState.getName(), transaction, + ifState.getIfIndex(), low.getServicePriority(), lowerServiceIndex, iface); } else { currentServiceIndex = boundServiceNew.getServicePriority(); } @@ -135,20 +146,27 @@ public class FlowBasedEgressServicesConfigBindHelper implements FlowBasedService if (high != null) { currentServiceIndex = boundServiceNew.getServicePriority(); if (high.equals(highest)) { - LOG.trace("Installing egress dispatcher table entry for existing service {} service match on " - + "service index {} update with service index {}", - high, NwConstants.DEFAULT_SERVICE_INDEX, currentServiceIndex); - FlowBasedServicesUtils.installEgressDispatcherFlows(dpId, high, ifState.getName(), transaction, ifState.getIfIndex(), NwConstants.DEFAULT_SERVICE_INDEX, currentServiceIndex, iface); + LOG.trace( + "Installing egress dispatcher table entry for existing service {} service match on " + + "service index {} update with service index {}", + high, NwConstants.DEFAULT_SERVICE_INDEX, currentServiceIndex); + FlowBasedServicesUtils.installEgressDispatcherFlows(dpId, high, ifState.getName(), transaction, + ifState.getIfIndex(), NwConstants.DEFAULT_SERVICE_INDEX, currentServiceIndex, iface); } else { - LOG.trace("Installing egress dispatcher table entry for existing service {} service match on " - + "service index {} update with service index {}", - high, high.getServicePriority(), currentServiceIndex); - FlowBasedServicesUtils.installEgressDispatcherFlows(dpId, high, ifState.getName(), transaction, ifState.getIfIndex(), high.getServicePriority(), currentServiceIndex, iface); + LOG.trace( + "Installing egress dispatcher table entry for existing service {} service match on " + + "service index {} update with service index {}", + high, high.getServicePriority(), currentServiceIndex); + FlowBasedServicesUtils.installEgressDispatcherFlows(dpId, high, ifState.getName(), transaction, + ifState.getIfIndex(), high.getServicePriority(), currentServiceIndex, iface); } } - LOG.trace("Installing egress dispatcher table entry for new service match on service index {} update with service index {}", - currentServiceIndex, nextServiceIndex); - FlowBasedServicesUtils.installEgressDispatcherFlows(dpId, boundServiceNew, ifState.getName(), transaction, ifState.getIfIndex(), currentServiceIndex, nextServiceIndex, iface); + LOG.trace( + "Installing egress dispatcher table entry " + + "for new service match on service index {} update with service index {}", + currentServiceIndex, nextServiceIndex); + FlowBasedServicesUtils.installEgressDispatcherFlows(dpId, boundServiceNew, ifState.getName(), transaction, + ifState.getIfIndex(), currentServiceIndex, nextServiceIndex, iface); futures.add(transaction.submit()); return futures; } diff --git a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/config/helpers/FlowBasedEgressServicesConfigUnbindHelper.java b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/config/helpers/FlowBasedEgressServicesConfigUnbindHelper.java index e532de186..97f7717eb 100644 --- a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/config/helpers/FlowBasedEgressServicesConfigUnbindHelper.java +++ b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/config/helpers/FlowBasedEgressServicesConfigUnbindHelper.java @@ -21,7 +21,6 @@ import org.opendaylight.genius.mdsalutil.NwConstants; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.L2vlan; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.Tunnel; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus; import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.ServiceModeBase; import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.service.bindings.ServicesInfo; import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.service.bindings.services.info.BoundServices; @@ -127,9 +126,10 @@ public class FlowBasedEgressServicesConfigUnbindHelper implements FlowBasedServi BoundServices lower = FlowBasedServicesUtils.getHighAndLowPriorityService(boundServices, low)[0]; short lowerServiceIndex = (short) (lower != null ? lower.getServicePriority() : low.getServicePriority() + 1); - LOG.trace("Installing new egress dispatcher table entry for lower service {}, match service index {}," + - " update service index {}", - low, NwConstants.DEFAULT_SERVICE_INDEX, lowerServiceIndex); + LOG.trace( + "Installing new egress dispatcher table entry for lower service {}, match service index {}," + + " update service index {}", + low, NwConstants.DEFAULT_SERVICE_INDEX, lowerServiceIndex); FlowBasedServicesUtils.installEgressDispatcherFlows(dpId, low, ifaceState.getName(), tx, ifaceState.getIfIndex(), NwConstants.DEFAULT_SERVICE_INDEX, lowerServiceIndex, iface); } diff --git a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/config/helpers/FlowBasedIngressServicesConfigBindHelper.java b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/config/helpers/FlowBasedIngressServicesConfigBindHelper.java index 37a47685f..5950ded58 100644 --- a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/config/helpers/FlowBasedIngressServicesConfigBindHelper.java +++ b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/config/helpers/FlowBasedIngressServicesConfigBindHelper.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * Copyright (c) 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, @@ -25,7 +25,6 @@ import org.opendaylight.genius.mdsalutil.NwConstants; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.L2vlan; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.Tunnel; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus; import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.ServiceModeBase; import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.service.bindings.ServicesInfo; import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.service.bindings.services.info.BoundServices; @@ -68,16 +67,17 @@ public class FlowBasedIngressServicesConfigBindHelper implements FlowBasedServic @Override public List> bindService(InstanceIdentifier instanceIdentifier, - BoundServices boundServiceNew) { + BoundServices boundServiceNew) { List> futures = new ArrayList<>(); DataBroker dataBroker = interfaceMgrProvider.getDataBroker(); - String interfaceName = - InstanceIdentifier.keyOf(instanceIdentifier.firstIdentifierOf(ServicesInfo.class)).getInterfaceName(); + String interfaceName = InstanceIdentifier.keyOf(instanceIdentifier.firstIdentifierOf(ServicesInfo.class)) + .getInterfaceName(); Class serviceMode = InstanceIdentifier .keyOf(instanceIdentifier.firstIdentifierOf(ServicesInfo.class)).getServiceMode(); - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state - .Interface ifState = InterfaceManagerCommonUtils.getInterfaceStateFromOperDS(interfaceName, dataBroker); + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang + .ietf.interfaces.rev140508.interfaces.state.Interface ifState = InterfaceManagerCommonUtils + .getInterfaceStateFromOperDS(interfaceName, dataBroker); if (ifState == null) { LOG.warn("Interface not operational, not binding Service for Interface: {}", interfaceName); return futures; @@ -108,8 +108,9 @@ public class FlowBasedIngressServicesConfigBindHelper implements FlowBasedServic private static List> bindServiceOnTunnel(BoundServices boundServiceNew, List allServices, - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state - .Interface ifState, DataBroker dataBroker) { + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang + .ietf.interfaces.rev140508.interfaces.state.Interface ifState, + DataBroker dataBroker) { List> futures = new ArrayList<>(); NodeConnectorId nodeConnectorId = FlowBasedServicesUtils.getNodeConnectorIdFromInterface(ifState); long portNo = IfmUtil.getPortNumberFromNodeConnectorId(nodeConnectorId); @@ -120,8 +121,8 @@ public class FlowBasedIngressServicesConfigBindHelper implements FlowBasedServic // If only one service present, install instructions in table 0. List matches = null; matches = FlowBasedServicesUtils.getMatchInfoForTunnelPortAtIngressTable(dpId, portNo); - FlowBasedServicesUtils.installInterfaceIngressFlow(dpId, iface, boundServiceNew, - transaction, matches, ifState.getIfIndex(), NwConstants.VLAN_INTERFACE_INGRESS_TABLE); + FlowBasedServicesUtils.installInterfaceIngressFlow(dpId, iface, boundServiceNew, transaction, matches, + ifState.getIfIndex(), NwConstants.VLAN_INTERFACE_INGRESS_TABLE); if (transaction != null) { futures.add(transaction.submit()); } @@ -153,8 +154,7 @@ public class FlowBasedIngressServicesConfigBindHelper implements FlowBasedServic FlowBasedServicesUtils.installLPortDispatcherFlow(dpId, serviceToReplace, ifState.getName(), transaction, ifState.getIfIndex(), serviceToReplace.getServicePriority(), (short) (serviceToReplace.getServicePriority() + 1)); - List matches = null; - matches = FlowBasedServicesUtils.getMatchInfoForTunnelPortAtIngressTable(dpId, portNo); + List matches = FlowBasedServicesUtils.getMatchInfoForTunnelPortAtIngressTable(dpId, portNo); if (matches != null) { WriteTransaction removeFlowTransaction = dataBroker.newWriteOnlyTransaction(); @@ -177,8 +177,9 @@ public class FlowBasedIngressServicesConfigBindHelper implements FlowBasedServic private static List> bindServiceOnVlan(BoundServices boundServiceNew, List allServices, - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state - .Interface ifState, DataBroker dataBroker) { + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang + .ietf.interfaces.rev140508.interfaces.state.Interface ifState, + DataBroker dataBroker) { List> futures = new ArrayList<>(); BigInteger dpId = FlowBasedServicesUtils.getDpnIdFromInterface(ifState); WriteTransaction transaction = dataBroker.newWriteOnlyTransaction(); @@ -202,16 +203,20 @@ public class FlowBasedIngressServicesConfigBindHelper implements FlowBasedServic BoundServices high = highLowPriorityService[1]; BoundServices highest = FlowBasedServicesUtils.getHighestPriorityService(allServices); short currentServiceIndex = NwConstants.DEFAULT_SERVICE_INDEX; - short nextServiceIndex = (short) (boundServiceNew.getServicePriority() + 1); // dummy service index + short nextServiceIndex = (short) (boundServiceNew.getServicePriority() + 1); // dummy + // service + // index if (low != null) { nextServiceIndex = low.getServicePriority(); if (low.equals(highest)) { - //In this case the match criteria of existing service should be changed. + // In this case the match criteria of existing service should be + // changed. BoundServices lower = FlowBasedServicesUtils.getHighAndLowPriorityService(allServices, low)[0]; short lowerServiceIndex = (short) (lower != null ? lower.getServicePriority() : low.getServicePriority() + 1); - LOG.trace("Installing ingress dispatcher table entry for existing service {} service match on " - + "service index {} update with service index {}", + LOG.trace( + "Installing ingress dispatcher table entry for existing service {} service match on " + + "service index {} update with service index {}", low, low.getServicePriority(), lowerServiceIndex); FlowBasedServicesUtils.installLPortDispatcherFlow(dpId, low, ifState.getName(), transaction, ifState.getIfIndex(), low.getServicePriority(), lowerServiceIndex); @@ -222,22 +227,23 @@ public class FlowBasedIngressServicesConfigBindHelper implements FlowBasedServic if (high != null) { currentServiceIndex = boundServiceNew.getServicePriority(); if (high.equals(highest)) { - LOG.trace("Installing ingress dispatcher table entry for existing service {} service match on " - + "service index {} update with service index {}", + LOG.trace( + "Installing ingress dispatcher table entry for existing service {} service match on " + + "service index {} update with service index {}", high, NwConstants.DEFAULT_SERVICE_INDEX, currentServiceIndex); FlowBasedServicesUtils.installLPortDispatcherFlow(dpId, high, ifState.getName(), transaction, ifState.getIfIndex(), NwConstants.DEFAULT_SERVICE_INDEX, currentServiceIndex); } else { - LOG.trace("Installing ingress dispatcher table entry for existing service {} service match on " - + "service index {} update with service index {}", + LOG.trace( + "Installing ingress dispatcher table entry for existing service {} service match on " + + "service index {} update with service index {}", high, high.getServicePriority(), currentServiceIndex); FlowBasedServicesUtils.installLPortDispatcherFlow(dpId, high, ifState.getName(), transaction, ifState.getIfIndex(), high.getServicePriority(), currentServiceIndex); } } - LOG.trace("Installing ingress dispatcher table entry for new service match on service index {} update with " + - "service index {}", - currentServiceIndex, nextServiceIndex); + LOG.trace("Installing ingress dispatcher table entry for new service match on service index {} update with " + + "service index {}", currentServiceIndex, nextServiceIndex); FlowBasedServicesUtils.installLPortDispatcherFlow(dpId, boundServiceNew, ifState.getName(), transaction, ifState.getIfIndex(), currentServiceIndex, nextServiceIndex); futures.add(transaction.submit()); diff --git a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/config/helpers/FlowBasedIngressServicesConfigUnbindHelper.java b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/config/helpers/FlowBasedIngressServicesConfigUnbindHelper.java index fa818fcf9..0f16a23a8 100644 --- a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/config/helpers/FlowBasedIngressServicesConfigUnbindHelper.java +++ b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/config/helpers/FlowBasedIngressServicesConfigUnbindHelper.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * Copyright (c) 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, @@ -25,7 +25,6 @@ import org.opendaylight.genius.mdsalutil.NwConstants; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.L2vlan; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.Tunnel; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus; import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.ServiceModeBase; import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.service.bindings.ServicesInfo; import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.service.bindings.services.info.BoundServices; @@ -69,12 +68,12 @@ public class FlowBasedIngressServicesConfigUnbindHelper implements FlowBasedServ @Override public List> unbindService(InstanceIdentifier instanceIdentifier, - BoundServices boundServiceOld) { + BoundServices boundServiceOld) { List> futures = new ArrayList<>(); DataBroker dataBroker = interfaceMgrProvider.getDataBroker(); - String interfaceName = - InstanceIdentifier.keyOf(instanceIdentifier.firstIdentifierOf(ServicesInfo.class)).getInterfaceName(); + String interfaceName = InstanceIdentifier.keyOf(instanceIdentifier.firstIdentifierOf(ServicesInfo.class)) + .getInterfaceName(); Class serviceMode = InstanceIdentifier .keyOf(instanceIdentifier.firstIdentifierOf(ServicesInfo.class)).getServiceMode(); @@ -86,8 +85,9 @@ public class FlowBasedIngressServicesConfigUnbindHelper implements FlowBasedServ return futures; } - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface - ifState = InterfaceManagerCommonUtils.getInterfaceStateFromOperDS(interfaceName, dataBroker); + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang + .ietf.interfaces.rev140508.interfaces.state.Interface ifState = InterfaceManagerCommonUtils + .getInterfaceStateFromOperDS(interfaceName, dataBroker); if (ifState == null) { LOG.info("Interface not operational, not unbinding Service for Interface: {}", interfaceName); return futures; @@ -105,10 +105,11 @@ public class FlowBasedIngressServicesConfigUnbindHelper implements FlowBasedServ private static List> unbindServiceOnVlan(BoundServices boundServiceOld, List boundServices, - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state - .Interface ifaceState, DataBroker dataBroker) { - LOG.info("unbinding ingress service {} for vlan port: {}", boundServiceOld.getServiceName(), ifaceState - .getName()); + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang + .ietf.interfaces.rev140508.interfaces.state.Interface ifaceState, + DataBroker dataBroker) { + LOG.info("unbinding ingress service {} for vlan port: {}", boundServiceOld.getServiceName(), + ifaceState.getName()); List> futures = new ArrayList<>(); WriteTransaction tx = dataBroker.newWriteOnlyTransaction(); BigInteger dpId = FlowBasedServicesUtils.getDpnIdFromInterface(ifaceState); @@ -131,7 +132,7 @@ public class FlowBasedIngressServicesConfigUnbindHelper implements FlowBasedServ FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, ifaceState.getName(), boundServiceOld, tx, NwConstants.DEFAULT_SERVICE_INDEX); if (low != null) { - //delete the lower services flow entry. + // delete the lower services flow entry. LOG.trace("Deleting ingress dispatcher table entry for lower service {}, match service index {}", low, low.getServicePriority()); FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, ifaceState.getName(), low, tx, @@ -139,8 +140,9 @@ public class FlowBasedIngressServicesConfigUnbindHelper implements FlowBasedServ BoundServices lower = FlowBasedServicesUtils.getHighAndLowPriorityService(boundServices, low)[0]; short lowerServiceIndex = (short) (lower != null ? lower.getServicePriority() : low.getServicePriority() + 1); - LOG.trace("Installing new ingress dispatcher table entry for lower service {}, match service index " + - "{}, update service index {}", + LOG.trace( + "Installing new ingress dispatcher table entry for lower service {}, match service index " + + "{}, update service index {}", low, NwConstants.DEFAULT_SERVICE_INDEX, lowerServiceIndex); FlowBasedServicesUtils.installLPortDispatcherFlow(dpId, low, ifaceState.getName(), tx, ifaceState.getIfIndex(), NwConstants.DEFAULT_SERVICE_INDEX, lowerServiceIndex); @@ -171,14 +173,14 @@ public class FlowBasedIngressServicesConfigUnbindHelper implements FlowBasedServ private static List> unbindServiceOnTunnel(BoundServices boundServiceOld, List boundServices, - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state - .Interface ifState, DataBroker dataBroker) { + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang + .ietf.interfaces.rev140508.interfaces.state.Interface ifState, + DataBroker dataBroker) { List> futures = new ArrayList<>(); - Interface iface = InterfaceManagerCommonUtils.getInterfaceFromConfigDS(ifState.getName(), dataBroker); WriteTransaction tx = dataBroker.newWriteOnlyTransaction(); NodeConnectorId nodeConnectorId = FlowBasedServicesUtils.getNodeConnectorIdFromInterface(ifState); - long portNo = IfmUtil.getPortNumberFromNodeConnectorId(nodeConnectorId); + BigInteger dpId = IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId); if (boundServices.isEmpty()) { @@ -208,13 +210,16 @@ public class FlowBasedIngressServicesConfigUnbindHelper implements FlowBasedServ return futures; } - List matches = null; + List matches; + long portNo = IfmUtil.getPortNumberFromNodeConnectorId(nodeConnectorId); matches = FlowBasedServicesUtils.getMatchInfoForTunnelPortAtIngressTable(dpId, portNo); BoundServices toBeMoved = tmpServicesMap.get(highestPriority); + Interface iface = + InterfaceManagerCommonUtils.getInterfaceFromConfigDS(ifState.getName(), dataBroker); FlowBasedServicesUtils.removeIngressFlow(iface.getName(), boundServiceOld, dpId, tx); - FlowBasedServicesUtils.installInterfaceIngressFlow(dpId, iface, toBeMoved, tx, - matches, ifState.getIfIndex(), NwConstants.VLAN_INTERFACE_INGRESS_TABLE); + FlowBasedServicesUtils.installInterfaceIngressFlow(dpId, iface, toBeMoved, tx, matches, ifState.getIfIndex(), + NwConstants.VLAN_INTERFACE_INGRESS_TABLE); FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, iface.getName(), toBeMoved, tx, toBeMoved.getServicePriority()); @@ -223,5 +228,4 @@ public class FlowBasedIngressServicesConfigUnbindHelper implements FlowBasedServ } return futures; } - } diff --git a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/listeners/FlowBasedServicesConfigListener.java b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/listeners/FlowBasedServicesConfigListener.java index 3609842f7..1096b76ac 100644 --- a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/listeners/FlowBasedServicesConfigListener.java +++ b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/listeners/FlowBasedServicesConfigListener.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * Copyright (c) 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, @@ -14,7 +14,6 @@ import java.util.Objects; import java.util.concurrent.Callable; import javax.inject.Inject; import javax.inject.Singleton; - import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.genius.datastoreutils.AsyncClusteredDataTreeChangeListenerBase; @@ -38,11 +37,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; @Singleton -public class FlowBasedServicesConfigListener extends AsyncClusteredDataTreeChangeListenerBase { +public class FlowBasedServicesConfigListener + extends AsyncClusteredDataTreeChangeListenerBase { private static final Logger LOG = LoggerFactory.getLogger(FlowBasedServicesConfigListener.class); @Inject - public FlowBasedServicesConfigListener(final DataBroker dataBroker, final InterfacemgrProvider interfacemgrProvider) { + public FlowBasedServicesConfigListener(final DataBroker dataBroker, + final InterfacemgrProvider interfacemgrProvider) { super(BoundServices.class, FlowBasedServicesConfigListener.class); initializeFlowBasedServiceHelpers(interfacemgrProvider); registerListener(LogicalDatastoreType.CONFIGURATION, dataBroker); @@ -60,8 +61,7 @@ public class FlowBasedServicesConfigListener extends AsyncClusteredDataTreeChang @Override protected InstanceIdentifier getWildCardPath() { - return InstanceIdentifier.create(ServiceBindings.class).child(ServicesInfo.class) - .child(BoundServices.class); + return InstanceIdentifier.create(ServiceBindings.class).child(ServicesInfo.class).child(BoundServices.class); } @Override @@ -69,13 +69,13 @@ public class FlowBasedServicesConfigListener extends AsyncClusteredDataTreeChang IfmClusterUtils.runOnlyInLeaderNode(() -> { ServicesInfoKey serviceKey = InstanceIdentifier.keyOf(key.firstIdentifierOf(ServicesInfo.class)); LOG.info("Service Binding Entry removed for Interface: {}, Data: {}", serviceKey.getInterfaceName(), - boundServiceOld); - FlowBasedServicesConfigRemovable flowBasedServicesConfigRemovable = - FlowBasedServicesRendererFactory.getFlowBasedServicesRendererFactory(serviceKey.getServiceMode()) + boundServiceOld); + FlowBasedServicesConfigRemovable flowBasedServicesConfigRemovable = FlowBasedServicesRendererFactory + .getFlowBasedServicesRendererFactory(serviceKey.getServiceMode()) .getFlowBasedServicesRemoveRenderer(); DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance(); - RendererConfigRemoveWorker configWorker = - new RendererConfigRemoveWorker(flowBasedServicesConfigRemovable, key, boundServiceOld); + RendererConfigRemoveWorker configWorker = new RendererConfigRemoveWorker(flowBasedServicesConfigRemovable, + key, boundServiceOld); coordinator.enqueueJob(serviceKey.getInterfaceName(), configWorker, IfmConstants.JOB_MAX_RETRIES); }, IfmClusterUtils.INTERFACE_SERVICE_BINDING_ENTITY); } @@ -95,13 +95,12 @@ public class FlowBasedServicesConfigListener extends AsyncClusteredDataTreeChang IfmClusterUtils.runOnlyInLeaderNode(() -> { ServicesInfoKey serviceKey = InstanceIdentifier.keyOf(key.firstIdentifierOf(ServicesInfo.class)); LOG.info("Service Binding Entry created for Interface: {}, Data: {}", serviceKey.getInterfaceName(), - boundServicesNew); - FlowBasedServicesConfigAddable flowBasedServicesAddable = - FlowBasedServicesRendererFactory.getFlowBasedServicesRendererFactory(serviceKey.getServiceMode()) - .getFlowBasedServicesAddRenderer(); + boundServicesNew); + FlowBasedServicesConfigAddable flowBasedServicesAddable = FlowBasedServicesRendererFactory + .getFlowBasedServicesRendererFactory(serviceKey.getServiceMode()).getFlowBasedServicesAddRenderer(); DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance(); - RendererConfigAddWorker configWorker = - new RendererConfigAddWorker(flowBasedServicesAddable, key, boundServicesNew); + RendererConfigAddWorker configWorker = new RendererConfigAddWorker(flowBasedServicesAddable, key, + boundServicesNew); coordinator.enqueueJob(serviceKey.getInterfaceName(), configWorker, IfmConstants.JOB_MAX_RETRIES); }, IfmClusterUtils.INTERFACE_SERVICE_BINDING_ENTITY); } @@ -125,8 +124,7 @@ public class FlowBasedServicesConfigListener extends AsyncClusteredDataTreeChang @Override public List> call() { - return flowBasedServicesAddable.bindService(instanceIdentifier, - boundServicesNew); + return flowBasedServicesAddable.bindService(instanceIdentifier, boundServicesNew); } } @@ -136,8 +134,7 @@ public class FlowBasedServicesConfigListener extends AsyncClusteredDataTreeChang BoundServices boundServicesNew; RendererConfigRemoveWorker(FlowBasedServicesConfigRemovable flowBasedServicesConfigRemovable, - InstanceIdentifier instanceIdentifier, - BoundServices boundServicesNew) { + InstanceIdentifier instanceIdentifier, BoundServices boundServicesNew) { this.flowBasedServicesConfigRemovable = flowBasedServicesConfigRemovable; this.instanceIdentifier = instanceIdentifier; this.boundServicesNew = boundServicesNew; @@ -145,8 +142,7 @@ public class FlowBasedServicesConfigListener extends AsyncClusteredDataTreeChang @Override public List> call() { - return flowBasedServicesConfigRemovable.unbindService(instanceIdentifier, - boundServicesNew); + return flowBasedServicesConfigRemovable.unbindService(instanceIdentifier, boundServicesNew); } } } diff --git a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/listeners/FlowBasedServicesInterfaceStateListener.java b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/listeners/FlowBasedServicesInterfaceStateListener.java index 7c6e29806..0d271b357 100644 --- a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/listeners/FlowBasedServicesInterfaceStateListener.java +++ b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/listeners/FlowBasedServicesInterfaceStateListener.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * Copyright (c) 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, @@ -31,17 +31,18 @@ import org.opendaylight.genius.interfacemanager.servicebindings.flowbased.state. import org.opendaylight.genius.interfacemanager.servicebindings.flowbased.utilities.FlowBasedServicesUtils; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.ServiceModeBase; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @Singleton -public class FlowBasedServicesInterfaceStateListener extends AsyncClusteredDataTreeChangeListenerBase { +public class FlowBasedServicesInterfaceStateListener + extends AsyncClusteredDataTreeChangeListenerBase { private static final Logger LOG = LoggerFactory.getLogger(FlowBasedServicesInterfaceStateListener.class); @Inject - public FlowBasedServicesInterfaceStateListener(final InterfacemgrProvider interfacemgrProvider, DataBroker dataBroker) { + public FlowBasedServicesInterfaceStateListener(final InterfacemgrProvider interfacemgrProvider, + DataBroker dataBroker) { super(Interface.class, FlowBasedServicesInterfaceStateListener.class); initializeFlowBasedServiceStateBindHelpers(interfacemgrProvider); this.registerListener(LogicalDatastoreType.OPERATIONAL, dataBroker); @@ -53,17 +54,21 @@ public class FlowBasedServicesInterfaceStateListener extends AsyncClusteredDataT LOG.info("FlowBasedServicesInterfaceStateListener started"); } + @Override @PreDestroy - public void close(){ + public void close() { LOG.info("FlowBasedServicesInterfaceStateListener closed"); } private void initializeFlowBasedServiceStateBindHelpers(InterfacemgrProvider interfaceMgrProvider) { FlowBasedIngressServicesStateBindHelper.intitializeFlowBasedIngressServicesStateAddHelper(interfaceMgrProvider); - FlowBasedIngressServicesStateUnbindHelper.intitializeFlowBasedIngressServicesStateRemoveHelper(interfaceMgrProvider); + FlowBasedIngressServicesStateUnbindHelper + .intitializeFlowBasedIngressServicesStateRemoveHelper(interfaceMgrProvider); FlowBasedEgressServicesStateBindHelper.intitializeFlowBasedEgressServicesStateBindHelper(interfaceMgrProvider); - FlowBasedEgressServicesStateUnbindHelper.intitializeFlowBasedEgressServicesStateUnbindHelper(interfaceMgrProvider); + FlowBasedEgressServicesStateUnbindHelper + .intitializeFlowBasedEgressServicesStateUnbindHelper(interfaceMgrProvider); } + @Override protected InstanceIdentifier getWildCardPath() { return InstanceIdentifier.create(InterfacesState.class).child(Interface.class); @@ -72,16 +77,18 @@ public class FlowBasedServicesInterfaceStateListener extends AsyncClusteredDataT @Override protected void remove(InstanceIdentifier key, Interface interfaceStateOld) { if (interfaceStateOld.getType() == null - || !IfmClusterUtils.isEntityOwner(IfmClusterUtils.INTERFACE_SERVICE_BINDING_ENTITY)) { + || !IfmClusterUtils.isEntityOwner(IfmClusterUtils.INTERFACE_SERVICE_BINDING_ENTITY)) { return; } LOG.debug("Received interface state remove event for {}", interfaceStateOld.getName()); DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance(); - FlowBasedServicesUtils.SERVICE_MODE_MAP.values().stream().forEach(serviceMode -> - coordinator.enqueueJob(interfaceStateOld.getName(), new RendererStateInterfaceUnbindWorker - (FlowBasedServicesStateRendererFactory.getFlowBasedServicesStateRendererFactory(serviceMode) - .getFlowBasedServicesStateRemoveRenderer(), interfaceStateOld), IfmConstants.JOB_MAX_RETRIES)); + FlowBasedServicesUtils.SERVICE_MODE_MAP.values().stream() + .forEach(serviceMode -> coordinator.enqueueJob(interfaceStateOld.getName(), + new RendererStateInterfaceUnbindWorker(FlowBasedServicesStateRendererFactory + .getFlowBasedServicesStateRendererFactory(serviceMode) + .getFlowBasedServicesStateRemoveRenderer(), interfaceStateOld), + IfmConstants.JOB_MAX_RETRIES)); } @Override @@ -92,15 +99,17 @@ public class FlowBasedServicesInterfaceStateListener extends AsyncClusteredDataT @Override protected void add(InstanceIdentifier key, Interface interfaceStateNew) { if (interfaceStateNew.getType() == null - || !IfmClusterUtils.isEntityOwner(IfmClusterUtils.INTERFACE_SERVICE_BINDING_ENTITY)) { + || !IfmClusterUtils.isEntityOwner(IfmClusterUtils.INTERFACE_SERVICE_BINDING_ENTITY)) { return; } LOG.debug("Received interface state add event for {}", interfaceStateNew.getName()); DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance(); - FlowBasedServicesUtils.SERVICE_MODE_MAP.values().stream().forEach(serviceMode -> - coordinator.enqueueJob(interfaceStateNew.getName(), new RendererStateInterfaceBindWorker - (FlowBasedServicesStateRendererFactory.getFlowBasedServicesStateRendererFactory(serviceMode) - .getFlowBasedServicesStateAddRenderer(), interfaceStateNew), IfmConstants.JOB_MAX_RETRIES)); + FlowBasedServicesUtils.SERVICE_MODE_MAP.values().stream().forEach(serviceMode -> coordinator.enqueueJob( + interfaceStateNew.getName(), + new RendererStateInterfaceBindWorker(FlowBasedServicesStateRendererFactory + .getFlowBasedServicesStateRendererFactory(serviceMode).getFlowBasedServicesStateAddRenderer(), + interfaceStateNew), + IfmConstants.JOB_MAX_RETRIES)); } @Override @@ -112,8 +121,8 @@ public class FlowBasedServicesInterfaceStateListener extends AsyncClusteredDataT Interface iface; FlowBasedServicesStateAddable flowBasedServicesStateAddable; - public RendererStateInterfaceBindWorker(FlowBasedServicesStateAddable flowBasedServicesStateAddable, - Interface iface) { + RendererStateInterfaceBindWorker(FlowBasedServicesStateAddable flowBasedServicesStateAddable, + Interface iface) { this.flowBasedServicesStateAddable = flowBasedServicesStateAddable; this.iface = iface; } @@ -128,8 +137,8 @@ public class FlowBasedServicesInterfaceStateListener extends AsyncClusteredDataT Interface iface; FlowBasedServicesStateRemovable flowBasedServicesStateRemovable; - public RendererStateInterfaceUnbindWorker(FlowBasedServicesStateRemovable flowBasedServicesStateRemovable, - Interface iface) { + RendererStateInterfaceUnbindWorker(FlowBasedServicesStateRemovable flowBasedServicesStateRemovable, + Interface iface) { this.flowBasedServicesStateRemovable = flowBasedServicesStateRemovable; this.iface = iface; } @@ -139,4 +148,4 @@ public class FlowBasedServicesInterfaceStateListener extends AsyncClusteredDataT return flowBasedServicesStateRemovable.unbindServicesFromInterface(iface); } } -} \ No newline at end of file +} diff --git a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/state/helpers/FlowBasedEgressServicesStateBindHelper.java b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/state/helpers/FlowBasedEgressServicesStateBindHelper.java index 7a955c64f..45cc5bfd9 100644 --- a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/state/helpers/FlowBasedEgressServicesStateBindHelper.java +++ b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/state/helpers/FlowBasedEgressServicesStateBindHelper.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * Copyright (c) 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, @@ -30,10 +30,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeCon import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class FlowBasedEgressServicesStateBindHelper implements FlowBasedServicesStateAddable{ +public class FlowBasedEgressServicesStateBindHelper implements FlowBasedServicesStateAddable { private static final Logger LOG = LoggerFactory.getLogger(FlowBasedEgressServicesStateBindHelper.class); - private InterfacemgrProvider interfaceMgrProvider; + private final InterfacemgrProvider interfaceMgrProvider; private static volatile FlowBasedServicesStateAddable flowBasedServicesStateAddable; private FlowBasedEgressServicesStateBindHelper(InterfacemgrProvider interfaceMgrProvider) { @@ -57,11 +57,13 @@ public class FlowBasedEgressServicesStateBindHelper implements FlowBasedServices return flowBasedServicesStateAddable; } + @Override public List> bindServicesOnInterface(Interface ifaceState) { List> futures = new ArrayList<>(); LOG.debug("binding services on interface {}", ifaceState.getName()); DataBroker dataBroker = interfaceMgrProvider.getDataBroker(); - ServicesInfo servicesInfo = FlowBasedServicesUtils.getServicesInfoForInterface(ifaceState.getName(), ServiceModeEgress.class, dataBroker); + ServicesInfo servicesInfo = FlowBasedServicesUtils.getServicesInfoForInterface(ifaceState.getName(), + ServiceModeEgress.class, dataBroker); if (servicesInfo == null) { LOG.trace("service info is null for interface {}", ifaceState.getName()); return futures; @@ -73,40 +75,44 @@ public class FlowBasedEgressServicesStateBindHelper implements FlowBasedServices return futures; } - if (L2vlan.class.equals(ifaceState.getType()) - || Tunnel.class.equals(ifaceState.getType())) { + if (L2vlan.class.equals(ifaceState.getType()) || Tunnel.class.equals(ifaceState.getType())) { return bindServices(allServices, ifaceState, dataBroker); } return futures; } - private static List> bindServices( - List allServices, - Interface ifState, DataBroker dataBroker) { + private static List> bindServices(List allServices, Interface ifState, + DataBroker dataBroker) { LOG.info("bind all egress services for interface: {}", ifState.getName()); - List> futures = new ArrayList<>(); + NodeConnectorId nodeConnectorId = FlowBasedServicesUtils.getNodeConnectorIdFromInterface(ifState); BigInteger dpId = IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId); - WriteTransaction t = dataBroker.newWriteOnlyTransaction(); - Collections.sort(allServices, - (serviceInfo1, serviceInfo2) -> serviceInfo1.getServicePriority().compareTo(serviceInfo2.getServicePriority())); + WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction(); + Collections.sort(allServices, (serviceInfo1, serviceInfo2) -> serviceInfo1.getServicePriority() + .compareTo(serviceInfo2.getServicePriority())); BoundServices highestPriority = allServices.remove(0); - short nextServiceIndex = (short) (allServices.size() > 0 ? allServices.get(0).getServicePriority() : highestPriority.getServicePriority() + 1); - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface iface = InterfaceManagerCommonUtils.getInterfaceFromConfigDS(ifState.getName(), dataBroker); - FlowBasedServicesUtils.installEgressDispatcherFlows(dpId, highestPriority, ifState.getName(), t, ifState.getIfIndex(), NwConstants.DEFAULT_SERVICE_INDEX, nextServiceIndex, iface); + short nextServiceIndex = (short) (allServices.size() > 0 ? allServices.get(0).getServicePriority() + : highestPriority.getServicePriority() + 1); + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang + .ietf.interfaces.rev140508.interfaces.Interface iface = InterfaceManagerCommonUtils + .getInterfaceFromConfigDS(ifState.getName(), dataBroker); + FlowBasedServicesUtils.installEgressDispatcherFlows(dpId, highestPriority, ifState.getName(), writeTransaction, + ifState.getIfIndex(), NwConstants.DEFAULT_SERVICE_INDEX, nextServiceIndex, iface); BoundServices prev = null; for (BoundServices boundService : allServices) { - if (prev!=null) { - FlowBasedServicesUtils.installEgressDispatcherFlows(dpId, prev, ifState.getName(), t, ifState.getIfIndex(), prev.getServicePriority(), boundService.getServicePriority(), iface); + if (prev != null) { + FlowBasedServicesUtils.installEgressDispatcherFlows(dpId, prev, ifState.getName(), writeTransaction, + ifState.getIfIndex(), prev.getServicePriority(), boundService.getServicePriority(), iface); } prev = boundService; } - if (prev!=null) { - FlowBasedServicesUtils.installEgressDispatcherFlows(dpId, prev, ifState.getName(), t, ifState.getIfIndex(), prev.getServicePriority(), (short) (prev.getServicePriority()+1), iface); + if (prev != null) { + FlowBasedServicesUtils.installEgressDispatcherFlows(dpId, prev, ifState.getName(), writeTransaction, + ifState.getIfIndex(), + prev.getServicePriority(), (short) (prev.getServicePriority() + 1), iface); } - futures.add(t.submit()); + List> futures = new ArrayList<>(); + futures.add(writeTransaction.submit()); return futures; - } - -} \ No newline at end of file +} diff --git a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/state/helpers/FlowBasedEgressServicesStateUnbindHelper.java b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/state/helpers/FlowBasedEgressServicesStateUnbindHelper.java index 61d6e07f3..423a4a70f 100644 --- a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/state/helpers/FlowBasedEgressServicesStateUnbindHelper.java +++ b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/state/helpers/FlowBasedEgressServicesStateUnbindHelper.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * Copyright (c) 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, @@ -29,10 +29,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeCon import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class FlowBasedEgressServicesStateUnbindHelper implements FlowBasedServicesStateRemovable{ +public class FlowBasedEgressServicesStateUnbindHelper implements FlowBasedServicesStateRemovable { private static final Logger LOG = LoggerFactory.getLogger(FlowBasedEgressServicesStateUnbindHelper.class); - private InterfacemgrProvider interfaceMgrProvider; + private final InterfacemgrProvider interfaceMgrProvider; private static volatile FlowBasedServicesStateRemovable flowBasedServicesStateRemovable; private FlowBasedEgressServicesStateUnbindHelper(InterfacemgrProvider interfaceMgrProvider) { @@ -43,7 +43,8 @@ public class FlowBasedEgressServicesStateUnbindHelper implements FlowBasedServic if (flowBasedServicesStateRemovable == null) { synchronized (FlowBasedEgressServicesStateUnbindHelper.class) { if (flowBasedServicesStateRemovable == null) { - flowBasedServicesStateRemovable = new FlowBasedEgressServicesStateUnbindHelper(interfaceMgrProvider); + flowBasedServicesStateRemovable = new FlowBasedEgressServicesStateUnbindHelper( + interfaceMgrProvider); } } } @@ -55,12 +56,15 @@ public class FlowBasedEgressServicesStateUnbindHelper implements FlowBasedServic } return flowBasedServicesStateRemovable; } + + @Override public List> unbindServicesFromInterface(Interface ifaceState) { List> futures = new ArrayList<>(); LOG.debug("unbinding services on interface {}", ifaceState.getName()); DataBroker dataBroker = interfaceMgrProvider.getDataBroker(); - ServicesInfo servicesInfo = FlowBasedServicesUtils.getServicesInfoForInterface(ifaceState.getName(), ServiceModeEgress.class, dataBroker); + ServicesInfo servicesInfo = FlowBasedServicesUtils.getServicesInfoForInterface(ifaceState.getName(), + ServiceModeEgress.class, dataBroker); if (servicesInfo == null) { LOG.trace("service info is null for interface {}", ifaceState.getName()); return futures; @@ -72,37 +76,37 @@ public class FlowBasedEgressServicesStateUnbindHelper implements FlowBasedServic return futures; } - if (L2vlan.class.equals(ifaceState.getType()) - || Tunnel.class.equals(ifaceState.getType())) { + if (L2vlan.class.equals(ifaceState.getType()) || Tunnel.class.equals(ifaceState.getType())) { return unbindServices(allServices, ifaceState, ifaceState.getIfIndex(), dataBroker); } return futures; } - private static List> unbindServices( - List allServices, Interface ifaceState, + private static List> unbindServices(List allServices, Interface ifaceState, Integer ifIndex, DataBroker dataBroker) { LOG.info("unbind all egress services for interface: {}", ifaceState.getName()); List> futures = new ArrayList<>(); - WriteTransaction t = dataBroker.newWriteOnlyTransaction(); + WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction(); List ofportIds = ifaceState.getLowerLayerIf(); NodeConnectorId nodeConnectorId = new NodeConnectorId(ofportIds.get(0)); - if(nodeConnectorId == null){ + if (nodeConnectorId == null) { return futures; } BigInteger dpId = IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId); - Collections.sort(allServices, - (serviceInfo1, serviceInfo2) -> serviceInfo1.getServicePriority().compareTo(serviceInfo2.getServicePriority())); + Collections.sort(allServices, (serviceInfo1, serviceInfo2) -> serviceInfo1.getServicePriority() + .compareTo(serviceInfo2.getServicePriority())); BoundServices highestPriority = allServices.remove(0); - FlowBasedServicesUtils.removeEgressDispatcherFlows(dpId, ifaceState.getName(), highestPriority, t, NwConstants.DEFAULT_SERVICE_INDEX); + FlowBasedServicesUtils.removeEgressDispatcherFlows(dpId, ifaceState.getName(), highestPriority, + writeTransaction, NwConstants.DEFAULT_SERVICE_INDEX); for (BoundServices boundService : allServices) { - FlowBasedServicesUtils.removeEgressDispatcherFlows(dpId, ifaceState.getName(), boundService, t, boundService.getServicePriority()); + FlowBasedServicesUtils.removeEgressDispatcherFlows(dpId, ifaceState.getName(), boundService, + writeTransaction, boundService.getServicePriority()); } - futures.add(t.submit()); - // remove the default egress service bound on the interface, once all flows are removed + futures.add(writeTransaction.submit()); + // remove the default egress service bound on the interface, once all + // flows are removed FlowBasedServicesUtils.unbindDefaultEgressDispatcherService(dataBroker, ifaceState.getName()); return futures; } - } diff --git a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/state/helpers/FlowBasedIngressServicesStateBindHelper.java b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/state/helpers/FlowBasedIngressServicesStateBindHelper.java index 74dd8d591..90199c899 100644 --- a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/state/helpers/FlowBasedIngressServicesStateBindHelper.java +++ b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/state/helpers/FlowBasedIngressServicesStateBindHelper.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * Copyright (c) 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, @@ -31,10 +31,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeCon import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class FlowBasedIngressServicesStateBindHelper implements FlowBasedServicesStateAddable{ +public class FlowBasedIngressServicesStateBindHelper implements FlowBasedServicesStateAddable { private static final Logger LOG = LoggerFactory.getLogger(FlowBasedIngressServicesStateBindHelper.class); - private InterfacemgrProvider interfaceMgrProvider; + private final InterfacemgrProvider interfaceMgrProvider; private static volatile FlowBasedServicesStateAddable flowBasedIngressServicesStateAddable; private FlowBasedIngressServicesStateBindHelper(InterfacemgrProvider interfaceMgrProvider) { @@ -45,7 +45,8 @@ public class FlowBasedIngressServicesStateBindHelper implements FlowBasedService if (flowBasedIngressServicesStateAddable == null) { synchronized (FlowBasedIngressServicesStateBindHelper.class) { if (flowBasedIngressServicesStateAddable == null) { - flowBasedIngressServicesStateAddable = new FlowBasedIngressServicesStateBindHelper(interfaceMgrProvider); + flowBasedIngressServicesStateAddable = new FlowBasedIngressServicesStateBindHelper( + interfaceMgrProvider); } } } @@ -61,14 +62,17 @@ public class FlowBasedIngressServicesStateBindHelper implements FlowBasedService } return flowBasedIngressServicesStateAddable; } + + @Override public List> bindServicesOnInterface(Interface ifaceState) { - if(ifaceState.getType() == null) { + if (ifaceState.getType() == null) { return null; } List> futures = new ArrayList<>(); LOG.debug("binding services on interface {}", ifaceState.getName()); DataBroker dataBroker = interfaceMgrProvider.getDataBroker(); - ServicesInfo servicesInfo = FlowBasedServicesUtils.getServicesInfoForInterface(ifaceState.getName(), ServiceModeIngress.class, dataBroker); + ServicesInfo servicesInfo = FlowBasedServicesUtils.getServicesInfoForInterface(ifaceState.getName(), + ServiceModeIngress.class, dataBroker); if (servicesInfo == null) { LOG.trace("service info is null for interface {}", ifaceState.getName()); return futures; @@ -81,64 +85,68 @@ public class FlowBasedIngressServicesStateBindHelper implements FlowBasedService } if (L2vlan.class.equals(ifaceState.getType())) { return bindServiceOnVlan(allServices, ifaceState, dataBroker); - } else if (Tunnel.class.equals(ifaceState.getType())){ + } else if (Tunnel.class.equals(ifaceState.getType())) { return bindServiceOnTunnel(allServices, ifaceState, dataBroker); } return futures; } - private static List> bindServiceOnTunnel( - List allServices, Interface ifState, DataBroker dataBroker) { + private static List> bindServiceOnTunnel(List allServices, Interface ifState, + DataBroker dataBroker) { List> futures = new ArrayList<>(); - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface iface = - InterfaceManagerCommonUtils.getInterfaceFromConfigDS(ifState.getName(), dataBroker); + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang + .ietf.interfaces.rev140508.interfaces.Interface iface = InterfaceManagerCommonUtils + .getInterfaceFromConfigDS(ifState.getName(), dataBroker); NodeConnectorId nodeConnectorId = FlowBasedServicesUtils.getNodeConnectorIdFromInterface(ifState); long portNo = IfmUtil.getPortNumberFromNodeConnectorId(nodeConnectorId); BigInteger dpId = IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId); - List matches = FlowBasedServicesUtils.getMatchInfoForTunnelPortAtIngressTable (dpId, portNo); + List matches = FlowBasedServicesUtils.getMatchInfoForTunnelPortAtIngressTable(dpId, portNo); BoundServices highestPriorityBoundService = FlowBasedServicesUtils.getHighestPriorityService(allServices); - WriteTransaction t = dataBroker.newWriteOnlyTransaction(); + WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction(); if (matches != null) { FlowBasedServicesUtils.installInterfaceIngressFlow(dpId, iface, highestPriorityBoundService, - t, matches, ifState.getIfIndex(), NwConstants.VLAN_INTERFACE_INGRESS_TABLE); + writeTransaction, matches, ifState.getIfIndex(), NwConstants.VLAN_INTERFACE_INGRESS_TABLE); } for (BoundServices boundService : allServices) { if (!boundService.equals(highestPriorityBoundService)) { - FlowBasedServicesUtils.installLPortDispatcherFlow(dpId, boundService, ifState.getName(), t, ifState.getIfIndex(), boundService.getServicePriority(), (short) (boundService.getServicePriority()+1)); + FlowBasedServicesUtils.installLPortDispatcherFlow(dpId, boundService, ifState.getName(), + writeTransaction, ifState.getIfIndex(), boundService.getServicePriority(), + (short) (boundService.getServicePriority() + 1)); } } - futures.add(t.submit()); + futures.add(writeTransaction.submit()); return futures; } - private static List> bindServiceOnVlan( - List allServices, - Interface ifState, DataBroker dataBroker) { + private static List> bindServiceOnVlan(List allServices, Interface ifState, + DataBroker dataBroker) { LOG.info("bind all ingress services for vlan port: {}", ifState.getName()); - List> futures = new ArrayList<>(); NodeConnectorId nodeConnectorId = FlowBasedServicesUtils.getNodeConnectorIdFromInterface(ifState); BigInteger dpId = IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId); - WriteTransaction t = dataBroker.newWriteOnlyTransaction(); - Collections.sort(allServices, - (serviceInfo1, serviceInfo2) -> serviceInfo1.getServicePriority().compareTo(serviceInfo2.getServicePriority())); + WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction(); + Collections.sort(allServices, (serviceInfo1, serviceInfo2) -> serviceInfo1.getServicePriority() + .compareTo(serviceInfo2.getServicePriority())); BoundServices highestPriority = allServices.remove(0); - short nextServiceIndex = (short) (allServices.size() > 0 ? allServices.get(0).getServicePriority() : highestPriority.getServicePriority() + 1); - FlowBasedServicesUtils.installLPortDispatcherFlow(dpId, highestPriority, ifState.getName(), t, ifState.getIfIndex(), NwConstants.DEFAULT_SERVICE_INDEX, nextServiceIndex); + short nextServiceIndex = (short) (allServices.size() > 0 ? allServices.get(0).getServicePriority() + : highestPriority.getServicePriority() + 1); + FlowBasedServicesUtils.installLPortDispatcherFlow(dpId, highestPriority, ifState.getName(), writeTransaction, + ifState.getIfIndex(), NwConstants.DEFAULT_SERVICE_INDEX, nextServiceIndex); BoundServices prev = null; for (BoundServices boundService : allServices) { - if (prev!=null) { - FlowBasedServicesUtils.installLPortDispatcherFlow(dpId, prev, ifState.getName(), t, ifState.getIfIndex(), prev.getServicePriority(), boundService.getServicePriority()); + if (prev != null) { + FlowBasedServicesUtils.installLPortDispatcherFlow(dpId, prev, ifState.getName(), writeTransaction, + ifState.getIfIndex(), prev.getServicePriority(), boundService.getServicePriority()); } prev = boundService; } - if (prev!=null) { - FlowBasedServicesUtils.installLPortDispatcherFlow(dpId, prev, ifState.getName(), t, ifState.getIfIndex(), prev.getServicePriority(), (short) (prev.getServicePriority()+1)); + if (prev != null) { + FlowBasedServicesUtils.installLPortDispatcherFlow(dpId, prev, ifState.getName(), writeTransaction, + ifState.getIfIndex(), prev.getServicePriority(), (short) (prev.getServicePriority() + 1)); } - futures.add(t.submit()); + List> futures = new ArrayList<>(); + futures.add(writeTransaction.submit()); return futures; - } - -} \ No newline at end of file +} diff --git a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/state/helpers/FlowBasedIngressServicesStateUnbindHelper.java b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/state/helpers/FlowBasedIngressServicesStateUnbindHelper.java index 89c08b3b8..03efdf3c2 100644 --- a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/state/helpers/FlowBasedIngressServicesStateUnbindHelper.java +++ b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/state/helpers/FlowBasedIngressServicesStateUnbindHelper.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * Copyright (c) 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, @@ -29,10 +29,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeCon import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class FlowBasedIngressServicesStateUnbindHelper implements FlowBasedServicesStateRemovable{ +public class FlowBasedIngressServicesStateUnbindHelper implements FlowBasedServicesStateRemovable { private static final Logger LOG = LoggerFactory.getLogger(FlowBasedIngressServicesStateUnbindHelper.class); - private InterfacemgrProvider interfaceMgrProvider; + private final InterfacemgrProvider interfaceMgrProvider; private static volatile FlowBasedServicesStateRemovable flowBasedIngressServicesStateRemovable; private FlowBasedIngressServicesStateUnbindHelper(InterfacemgrProvider interfaceMgrProvider) { @@ -43,7 +43,8 @@ public class FlowBasedIngressServicesStateUnbindHelper implements FlowBasedServi if (flowBasedIngressServicesStateRemovable == null) { synchronized (FlowBasedIngressServicesStateUnbindHelper.class) { if (flowBasedIngressServicesStateRemovable == null) { - flowBasedIngressServicesStateRemovable = new FlowBasedIngressServicesStateUnbindHelper(interfaceMgrProvider); + flowBasedIngressServicesStateRemovable = new FlowBasedIngressServicesStateUnbindHelper( + interfaceMgrProvider); } } } @@ -60,15 +61,17 @@ public class FlowBasedIngressServicesStateUnbindHelper implements FlowBasedServi flowBasedIngressServicesStateRemovable = null; } + @Override public List> unbindServicesFromInterface(Interface ifaceState) { - if(ifaceState.getType() == null) { + if (ifaceState.getType() == null) { return null; } List> futures = new ArrayList<>(); LOG.info("unbind all ingress services on interface {}", ifaceState.getName()); DataBroker dataBroker = interfaceMgrProvider.getDataBroker(); - ServicesInfo servicesInfo = FlowBasedServicesUtils.getServicesInfoForInterface(ifaceState.getName(), ServiceModeIngress.class, dataBroker); + ServicesInfo servicesInfo = FlowBasedServicesUtils.getServicesInfoForInterface(ifaceState.getName(), + ServiceModeIngress.class, dataBroker); if (servicesInfo == null) { LOG.trace("service info is null for interface {}", ifaceState.getName()); return futures; @@ -82,60 +85,58 @@ public class FlowBasedIngressServicesStateUnbindHelper implements FlowBasedServi if (L2vlan.class.equals(ifaceState.getType())) { return unbindServiceOnVlan(allServices, ifaceState, ifaceState.getIfIndex(), dataBroker); - } else if (Tunnel.class.equals(ifaceState.getType())){ + } else if (Tunnel.class.equals(ifaceState.getType())) { return unbindServiceOnTunnel(allServices, ifaceState, ifaceState.getIfIndex(), dataBroker); } return futures; } - private static List> unbindServiceOnTunnel( - List allServices, - Interface iface, + private static List> unbindServiceOnTunnel(List allServices, Interface iface, Integer ifIndex, DataBroker dataBroker) { List> futures = new ArrayList<>(); - WriteTransaction t = dataBroker.newWriteOnlyTransaction(); + WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction(); List ofportIds = iface.getLowerLayerIf(); NodeConnectorId nodeConnectorId = new NodeConnectorId(ofportIds.get(0)); - if(nodeConnectorId == null){ + if (nodeConnectorId == null) { return futures; } BoundServices highestPriorityBoundService = FlowBasedServicesUtils.getHighestPriorityService(allServices); BigInteger dpId = IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId); - FlowBasedServicesUtils.removeIngressFlow(iface.getName(), highestPriorityBoundService, dpId, t); + FlowBasedServicesUtils.removeIngressFlow(iface.getName(), highestPriorityBoundService, dpId, writeTransaction); for (BoundServices boundService : allServices) { if (!boundService.equals(highestPriorityBoundService)) { - FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, iface.getName(), boundService, t, boundService.getServicePriority()); + FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, iface.getName(), boundService, writeTransaction, + boundService.getServicePriority()); } } - futures.add(t.submit()); + futures.add(writeTransaction.submit()); return futures; } - private static List> unbindServiceOnVlan( - List allServices, Interface ifaceState, - Integer ifIndex, DataBroker dataBroker) { + private static List> unbindServiceOnVlan(List allServices, + Interface ifaceState, Integer ifIndex, DataBroker dataBroker) { List> futures = new ArrayList<>(); - WriteTransaction t = dataBroker.newWriteOnlyTransaction(); + WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction(); List ofportIds = ifaceState.getLowerLayerIf(); NodeConnectorId nodeConnectorId = new NodeConnectorId(ofportIds.get(0)); - if(nodeConnectorId == null){ + if (nodeConnectorId == null) { return futures; } BigInteger dpId = IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId); - Collections.sort(allServices, - (serviceInfo1, serviceInfo2) -> serviceInfo1.getServicePriority().compareTo(serviceInfo2.getServicePriority())); + Collections.sort(allServices, (serviceInfo1, serviceInfo2) -> serviceInfo1.getServicePriority() + .compareTo(serviceInfo2.getServicePriority())); BoundServices highestPriority = allServices.remove(0); - FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, ifaceState.getName(), highestPriority, t, NwConstants.DEFAULT_SERVICE_INDEX); + FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, ifaceState.getName(), highestPriority, writeTransaction, + NwConstants.DEFAULT_SERVICE_INDEX); for (BoundServices boundService : allServices) { - FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, ifaceState.getName(), boundService, t, boundService.getServicePriority()); + FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, ifaceState.getName(), boundService, writeTransaction, + boundService.getServicePriority()); } - futures.add(t.submit()); + futures.add(writeTransaction.submit()); return futures; - } - } diff --git a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/utilities/ActionConverterUtil.java b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/utilities/ActionConverterUtil.java index 824997fc2..9be6595d5 100644 --- a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/utilities/ActionConverterUtil.java +++ b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/utilities/ActionConverterUtil.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * Copyright (c) 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, @@ -54,97 +54,122 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class ActionConverterUtil { - private static final Logger LOG = LoggerFactory.getLogger(ActionConverterUtil.class); - private static final Map, Class> serviceActionToOfActionMap = new HashMap(); - private static final String buildMethod = "build"; - private static final String augmentationMethod = "getAugmentation"; - private static final String getImplMethod = "getImplementedInterface"; - static { - serviceActionToOfActionMap.put(ServiceBindingNxActionConntrackApplyActionsCase.class, NxActionConntrackNodesNodeTableFlowApplyActionsCaseBuilder.class); - serviceActionToOfActionMap.put(ServiceBindingNxActionLearnApplyActionsCase.class, NxActionLearnNodesNodeTableFlowApplyActionsCaseBuilder.class); - serviceActionToOfActionMap.put(ServiceBindingNxActionMultipathApplyActionsCase.class, NxActionMultipathNodesNodeTableFlowApplyActionsCaseBuilder.class); - serviceActionToOfActionMap.put(ServiceBindingNxActionOutputRegApplyActionsCase.class, NxActionOutputRegNodesNodeTableFlowApplyActionsCaseBuilder.class); - serviceActionToOfActionMap.put(ServiceBindingNxActionPopNshApplyActionsCase.class, NxActionPopNshNodesNodeTableFlowApplyActionsCaseBuilder.class); - serviceActionToOfActionMap.put(ServiceBindingNxActionPushNshApplyActionsCase.class, NxActionPushNshNodesNodeTableFlowApplyActionsCaseBuilder.class); - serviceActionToOfActionMap.put(ServiceBindingNxActionRegLoadApplyActionsCase.class, NxActionRegLoadNodesNodeTableFlowApplyActionsCaseBuilder.class); - serviceActionToOfActionMap.put(ServiceBindingNxActionRegMoveApplyActionsCase.class, NxActionRegMoveNodesNodeTableFlowApplyActionsCaseBuilder.class); - serviceActionToOfActionMap.put(ServiceBindingNxActionResubmitApplyActionsCase.class, NxActionResubmitNodesNodeTableFlowApplyActionsCaseBuilder.class); - serviceActionToOfActionMap.put(ServiceBindingNxActionConntrackWriteActionsCase.class, NxActionConntrackNodesNodeTableFlowWriteActionsCaseBuilder.class); - serviceActionToOfActionMap.put(ServiceBindingNxActionLearnWriteActionsCase.class, NxActionLearnNodesNodeTableFlowWriteActionsCaseBuilder.class); - serviceActionToOfActionMap.put(ServiceBindingNxActionMultipathWriteActionsCase.class, NxActionMultipathNodesNodeTableFlowWriteActionsCaseBuilder.class); - serviceActionToOfActionMap.put(ServiceBindingNxActionOutputRegWriteActionsCase.class, NxActionOutputRegNodesNodeTableFlowWriteActionsCaseBuilder.class); - serviceActionToOfActionMap.put(ServiceBindingNxActionPopNshWriteActionsCase.class, NxActionPopNshNodesNodeTableFlowWriteActionsCaseBuilder.class); - serviceActionToOfActionMap.put(ServiceBindingNxActionPushNshWriteActionsCase.class, NxActionPushNshNodesNodeTableFlowWriteActionsCaseBuilder.class); - serviceActionToOfActionMap.put(ServiceBindingNxActionRegLoadWriteActionsCase.class, NxActionRegLoadNodesNodeTableFlowWriteActionsCaseBuilder.class); - serviceActionToOfActionMap.put(ServiceBindingNxActionRegMoveWriteActionsCase.class, NxActionRegMoveNodesNodeTableFlowWriteActionsCaseBuilder.class); - serviceActionToOfActionMap.put(ServiceBindingNxActionResubmitWriteActionsCase.class, NxActionResubmitNodesNodeTableFlowWriteActionsCaseBuilder.class); - } + private static final Logger LOG = LoggerFactory.getLogger(ActionConverterUtil.class); + private static final Map, Class> SERVICE_ACTION_TO_OF_ACTION_MAP = new HashMap<>(); + private static final String BUILD_METHOD = "build"; + private static final String AUGMENTATION_METHOD = "getAugmentation"; + private static final String GET_IMPL_METHOD = "getImplementedInterface"; - public static List convertServiceActionToFlowAction - (List inActionList) { - List outActionList = new ArrayList<>(); - if (inActionList != null) { - for (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action inAction : inActionList) { - outActionList.add( - new org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder() - .setAction(convertServiceActionToFlowAction(inAction.getAction())) - .setKey(inAction.getKey()) - .build()); - } + static { + SERVICE_ACTION_TO_OF_ACTION_MAP.put(ServiceBindingNxActionConntrackApplyActionsCase.class, + NxActionConntrackNodesNodeTableFlowApplyActionsCaseBuilder.class); + SERVICE_ACTION_TO_OF_ACTION_MAP.put(ServiceBindingNxActionLearnApplyActionsCase.class, + NxActionLearnNodesNodeTableFlowApplyActionsCaseBuilder.class); + SERVICE_ACTION_TO_OF_ACTION_MAP.put(ServiceBindingNxActionMultipathApplyActionsCase.class, + NxActionMultipathNodesNodeTableFlowApplyActionsCaseBuilder.class); + SERVICE_ACTION_TO_OF_ACTION_MAP.put(ServiceBindingNxActionOutputRegApplyActionsCase.class, + NxActionOutputRegNodesNodeTableFlowApplyActionsCaseBuilder.class); + SERVICE_ACTION_TO_OF_ACTION_MAP.put(ServiceBindingNxActionPopNshApplyActionsCase.class, + NxActionPopNshNodesNodeTableFlowApplyActionsCaseBuilder.class); + SERVICE_ACTION_TO_OF_ACTION_MAP.put(ServiceBindingNxActionPushNshApplyActionsCase.class, + NxActionPushNshNodesNodeTableFlowApplyActionsCaseBuilder.class); + SERVICE_ACTION_TO_OF_ACTION_MAP.put(ServiceBindingNxActionRegLoadApplyActionsCase.class, + NxActionRegLoadNodesNodeTableFlowApplyActionsCaseBuilder.class); + SERVICE_ACTION_TO_OF_ACTION_MAP.put(ServiceBindingNxActionRegMoveApplyActionsCase.class, + NxActionRegMoveNodesNodeTableFlowApplyActionsCaseBuilder.class); + SERVICE_ACTION_TO_OF_ACTION_MAP.put(ServiceBindingNxActionResubmitApplyActionsCase.class, + NxActionResubmitNodesNodeTableFlowApplyActionsCaseBuilder.class); + SERVICE_ACTION_TO_OF_ACTION_MAP.put(ServiceBindingNxActionConntrackWriteActionsCase.class, + NxActionConntrackNodesNodeTableFlowWriteActionsCaseBuilder.class); + SERVICE_ACTION_TO_OF_ACTION_MAP.put(ServiceBindingNxActionLearnWriteActionsCase.class, + NxActionLearnNodesNodeTableFlowWriteActionsCaseBuilder.class); + SERVICE_ACTION_TO_OF_ACTION_MAP.put(ServiceBindingNxActionMultipathWriteActionsCase.class, + NxActionMultipathNodesNodeTableFlowWriteActionsCaseBuilder.class); + SERVICE_ACTION_TO_OF_ACTION_MAP.put(ServiceBindingNxActionOutputRegWriteActionsCase.class, + NxActionOutputRegNodesNodeTableFlowWriteActionsCaseBuilder.class); + SERVICE_ACTION_TO_OF_ACTION_MAP.put(ServiceBindingNxActionPopNshWriteActionsCase.class, + NxActionPopNshNodesNodeTableFlowWriteActionsCaseBuilder.class); + SERVICE_ACTION_TO_OF_ACTION_MAP.put(ServiceBindingNxActionPushNshWriteActionsCase.class, + NxActionPushNshNodesNodeTableFlowWriteActionsCaseBuilder.class); + SERVICE_ACTION_TO_OF_ACTION_MAP.put(ServiceBindingNxActionRegLoadWriteActionsCase.class, + NxActionRegLoadNodesNodeTableFlowWriteActionsCaseBuilder.class); + SERVICE_ACTION_TO_OF_ACTION_MAP.put(ServiceBindingNxActionRegMoveWriteActionsCase.class, + NxActionRegMoveNodesNodeTableFlowWriteActionsCaseBuilder.class); + SERVICE_ACTION_TO_OF_ACTION_MAP.put(ServiceBindingNxActionResubmitWriteActionsCase.class, + NxActionResubmitNodesNodeTableFlowWriteActionsCaseBuilder.class); } - return outActionList; - } - public static Action convertServiceActionToFlowAction(Action inAction) { - Class ofActionClass = serviceActionToOfActionMap.get(inAction.getImplementedInterface()); - if (ofActionClass != null) { - try { - Method build = ofActionClass.getDeclaredMethod(buildMethod); - Object ofActionObj = ofActionClass.newInstance(); - ofActionObj = build.invoke(copy(inAction, ofActionObj)); - LOG.info("Converted {} action to {} action", inAction.getImplementedInterface(), - ((Action)ofActionObj).getImplementedInterface()); - inAction = (Action)ofActionObj; - } catch (InstantiationException e) { - LOG.error("Failed to instantiate OF action class {}", ofActionClass); - } catch (IllegalAccessException e) { - LOG.error("Cannot access some fields in {}", ofActionClass); - } catch (NoSuchMethodException e) { - LOG.error("Method build does not exist in {}", ofActionClass); - } catch (InvocationTargetException e) { - LOG.error("Method build invocation failed in {}", ofActionClass); - } + public static List convertServiceActionToFlowAction( + List inActionList) { + List outActionList = new ArrayList<>(); + if (inActionList != null) { + for (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112 + .action.list.Action inAction : inActionList) { + outActionList.add( + new org.opendaylight.yang.gen.v1.urn.opendaylight + .action.types.rev131112.action.list.ActionBuilder() + .setAction(convertServiceActionToFlowAction(inAction.getAction())) + .setKey(inAction.getKey()).build()); + } + } + return outActionList; } - return inAction; - } - private static Object copy(Object src, Object dest) { - Method[] gettersAndSetters = src.getClass().getDeclaredMethods(); - for (int i = 0; i < gettersAndSetters.length; i++) { - String methodName = gettersAndSetters[i].getName(); - gettersAndSetters[i].setAccessible(true); - try{ - if(methodName.equals(augmentationMethod) || methodName.equals(getImplMethod)) { - continue; + public static Action convertServiceActionToFlowAction(Action inAction) { + Class ofActionClass = SERVICE_ACTION_TO_OF_ACTION_MAP.get(inAction.getImplementedInterface()); + if (ofActionClass != null) { + try { + Method build = ofActionClass.getDeclaredMethod(BUILD_METHOD); + Object ofActionObj = ofActionClass.newInstance(); + ofActionObj = build.invoke(copy(inAction, ofActionObj)); + LOG.info("Converted {} action to {} action", inAction.getImplementedInterface(), + ((Action) ofActionObj).getImplementedInterface()); + inAction = (Action) ofActionObj; + } catch (InstantiationException e) { + LOG.error("Failed to instantiate OF action class {}", ofActionClass); + } catch (IllegalAccessException e) { + LOG.error("Cannot access some fields in {}", ofActionClass); + } catch (NoSuchMethodException e) { + LOG.error("Method build does not exist in {}", ofActionClass); + } catch (InvocationTargetException e) { + LOG.error("Method build invocation failed in {}", ofActionClass); + } } - if(methodName.startsWith("get")){ - dest = dest.getClass().getMethod(methodName.replaceFirst("get", "set"), gettersAndSetters[i].getReturnType()) - .invoke(dest, gettersAndSetters[i].invoke(src, null)); - }else if(methodName.startsWith("is") ){ - dest = dest.getClass().getMethod(methodName.replaceFirst("is", "set"), gettersAndSetters[i].getReturnType()) - .invoke(dest, gettersAndSetters[i].invoke(src, null)); + return inAction; + } + + private static Object copy(Object src, Object dest) { + Method[] gettersAndSetters = src.getClass().getDeclaredMethods(); + for (Method gettersAndSetter : gettersAndSetters) { + String methodName = gettersAndSetter.getName(); + gettersAndSetter.setAccessible(true); + try { + if (methodName.equals(AUGMENTATION_METHOD) || methodName.equals(GET_IMPL_METHOD)) { + continue; + } + if (methodName.startsWith("get")) { + dest = dest.getClass() + .getMethod(methodName.replaceFirst("get", "set"), gettersAndSetter.getReturnType()) + .invoke(dest, gettersAndSetter.invoke(src, null)); + } else if (methodName.startsWith("is")) { + dest = dest.getClass() + .getMethod(methodName.replaceFirst("is", "set"), gettersAndSetter.getReturnType()) + .invoke(dest, gettersAndSetter.invoke(src, null)); + } + } catch (NoSuchMethodException e) { + LOG.error("Method {} does not exist in {}", methodName, src.getClass(), e); + } catch (IllegalArgumentException e) { + LOG.error("Method {} invocation failed in {} due to illegal argument.", methodName, dest.getClass(), e); + } catch (InvocationTargetException e) { + LOG.error("Method {} invocation failed in {}", methodName, dest.getClass(), e); + } catch (IllegalAccessException e) { + LOG.error("Cannot access method {} in {}", methodName, dest.getClass(), e); + } } - }catch (NoSuchMethodException e) { - LOG.error("Method {} does not exist in {}", methodName, src.getClass(), e); - }catch (IllegalArgumentException e) { - LOG.error("Method {} invocation failed in {} due to illegal argument.", methodName, dest.getClass(), e); - } catch (InvocationTargetException e) { - LOG.error("Method {} invocation failed in {}", methodName, dest.getClass(), e); - } catch (IllegalAccessException e) { - LOG.error("Cannot access method {} in {}", methodName, dest.getClass(), e); - } + return dest; } - return dest; - } } diff --git a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/utilities/FlowBasedServicesUtils.java b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/utilities/FlowBasedServicesUtils.java index e85ead49a..76428635f 100644 --- a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/utilities/FlowBasedServicesUtils.java +++ b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/utilities/FlowBasedServicesUtils.java @@ -13,18 +13,17 @@ import java.math.BigInteger; import java.util.ArrayList; import java.util.Collections; import java.util.List; - import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.genius.interfacemanager.IfmConstants; import org.opendaylight.genius.interfacemanager.IfmUtil; import org.opendaylight.genius.interfacemanager.commons.InterfaceManagerCommonUtils; -import org.opendaylight.genius.mdsalutil.MatchInfo; -import org.opendaylight.genius.mdsalutil.MatchInfoBase; import org.opendaylight.genius.mdsalutil.ActionInfo; import org.opendaylight.genius.mdsalutil.InstructionInfo; import org.opendaylight.genius.mdsalutil.MDSALUtil; +import org.opendaylight.genius.mdsalutil.MatchInfo; +import org.opendaylight.genius.mdsalutil.MatchInfoBase; import org.opendaylight.genius.mdsalutil.MetaDataUtil; import org.opendaylight.genius.mdsalutil.NwConstants; import org.opendaylight.genius.mdsalutil.actions.ActionDrop; @@ -75,47 +74,50 @@ import org.slf4j.LoggerFactory; public class FlowBasedServicesUtils { private static final Logger LOG = LoggerFactory.getLogger(FlowBasedServicesUtils.class); - public enum ServiceMode { - INGRESS, - EGRESS + public enum ServiceMode { + INGRESS, EGRESS } - public static final ImmutableBiMap> SERVICE_MODE_MAP = - new ImmutableBiMap.Builder>() - .put(ServiceMode.EGRESS, ServiceModeEgress.class) - .put(ServiceMode.INGRESS, ServiceModeIngress.class) + public static final ImmutableBiMap> + SERVICE_MODE_MAP = new ImmutableBiMap.Builder>() + .put(ServiceMode.EGRESS, ServiceModeEgress.class).put(ServiceMode.INGRESS, ServiceModeIngress.class) .build(); - public static ServicesInfo getServicesInfoForInterface(String interfaceName, Class serviceMode, - DataBroker dataBroker) { - ServicesInfoKey servicesInfoKey = new ServicesInfoKey(interfaceName,serviceMode); - InstanceIdentifier.InstanceIdentifierBuilder servicesInfoIdentifierBuilder = - InstanceIdentifier.builder(ServiceBindings.class).child(ServicesInfo.class, servicesInfoKey); - return IfmUtil.read(LogicalDatastoreType.CONFIGURATION, servicesInfoIdentifierBuilder.build(), - dataBroker).orNull(); + public static ServicesInfo getServicesInfoForInterface(String interfaceName, + Class serviceMode, DataBroker dataBroker) { + ServicesInfoKey servicesInfoKey = new ServicesInfoKey(interfaceName, serviceMode); + InstanceIdentifier.InstanceIdentifierBuilder servicesInfoIdentifierBuilder = InstanceIdentifier + .builder(ServiceBindings.class).child(ServicesInfo.class, servicesInfoKey); + return IfmUtil.read(LogicalDatastoreType.CONFIGURATION, servicesInfoIdentifierBuilder.build(), dataBroker) + .orNull(); } public static NodeConnectorId getNodeConnectorIdFromInterface(String interfaceName, DataBroker dataBroker) { - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifState = - InterfaceManagerCommonUtils.getInterfaceStateFromOperDS(interfaceName, dataBroker); - if(ifState != null) { + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang + .ietf.interfaces.rev140508.interfaces.state.Interface ifState = InterfaceManagerCommonUtils + .getInterfaceStateFromOperDS(interfaceName, dataBroker); + if (ifState != null) { List ofportIds = ifState.getLowerLayerIf(); return new NodeConnectorId(ofportIds.get(0)); } return null; } - public static NodeConnectorId getNodeConnectorIdFromInterface(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifState) { - if(ifState != null) { + public static NodeConnectorId getNodeConnectorIdFromInterface( + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang + .ietf.interfaces.rev140508.interfaces.state.Interface ifState) { + if (ifState != null) { List ofportIds = ifState.getLowerLayerIf(); return new NodeConnectorId(ofportIds.get(0)); } return null; } - public static BigInteger getDpnIdFromInterface(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifState) { + public static BigInteger getDpnIdFromInterface( + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang + .ietf.interfaces.rev140508.interfaces.state.Interface ifState) { NodeConnectorId nodeConnectorId = null; - if(ifState != null) { + if (ifState != null) { List ofportIds = ifState.getLowerLayerIf(); nodeConnectorId = new NodeConnectorId(ofportIds.get(0)); } @@ -127,7 +129,7 @@ public class FlowBasedServicesUtils { matches.add(new MatchInPort(dpId, portNo)); int vlanId = 0; IfL2vlan l2vlan = iface.getAugmentation(IfL2vlan.class); - if(l2vlan != null && l2vlan.getL2vlanMode() != IfL2vlan.L2vlanMode.Transparent){ + if (l2vlan != null && l2vlan.getL2vlanMode() != IfL2vlan.L2vlanMode.Transparent) { vlanId = l2vlan.getVlanId() == null ? 0 : l2vlan.getVlanId().getValue(); } if (vlanId > 0) { @@ -142,11 +144,10 @@ public class FlowBasedServicesUtils { return matches; } - public static List getMatchInfoForDispatcherTable(BigInteger dpId, - int interfaceTag, short servicePriority) { + public static List getMatchInfoForDispatcherTable(BigInteger dpId, int interfaceTag, + short servicePriority) { List matches = new ArrayList<>(); - matches.add(new MatchMetadata( - MetaDataUtil.getMetaDataForLPortDispatcher(interfaceTag, servicePriority), + matches.add(new MatchMetadata(MetaDataUtil.getMetaDataForLPortDispatcher(interfaceTag, servicePriority), MetaDataUtil.getMetaDataMaskForLPortDispatcher())); return matches; } @@ -158,35 +159,34 @@ public class FlowBasedServicesUtils { return matches; } - public static void installInterfaceIngressFlow(BigInteger dpId, Interface iface, - BoundServices boundServiceNew, - WriteTransaction t, - List matches, int lportTag, short tableId) { + public static void installInterfaceIngressFlow(BigInteger dpId, Interface iface, BoundServices boundServiceNew, + WriteTransaction writeTransaction, List matches, int lportTag, short tableId) { List instructions = boundServiceNew.getAugmentation(StypeOpenflow.class).getInstruction(); int serviceInstructionsSize = instructions.size(); List instructionSet = new ArrayList<>(); int vlanId = 0; IfL2vlan l2vlan = iface.getAugmentation(IfL2vlan.class); - if(l2vlan != null && l2vlan.getVlanId() != null){ + if (l2vlan != null && l2vlan.getVlanId() != null) { vlanId = l2vlan.getVlanId().getValue(); } if (vlanId != 0) { - // incrementing instructionSize and using it as actionKey. Because it won't clash with any other instructions + // incrementing instructionSize and using it as actionKey. Because + // it won't clash with any other instructions int actionKey = ++serviceInstructionsSize; instructionSet.add(MDSALUtil.buildAndGetPopVlanActionInstruction(actionKey, ++serviceInstructionsSize)); } if (lportTag != 0L) { BigInteger[] metadataValues = IfmUtil.mergeOpenflowMetadataWriteInstructions(instructions); - short sIndex = boundServiceNew.getServicePriority(); - BigInteger metadata = MetaDataUtil.getMetaDataForLPortDispatcher(lportTag, - ++sIndex, metadataValues[0], isExternal(iface)); + short index = boundServiceNew.getServicePriority(); + BigInteger metadata = MetaDataUtil.getMetaDataForLPortDispatcher(lportTag, ++index, metadataValues[0], + isExternal(iface)); BigInteger metadataMask = MetaDataUtil.getMetaDataMaskForLPortDispatcher( - MetaDataUtil.METADATA_MASK_SERVICE_INDEX, - MetaDataUtil.METADATA_MASK_LPORT_TAG_SH_FLAG, metadataValues[1]); - instructionSet.add(MDSALUtil.buildAndGetWriteMetadaInstruction(metadata, metadataMask, - ++serviceInstructionsSize)); + MetaDataUtil.METADATA_MASK_SERVICE_INDEX, MetaDataUtil.METADATA_MASK_LPORT_TAG_SH_FLAG, + metadataValues[1]); + instructionSet.add( + MDSALUtil.buildAndGetWriteMetadaInstruction(metadata, metadataMask, ++serviceInstructionsSize)); } if (instructions != null && !instructions.isEmpty()) { @@ -196,44 +196,44 @@ public class FlowBasedServicesUtils { continue; } else if (info.getInstruction() instanceof WriteActionsCase) { info = MDSALUtil.buildWriteActionsInstruction(ActionConverterUtil.convertServiceActionToFlowAction( - ((WriteActionsCase)info.getInstruction()).getWriteActions().getAction())); + ((WriteActionsCase) info.getInstruction()).getWriteActions().getAction())); } else if (info.getInstruction() instanceof ApplyActionsCase) { info = MDSALUtil.buildApplyActionsInstruction(ActionConverterUtil.convertServiceActionToFlowAction( - ((ApplyActionsCase)info.getInstruction()).getApplyActions().getAction())); + ((ApplyActionsCase) info.getInstruction()).getApplyActions().getAction())); } instructionSet.add(info); } } String serviceRef = boundServiceNew.getServiceName(); - String flowRef = getFlowRef(dpId, NwConstants.VLAN_INTERFACE_INGRESS_TABLE, iface.getName(), - boundServiceNew, boundServiceNew.getServicePriority()); + String flowRef = getFlowRef(dpId, NwConstants.VLAN_INTERFACE_INGRESS_TABLE, iface.getName(), boundServiceNew, + boundServiceNew.getServicePriority()); StypeOpenflow stypeOpenflow = boundServiceNew.getAugmentation(StypeOpenflow.class); - Flow ingressFlow = MDSALUtil.buildFlowNew(tableId, flowRef, - stypeOpenflow.getFlowPriority(), serviceRef, 0, 0, + Flow ingressFlow = MDSALUtil.buildFlowNew(tableId, flowRef, stypeOpenflow.getFlowPriority(), serviceRef, 0, 0, stypeOpenflow.getFlowCookie(), matches, instructionSet); - installFlow(dpId, ingressFlow, t); + installFlow(dpId, ingressFlow, writeTransaction); } - public static void installFlow(BigInteger dpId, Flow flow, WriteTransaction t) { + public static void installFlow(BigInteger dpId, Flow flow, WriteTransaction writeTransaction) { FlowKey flowKey = new FlowKey(new FlowId(flow.getId())); Node nodeDpn = buildInventoryDpnNode(dpId); InstanceIdentifier flowInstanceId = InstanceIdentifier.builder(Nodes.class) .child(Node.class, nodeDpn.getKey()).augmentation(FlowCapableNode.class) - .child(Table.class, new TableKey(flow.getTableId())).child(Flow.class,flowKey).build(); + .child(Table.class, new TableKey(flow.getTableId())).child(Flow.class, flowKey).build(); - t.put(LogicalDatastoreType.CONFIGURATION, flowInstanceId, flow, true); + writeTransaction.put(LogicalDatastoreType.CONFIGURATION, flowInstanceId, flow, true); } - public static void removeFlow(String flowRef, BigInteger dpId, WriteTransaction t) { + public static void removeFlow(String flowRef, BigInteger dpId, WriteTransaction writeTransaction) { LOG.debug("Removing Ingress Flows"); FlowKey flowKey = new FlowKey(new FlowId(flowRef)); Node nodeDpn = buildInventoryDpnNode(dpId); InstanceIdentifier flowInstanceId = InstanceIdentifier.builder(Nodes.class) .child(Node.class, nodeDpn.getKey()).augmentation(FlowCapableNode.class) - .child(Table.class, new TableKey(NwConstants.VLAN_INTERFACE_INGRESS_TABLE)).child(Flow.class, flowKey).build(); + .child(Table.class, new TableKey(NwConstants.VLAN_INTERFACE_INGRESS_TABLE)).child(Flow.class, flowKey) + .build(); - t.delete(LogicalDatastoreType.CONFIGURATION, flowInstanceId); + writeTransaction.delete(LogicalDatastoreType.CONFIGURATION, flowInstanceId); } private static Node buildInventoryDpnNode(BigInteger dpnId) { @@ -244,17 +244,20 @@ public class FlowBasedServicesUtils { } public static void installLPortDispatcherFlow(BigInteger dpId, BoundServices boundService, String interfaceName, - WriteTransaction t, int interfaceTag, short currentServiceIndex, short nextServiceIndex) { + WriteTransaction writeTransaction, int interfaceTag, short currentServiceIndex, short nextServiceIndex) { LOG.debug("Installing LPort Dispatcher Flow {}, {}", dpId, interfaceName); String serviceRef = boundService.getServiceName(); - List matches = FlowBasedServicesUtils.getMatchInfoForDispatcherTable(dpId, interfaceTag, currentServiceIndex); + List matches = FlowBasedServicesUtils.getMatchInfoForDispatcherTable(dpId, interfaceTag, + currentServiceIndex); - // Get the metadata and mask from the service's write metadata instruction + // Get the metadata and mask from the service's write metadata + // instruction StypeOpenflow stypeOpenFlow = boundService.getAugmentation(StypeOpenflow.class); List serviceInstructions = stypeOpenFlow.getInstruction(); int instructionSize = serviceInstructions.size(); BigInteger[] metadataValues = IfmUtil.mergeOpenflowMetadataWriteInstructions(serviceInstructions); - BigInteger metadata = MetaDataUtil.getMetaDataForLPortDispatcher(interfaceTag, nextServiceIndex, metadataValues[0]); + BigInteger metadata = MetaDataUtil.getMetaDataForLPortDispatcher(interfaceTag, nextServiceIndex, + metadataValues[0]); BigInteger metadataMask = MetaDataUtil.getWriteMetaDataMaskForDispatcherTable(); // build the final instruction for LPort Dispatcher table flow entry @@ -267,50 +270,61 @@ public class FlowBasedServicesUtils { continue; } else if (info.getInstruction() instanceof WriteActionsCase) { info = MDSALUtil.buildWriteActionsInstruction(ActionConverterUtil.convertServiceActionToFlowAction( - ((WriteActionsCase)info.getInstruction()).getWriteActions().getAction())); + ((WriteActionsCase) info.getInstruction()).getWriteActions().getAction())); } else if (info.getInstruction() instanceof ApplyActionsCase) { info = MDSALUtil.buildApplyActionsInstruction(ActionConverterUtil.convertServiceActionToFlowAction( - ((ApplyActionsCase)info.getInstruction()).getApplyActions().getAction())); + ((ApplyActionsCase) info.getInstruction()).getApplyActions().getAction())); } instructions.add(info); } } // build the flow and install it - String flowRef = getFlowRef(dpId, NwConstants.LPORT_DISPATCHER_TABLE, interfaceName, boundService, currentServiceIndex); + String flowRef = getFlowRef(dpId, NwConstants.LPORT_DISPATCHER_TABLE, interfaceName, boundService, + currentServiceIndex); Flow ingressFlow = MDSALUtil.buildFlowNew(NwConstants.LPORT_DISPATCHER_TABLE, flowRef, - boundService.getServicePriority(), serviceRef, 0, 0, stypeOpenFlow.getFlowCookie(), matches, instructions); - installFlow(dpId, ingressFlow, t); + boundService.getServicePriority(), serviceRef, 0, 0, stypeOpenFlow.getFlowCookie(), matches, + instructions); + installFlow(dpId, ingressFlow, writeTransaction); } public static void installEgressDispatcherFlows(BigInteger dpId, BoundServices boundService, String interfaceName, - WriteTransaction t, int interfaceTag, short currentServiceIndex, - short nextServiceIndex, Interface iface) { + WriteTransaction writeTransaction, int interfaceTag, short currentServiceIndex, short nextServiceIndex, + Interface iface) { LOG.debug("Installing Egress Dispatcher Flows {}, {}", dpId, interfaceName); - installEgressDispatcherFlow(dpId, boundService, interfaceName, t, interfaceTag, currentServiceIndex, nextServiceIndex); + installEgressDispatcherFlow(dpId, boundService, interfaceName, writeTransaction, interfaceTag, + currentServiceIndex, nextServiceIndex); - // Install Split Horizon drop flow only for the default egress service - this flow drops traffic targeted to external interfaces if they arrived + // Install Split Horizon drop flow only for the default egress service - + // this flow drops traffic targeted to external interfaces if they + // arrived // from an external interface (marked with the SH bit) - if (boundService.getServicePriority() == ServiceIndex.getIndex(NwConstants.DEFAULT_EGRESS_SERVICE_NAME, NwConstants.DEFAULT_EGRESS_SERVICE_INDEX)) { - installEgressDispatcherSplitHorizonFlow(dpId, boundService, interfaceName, t, interfaceTag, currentServiceIndex, iface); + if (boundService.getServicePriority() == ServiceIndex.getIndex(NwConstants.DEFAULT_EGRESS_SERVICE_NAME, + NwConstants.DEFAULT_EGRESS_SERVICE_INDEX)) { + installEgressDispatcherSplitHorizonFlow(dpId, boundService, interfaceName, writeTransaction, interfaceTag, + currentServiceIndex, iface); } } private static void installEgressDispatcherFlow(BigInteger dpId, BoundServices boundService, String interfaceName, - WriteTransaction t, int interfaceTag, short currentServiceIndex, short nextServiceIndex) { + WriteTransaction writeTransaction, int interfaceTag, short currentServiceIndex, short nextServiceIndex) { String serviceRef = boundService.getServiceName(); - List matches = FlowBasedServicesUtils.getMatchInfoForEgressDispatcherTable(interfaceTag, currentServiceIndex); + List matches = FlowBasedServicesUtils + .getMatchInfoForEgressDispatcherTable(interfaceTag, currentServiceIndex); - // Get the metadata and mask from the service's write metadata instruction + // Get the metadata and mask from the service's write metadata + // instruction StypeOpenflow stypeOpenFlow = boundService.getAugmentation(StypeOpenflow.class); List serviceInstructions = stypeOpenFlow.getInstruction(); int instructionSize = serviceInstructions.size(); // build the final instruction for LPort Dispatcher table flow entry List instructions = new ArrayList<>(); - if(boundService.getServicePriority() != ServiceIndex.getIndex(NwConstants.DEFAULT_EGRESS_SERVICE_NAME, NwConstants.DEFAULT_EGRESS_SERVICE_INDEX)) { + if (boundService.getServicePriority() != ServiceIndex.getIndex(NwConstants.DEFAULT_EGRESS_SERVICE_NAME, + NwConstants.DEFAULT_EGRESS_SERVICE_INDEX)) { BigInteger[] metadataValues = IfmUtil.mergeOpenflowMetadataWriteInstructions(serviceInstructions); - BigInteger metadata = MetaDataUtil.getMetaDataForLPortDispatcher(interfaceTag, nextServiceIndex, metadataValues[0]); + BigInteger metadata = MetaDataUtil.getMetaDataForLPortDispatcher(interfaceTag, nextServiceIndex, + metadataValues[0]); BigInteger metadataMask = MetaDataUtil.getWriteMetaDataMaskForDispatcherTable(); instructions.add(MDSALUtil.buildAndGetWriteMetadaInstruction(metadata, metadataMask, ++instructionSize)); instructions.add(MDSALUtil.buildAndGetSetReg6ActionInstruction(0, ++instructionSize, 0, 31, @@ -323,25 +337,28 @@ public class FlowBasedServicesUtils { continue; } else if (info.getInstruction() instanceof WriteActionsCase) { info = MDSALUtil.buildWriteActionsInstruction(ActionConverterUtil.convertServiceActionToFlowAction( - ((WriteActionsCase)info.getInstruction()).getWriteActions().getAction())); + ((WriteActionsCase) info.getInstruction()).getWriteActions().getAction())); } else if (info.getInstruction() instanceof ApplyActionsCase) { info = MDSALUtil.buildApplyActionsInstruction(ActionConverterUtil.convertServiceActionToFlowAction( - ((ApplyActionsCase)info.getInstruction()).getApplyActions().getAction())); + ((ApplyActionsCase) info.getInstruction()).getApplyActions().getAction())); } instructions.add(info); } } // build the flow and install it - String flowRef = getFlowRef(dpId, NwConstants.EGRESS_LPORT_DISPATCHER_TABLE, interfaceName, boundService, currentServiceIndex); + String flowRef = getFlowRef(dpId, NwConstants.EGRESS_LPORT_DISPATCHER_TABLE, interfaceName, boundService, + currentServiceIndex); Flow egressFlow = MDSALUtil.buildFlowNew(NwConstants.EGRESS_LPORT_DISPATCHER_TABLE, flowRef, - boundService.getServicePriority(), serviceRef, 0, 0, stypeOpenFlow.getFlowCookie(), matches, instructions); + boundService.getServicePriority(), serviceRef, 0, 0, stypeOpenFlow.getFlowCookie(), matches, + instructions); LOG.debug("Installing Egress Dispatcher Flow {}, {}", flowRef, interfaceName); - installFlow(dpId, egressFlow, t); + installFlow(dpId, egressFlow, writeTransaction); } - public static void installEgressDispatcherSplitHorizonFlow(BigInteger dpId, BoundServices boundService, String interfaceName, - WriteTransaction t, int interfaceTag, short currentServiceIndex, Interface iface) { + public static void installEgressDispatcherSplitHorizonFlow(BigInteger dpId, BoundServices boundService, + String interfaceName, WriteTransaction writeTransaction, int interfaceTag, short currentServiceIndex, + Interface iface) { // only install split horizon drop flows for external interfaces if (!isExternal(iface)) { return; @@ -351,152 +368,203 @@ public class FlowBasedServicesUtils { LOG.debug("Installing split horizon drop flow for external interface {} on dpId {}", interfaceName, dpId); } - BigInteger shFlagSet = BigInteger.ONE; // BigInteger.ONE is used for checking the Split-Horizon flag - StypeOpenflow stypeOpenFlow = boundService.getAugmentation(StypeOpenflow.class); - List shMatches = FlowBasedServicesUtils.getMatchInfoForEgressDispatcherTable(interfaceTag, currentServiceIndex); + BigInteger shFlagSet = BigInteger.ONE; // BigInteger.ONE is used for + // checking the Split-Horizon + // flag + List shMatches = FlowBasedServicesUtils.getMatchInfoForEgressDispatcherTable(interfaceTag, + currentServiceIndex); shMatches.add(new MatchMetadata(shFlagSet, MetaDataUtil.METADATA_MASK_SH_FLAG)); List shInstructions = new ArrayList<>(); List actionsInfos = new ArrayList<>(); actionsInfos.add(new ActionDrop()); shInstructions.add(new InstructionApplyActions(actionsInfos)); - String flowRef = getSplitHorizonFlowRef(dpId, NwConstants.EGRESS_LPORT_DISPATCHER_TABLE, interfaceName, currentServiceIndex, shFlagSet); + String flowRef = getSplitHorizonFlowRef(dpId, NwConstants.EGRESS_LPORT_DISPATCHER_TABLE, interfaceName, + currentServiceIndex, shFlagSet); String serviceRef = boundService.getServiceName(); - int splitHorizonFlowPriority = boundService.getServicePriority() + 1; // this must be higher priority than the egress flow + // This must be higher priority than the egress flow + int splitHorizonFlowPriority = boundService.getServicePriority() + 1; + StypeOpenflow stypeOpenFlow = boundService.getAugmentation(StypeOpenflow.class); Flow egressSplitHorizonFlow = MDSALUtil.buildFlow(NwConstants.EGRESS_LPORT_DISPATCHER_TABLE, flowRef, splitHorizonFlowPriority, serviceRef, 0, 0, stypeOpenFlow.getFlowCookie(), shMatches, shInstructions); - installFlow(dpId, egressSplitHorizonFlow, t); + installFlow(dpId, egressSplitHorizonFlow, writeTransaction); } public static BoundServices getBoundServices(String serviceName, short servicePriority, int flowPriority, - BigInteger cookie, List instructions) { - StypeOpenflowBuilder augBuilder = new StypeOpenflowBuilder().setFlowCookie(cookie).setFlowPriority(flowPriority).setInstruction(instructions); - return new BoundServicesBuilder().setKey(new BoundServicesKey(servicePriority)) - .setServiceName(serviceName).setServicePriority(servicePriority) - .setServiceType(ServiceTypeFlowBased.class).addAugmentation(StypeOpenflow.class, augBuilder.build()).build(); + BigInteger cookie, List instructions) { + StypeOpenflowBuilder augBuilder = new StypeOpenflowBuilder().setFlowCookie(cookie).setFlowPriority(flowPriority) + .setInstruction(instructions); + return new BoundServicesBuilder().setKey(new BoundServicesKey(servicePriority)).setServiceName(serviceName) + .setServicePriority(servicePriority).setServiceType(ServiceTypeFlowBased.class) + .addAugmentation(StypeOpenflow.class, augBuilder.build()).build(); } public static InstanceIdentifier buildServiceId(String interfaceName, short serviceIndex) { - return InstanceIdentifier.builder(ServiceBindings.class).child(ServicesInfo.class, - new ServicesInfoKey(interfaceName, ServiceModeIngress.class)) + return InstanceIdentifier.builder(ServiceBindings.class) + .child(ServicesInfo.class, new ServicesInfoKey(interfaceName, ServiceModeIngress.class)) .child(BoundServices.class, new BoundServicesKey(serviceIndex)).build(); } - public static InstanceIdentifier buildServiceId(String interfaceName, short serviceIndex, Class serviceMode) { - return InstanceIdentifier.builder(ServiceBindings.class).child(ServicesInfo.class, - new ServicesInfoKey(interfaceName, serviceMode)) + public static InstanceIdentifier buildServiceId(String interfaceName, short serviceIndex, + Class serviceMode) { + return InstanceIdentifier.builder(ServiceBindings.class) + .child(ServicesInfo.class, new ServicesInfoKey(interfaceName, serviceMode)) .child(BoundServices.class, new BoundServicesKey(serviceIndex)).build(); } public static void unbindDefaultEgressDispatcherService(DataBroker dataBroker, String interfaceName) { - IfmUtil.unbindService(dataBroker, interfaceName, buildServiceId(interfaceName, - ServiceIndex.getIndex(NwConstants.DEFAULT_EGRESS_SERVICE_NAME, NwConstants.DEFAULT_EGRESS_SERVICE_INDEX), - ServiceModeEgress.class)); + IfmUtil.unbindService(dataBroker, interfaceName, + buildServiceId(interfaceName, ServiceIndex.getIndex(NwConstants.DEFAULT_EGRESS_SERVICE_NAME, + NwConstants.DEFAULT_EGRESS_SERVICE_INDEX), ServiceModeEgress.class)); } public static void bindDefaultEgressDispatcherService(DataBroker dataBroker, List> futures, - Interface interfaceInfo, String portNo, - String interfaceName, int ifIndex) { + Interface interfaceInfo, String portNo, String interfaceName, int ifIndex) { WriteTransaction tx = dataBroker.newWriteOnlyTransaction(); - int priority = ServiceIndex.getIndex(NwConstants.DEFAULT_EGRESS_SERVICE_NAME, NwConstants.DEFAULT_EGRESS_SERVICE_INDEX); - List instructions = IfmUtil.getEgressInstructionsForInterface(interfaceInfo, portNo, null, true, ifIndex); - BoundServices - serviceInfo = - getBoundServices(String.format("%s.%s", "default", interfaceName), - ServiceIndex.getIndex(NwConstants.DEFAULT_EGRESS_SERVICE_NAME, NwConstants.DEFAULT_EGRESS_SERVICE_INDEX), priority, - NwConstants.EGRESS_DISPATCHER_TABLE_COOKIE, instructions); + int priority = ServiceIndex.getIndex(NwConstants.DEFAULT_EGRESS_SERVICE_NAME, + NwConstants.DEFAULT_EGRESS_SERVICE_INDEX); + List instructions = IfmUtil.getEgressInstructionsForInterface(interfaceInfo, portNo, null, true, + ifIndex); + BoundServices serviceInfo = getBoundServices(String.format("%s.%s", "default", interfaceName), + ServiceIndex.getIndex(NwConstants.DEFAULT_EGRESS_SERVICE_NAME, + NwConstants.DEFAULT_EGRESS_SERVICE_INDEX), + priority, NwConstants.EGRESS_DISPATCHER_TABLE_COOKIE, instructions); IfmUtil.bindService(tx, interfaceName, serviceInfo, ServiceModeEgress.class); futures.add(tx.submit()); } - public static void removeIngressFlow(String name, BoundServices serviceOld, BigInteger dpId, WriteTransaction t) { - String flowKeyStr = getFlowRef(dpId, NwConstants.VLAN_INTERFACE_INGRESS_TABLE, name, serviceOld, serviceOld.getServicePriority()); - LOG.debug("Removing Ingress Flow {}", flowKeyStr ); + public static void removeIngressFlow(String interfaceName, BigInteger dpId, DataBroker dataBroker, + List> futures) { + if (dpId == null) { + return; + } + LOG.debug("Removing Ingress Flows for {}", interfaceName); + WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction(); + String flowKeyStr = getFlowRef(IfmConstants.VLAN_INTERFACE_INGRESS_TABLE, dpId, interfaceName); FlowKey flowKey = new FlowKey(new FlowId(flowKeyStr)); Node nodeDpn = buildInventoryDpnNode(dpId); InstanceIdentifier flowInstanceId = InstanceIdentifier.builder(Nodes.class) .child(Node.class, nodeDpn.getKey()).augmentation(FlowCapableNode.class) - .child(Table.class, new TableKey(NwConstants.VLAN_INTERFACE_INGRESS_TABLE)).child(Flow.class, flowKey).build(); + .child(Table.class, new TableKey(NwConstants.VLAN_INTERFACE_INGRESS_TABLE)).child(Flow.class, flowKey) + .build(); - t.delete(LogicalDatastoreType.CONFIGURATION, flowInstanceId); + writeTransaction.delete(LogicalDatastoreType.CONFIGURATION, flowInstanceId); + futures.add(writeTransaction.submit()); } - public static void removeLPortDispatcherFlow(BigInteger dpId, String iface, BoundServices boundServicesOld, WriteTransaction t, short currentServiceIndex) { + public static void removeIngressFlow(String name, BoundServices serviceOld, BigInteger dpId, + WriteTransaction writeTransaction) { + String flowKeyStr = getFlowRef(dpId, NwConstants.VLAN_INTERFACE_INGRESS_TABLE, name, serviceOld, + serviceOld.getServicePriority()); + LOG.debug("Removing Ingress Flow {}", flowKeyStr); + FlowKey flowKey = new FlowKey(new FlowId(flowKeyStr)); + Node nodeDpn = buildInventoryDpnNode(dpId); + InstanceIdentifier flowInstanceId = InstanceIdentifier.builder(Nodes.class) + .child(Node.class, nodeDpn.getKey()).augmentation(FlowCapableNode.class) + .child(Table.class, new TableKey(NwConstants.VLAN_INTERFACE_INGRESS_TABLE)).child(Flow.class, flowKey) + .build(); + + writeTransaction.delete(LogicalDatastoreType.CONFIGURATION, flowInstanceId); + } + + public static void removeLPortDispatcherFlow(BigInteger dpId, String iface, BoundServices boundServicesOld, + WriteTransaction writeTransaction, short currentServiceIndex) { LOG.debug("Removing LPort Dispatcher Flows {}, {}", dpId, iface); boundServicesOld.getAugmentation(StypeOpenflow.class); // build the flow and install it - String flowRef = getFlowRef(dpId, NwConstants.LPORT_DISPATCHER_TABLE, iface, boundServicesOld, currentServiceIndex); + String flowRef = getFlowRef(dpId, NwConstants.LPORT_DISPATCHER_TABLE, iface, boundServicesOld, + currentServiceIndex); FlowKey flowKey = new FlowKey(new FlowId(flowRef)); Node nodeDpn = buildInventoryDpnNode(dpId); InstanceIdentifier flowInstanceId = InstanceIdentifier.builder(Nodes.class) .child(Node.class, nodeDpn.getKey()).augmentation(FlowCapableNode.class) - .child(Table.class, new TableKey(NwConstants.LPORT_DISPATCHER_TABLE)).child(Flow.class, flowKey).build(); + .child(Table.class, new TableKey(NwConstants.LPORT_DISPATCHER_TABLE)).child(Flow.class, flowKey) + .build(); - t.delete(LogicalDatastoreType.CONFIGURATION, flowInstanceId); + writeTransaction.delete(LogicalDatastoreType.CONFIGURATION, flowInstanceId); } - public static void removeEgressDispatcherFlows(BigInteger dpId, String iface, BoundServices boundServicesOld, WriteTransaction t, short currentServiceIndex) { + public static void removeEgressDispatcherFlows(BigInteger dpId, String iface, BoundServices boundServicesOld, + WriteTransaction writeTransaction, short currentServiceIndex) { LOG.debug("Removing Egress Dispatcher Flows {}, {}", dpId, iface); - removeEgressDispatcherFlow(dpId, iface, t, currentServiceIndex, boundServicesOld); - removeEgressSplitHorizonDispatcherFlow(dpId, iface, t, currentServiceIndex); + removeEgressDispatcherFlow(dpId, iface, writeTransaction, currentServiceIndex, boundServicesOld); + removeEgressSplitHorizonDispatcherFlow(dpId, iface, writeTransaction, currentServiceIndex); } - private static void removeEgressDispatcherFlow(BigInteger dpId, String iface, WriteTransaction t, + private static void removeEgressDispatcherFlow(BigInteger dpId, String iface, WriteTransaction writeTransaction, short currentServiceIndex, BoundServices boundServicesOld) { // build the flow and install it - String flowRef = getFlowRef(dpId, NwConstants.EGRESS_LPORT_DISPATCHER_TABLE, iface, boundServicesOld, currentServiceIndex); + String flowRef = getFlowRef(dpId, NwConstants.EGRESS_LPORT_DISPATCHER_TABLE, iface, boundServicesOld, + currentServiceIndex); FlowKey flowKey = new FlowKey(new FlowId(flowRef)); Node nodeDpn = buildInventoryDpnNode(dpId); InstanceIdentifier flowInstanceId = InstanceIdentifier.builder(Nodes.class) .child(Node.class, nodeDpn.getKey()).augmentation(FlowCapableNode.class) - .child(Table.class, new TableKey(NwConstants.EGRESS_LPORT_DISPATCHER_TABLE)).child(Flow.class, flowKey).build(); + .child(Table.class, new TableKey(NwConstants.EGRESS_LPORT_DISPATCHER_TABLE)).child(Flow.class, flowKey) + .build(); - t.delete(LogicalDatastoreType.CONFIGURATION, flowInstanceId); + writeTransaction.delete(LogicalDatastoreType.CONFIGURATION, flowInstanceId); } - public static void removeEgressSplitHorizonDispatcherFlow(BigInteger dpId, String iface, WriteTransaction t, short currentServiceIndex) { - BigInteger shFlagSet = BigInteger.ONE; // BigInteger.ONE is used for checking the Split-Horizon flag - String shFlowRef = getSplitHorizonFlowRef(dpId, NwConstants.EGRESS_LPORT_DISPATCHER_TABLE, iface, currentServiceIndex, shFlagSet); + public static void removeEgressSplitHorizonDispatcherFlow(BigInteger dpId, String iface, + WriteTransaction writeTransaction, short currentServiceIndex) { + // BigInteger.ONE is used for checking the Split-Horizon flag + BigInteger shFlagSet = BigInteger.ONE; + String shFlowRef = getSplitHorizonFlowRef(dpId, NwConstants.EGRESS_LPORT_DISPATCHER_TABLE, iface, + currentServiceIndex, shFlagSet); FlowKey shFlowKey = new FlowKey(new FlowId(shFlowRef)); Node nodeDpn = buildInventoryDpnNode(dpId); InstanceIdentifier shFlowInstanceId = InstanceIdentifier.builder(Nodes.class) .child(Node.class, nodeDpn.getKey()).augmentation(FlowCapableNode.class) - .child(Table.class, new TableKey(NwConstants.EGRESS_LPORT_DISPATCHER_TABLE)).child(Flow.class, shFlowKey).build(); + .child(Table.class, new TableKey(NwConstants.EGRESS_LPORT_DISPATCHER_TABLE)) + .child(Flow.class, shFlowKey).build(); + + writeTransaction.delete(LogicalDatastoreType.CONFIGURATION, shFlowInstanceId); + } - t.delete(LogicalDatastoreType.CONFIGURATION, shFlowInstanceId); + public static String getFlowRef(short tableId, BigInteger dpnId, String infName) { + return String.format("%d:%s:%s", tableId, dpnId, infName); } - private static String getFlowRef(BigInteger dpnId, short tableId, String iface, BoundServices service, short currentServiceIndex) { - return String.valueOf(dpnId) + tableId + NwConstants.FLOWID_SEPARATOR + - iface + NwConstants.FLOWID_SEPARATOR + currentServiceIndex; + private static String getFlowRef(BigInteger dpnId, short tableId, String iface, BoundServices service, + short currentServiceIndex) { + return String.valueOf(dpnId) + tableId + NwConstants.FLOWID_SEPARATOR + iface + NwConstants.FLOWID_SEPARATOR + + currentServiceIndex; } - private static String getSplitHorizonFlowRef(BigInteger dpnId, short tableId, String iface, short currentServiceIndex, BigInteger shFlag) { - return new StringBuffer().append(dpnId).append(tableId).append(NwConstants.FLOWID_SEPARATOR) - .append(iface).append(NwConstants.FLOWID_SEPARATOR).append(shFlag.toString()).toString(); + private static String getSplitHorizonFlowRef(BigInteger dpnId, short tableId, String iface, + short currentServiceIndex, BigInteger shFlag) { + return new StringBuffer().append(dpnId).append(tableId).append(NwConstants.FLOWID_SEPARATOR).append(iface) + .append(NwConstants.FLOWID_SEPARATOR).append(shFlag.toString()).toString(); } + /** - * This util method returns an array of ServiceInfo in which index 0 will + * This utility method returns an array of ServiceInfo in which index 0 will * have the immediate lower priority service and index 1 will have the - * immediate higher priority service among the list of existing serviceInfos + * immediate higher priority service among the list of existing + * serviceInfos. * * @param serviceInfos + * list of services bound * @param currentServiceInfo - * @return + * current service bound + * @return array bound services */ - public static BoundServices[] getHighAndLowPriorityService( - List serviceInfos, BoundServices currentServiceInfo) { - BoundServices higher = null; // this will be used to hold the immediate higher service priority with respect to the currentServiceInfo - BoundServices lower = null; // this will be used to hold the immediate lower service priority with respect to the currentServiceInfo + public static BoundServices[] getHighAndLowPriorityService(List serviceInfos, + BoundServices currentServiceInfo) { + // This will be used to hold the immediate higher service priority with respect to the currentServiceInfo + BoundServices higher = null; + // This will be used to hold the immediate lower service priority with respect to the currentServiceInfo + BoundServices lower = null; if (serviceInfos == null || serviceInfos.isEmpty()) { - return new BoundServices[]{lower, higher}; + return new BoundServices[] { lower, higher }; } - List availableServiceInfos = new ArrayList<>(serviceInfos); - Collections.sort(availableServiceInfos, - (serviceInfo1, serviceInfo2) -> serviceInfo1.getServicePriority().compareTo(serviceInfo2.getServicePriority())); - for (BoundServices availableServiceInfo: availableServiceInfos) { + List availableServiceInfos = new ArrayList<>(serviceInfos); + Collections.sort(availableServiceInfos, (serviceInfo1, serviceInfo2) -> serviceInfo1.getServicePriority() + .compareTo(serviceInfo2.getServicePriority())); + for (BoundServices availableServiceInfo : availableServiceInfos) { if (currentServiceInfo.getServicePriority() < availableServiceInfo.getServicePriority()) { lower = availableServiceInfo; break; @@ -504,17 +572,17 @@ public class FlowBasedServicesUtils { higher = availableServiceInfo; } } - return new BoundServices[]{lower,higher}; + return new BoundServices[] { lower, higher }; } public static BoundServices getHighestPriorityService(List serviceInfos) { - List availableServiceInfos = new ArrayList<>(serviceInfos); + List availableServiceInfos = new ArrayList<>(serviceInfos); if (availableServiceInfos.isEmpty()) { return null; } BoundServices highPriorityService = availableServiceInfos.get(0); availableServiceInfos.remove(0); - for (BoundServices availableServiceInfo: availableServiceInfos) { + for (BoundServices availableServiceInfo : availableServiceInfos) { if (availableServiceInfo.getServicePriority() < highPriorityService.getServicePriority()) { highPriorityService = availableServiceInfo; } @@ -523,69 +591,52 @@ public class FlowBasedServicesUtils { } public static void installLportIngressFlow(BigInteger dpId, long portNo, Interface iface, - List> futures, DataBroker dataBroker, - int lportTag) { + List> futures, DataBroker dataBroker, int lportTag) { int vlanId = 0; boolean isVlanTransparent = false; - WriteTransaction inventoryConfigShardTransaction = dataBroker.newWriteOnlyTransaction(); - List matches = getMatchInfoForVlanPortAtIngressTable(dpId, portNo, iface); + IfL2vlan l2vlan = iface.getAugmentation(IfL2vlan.class); - if(l2vlan != null){ + if (l2vlan != null) { vlanId = l2vlan.getVlanId() == null ? 0 : l2vlan.getVlanId().getValue(); isVlanTransparent = l2vlan.getL2vlanMode() == IfL2vlan.L2vlanMode.Transparent; } int instructionKey = 0; - BigInteger metadata = MetaDataUtil.getMetaDataForLPortDispatcher(lportTag, (short) 0, BigInteger.ZERO, isExternal(iface)); - BigInteger metadataMask = MetaDataUtil.getMetaDataMaskForLPortDispatcher(MetaDataUtil.METADATA_MASK_LPORT_TAG_SH_FLAG); + List instructions = new ArrayList<>(); final SplitHorizon splitHorizon = iface.getAugmentation(SplitHorizon.class); - boolean overrideSplitHorizonProtection = splitHorizon != null && splitHorizon.isOverrideSplitHorizonProtection(); + boolean overrideSplitHorizonProtection = splitHorizon != null + && splitHorizon.isOverrideSplitHorizonProtection(); int actionKey = 0; List actions = new ArrayList<>(); if (vlanId != 0 && !isVlanTransparent) { actions.add(MDSALUtil.createPopVlanAction(actionKey++)); } if (overrideSplitHorizonProtection) { - actions.add(MDSALUtil.createNxOfInPortAction(actionKey++,0)); + actions.add(MDSALUtil.createNxOfInPortAction(actionKey++, 0)); } - if (actions.size() != 0) { - instructions.add(MDSALUtil.buildApplyActionsInstruction(actions,instructionKey++)); + if (!actions.isEmpty()) { + instructions.add(MDSALUtil.buildApplyActionsInstruction(actions, instructionKey++)); } - + BigInteger metadata = MetaDataUtil.getMetaDataForLPortDispatcher(lportTag, (short) 0, BigInteger.ZERO, + isExternal(iface)); + BigInteger metadataMask = MetaDataUtil + .getMetaDataMaskForLPortDispatcher(MetaDataUtil.METADATA_MASK_LPORT_TAG_SH_FLAG); instructions.add(MDSALUtil.buildAndGetWriteMetadaInstruction(metadata, metadataMask, instructionKey++)); - instructions.add(MDSALUtil.buildAndGetGotoTableInstruction(NwConstants.LPORT_DISPATCHER_TABLE, instructionKey++)); - int priority = isVlanTransparent ? 1 : vlanId == 0 ? IfmConstants.FLOW_PRIORITY_FOR_UNTAGGED_VLAN : IfmConstants.FLOW_HIGH_PRIORITY; + instructions + .add(MDSALUtil.buildAndGetGotoTableInstruction(NwConstants.LPORT_DISPATCHER_TABLE, instructionKey++)); + int priority = isVlanTransparent ? 1 + : vlanId == 0 ? IfmConstants.FLOW_PRIORITY_FOR_UNTAGGED_VLAN : IfmConstants.FLOW_HIGH_PRIORITY; String flowRef = getFlowRef(IfmConstants.VLAN_INTERFACE_INGRESS_TABLE, dpId, iface.getName()); - Flow ingressFlow = MDSALUtil.buildFlowNew(IfmConstants.VLAN_INTERFACE_INGRESS_TABLE, flowRef, priority, flowRef, 0, 0, - NwConstants.VLAN_TABLE_COOKIE, matches, instructions); + List matches = getMatchInfoForVlanPortAtIngressTable(dpId, portNo, iface); + Flow ingressFlow = MDSALUtil.buildFlowNew(IfmConstants.VLAN_INTERFACE_INGRESS_TABLE, flowRef, priority, flowRef, + 0, 0, NwConstants.VLAN_TABLE_COOKIE, matches, instructions); LOG.debug("Installing ingress flow {} for {}", flowRef, iface.getName()); + WriteTransaction inventoryConfigShardTransaction = dataBroker.newWriteOnlyTransaction(); installFlow(dpId, ingressFlow, inventoryConfigShardTransaction); futures.add(inventoryConfigShardTransaction.submit()); } - public static String getFlowRef(short tableId, BigInteger dpnId, String infName) { - return String.format("%d:%s:%s", tableId, dpnId, infName); - } - - public static void removeIngressFlow(String interfaceName, BigInteger dpId, DataBroker dataBroker, - List> futures) { - if(dpId == null){ - return; - } - LOG.debug("Removing Ingress Flows for {}", interfaceName); - WriteTransaction t = dataBroker.newWriteOnlyTransaction(); - String flowKeyStr = getFlowRef(IfmConstants.VLAN_INTERFACE_INGRESS_TABLE, dpId, interfaceName); - FlowKey flowKey = new FlowKey(new FlowId(flowKeyStr)); - Node nodeDpn = buildInventoryDpnNode(dpId); - InstanceIdentifier flowInstanceId = InstanceIdentifier.builder(Nodes.class) - .child(Node.class, nodeDpn.getKey()).augmentation(FlowCapableNode.class) - .child(Table.class, new TableKey(NwConstants.VLAN_INTERFACE_INGRESS_TABLE)).child(Flow.class, flowKey).build(); - - t.delete(LogicalDatastoreType.CONFIGURATION, flowInstanceId); - futures.add(t.submit()); - } - private static boolean isExternal(Interface iface) { if (iface == null) { return false; diff --git a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/statusanddiag/InterfaceStatusMonitorMBean.java b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/statusanddiag/InterfaceStatusMonitorMBean.java index 548203264..dc9ffb373 100644 --- a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/statusanddiag/InterfaceStatusMonitorMBean.java +++ b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/statusanddiag/InterfaceStatusMonitorMBean.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * Copyright (c) 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, @@ -8,7 +8,5 @@ package org.opendaylight.genius.interfacemanager.statusanddiag; public interface InterfaceStatusMonitorMBean { - String acquireServiceStatus(); - } diff --git a/interfacemanager/interfacemanager-impl/src/test/java/org/opendaylight/genius/interfacemanager/test/IfmUtilTest.java b/interfacemanager/interfacemanager-impl/src/test/java/org/opendaylight/genius/interfacemanager/test/IfmUtilTest.java index 18d96924d..2d48e3d52 100644 --- a/interfacemanager/interfacemanager-impl/src/test/java/org/opendaylight/genius/interfacemanager/test/IfmUtilTest.java +++ b/interfacemanager/interfacemanager-impl/src/test/java/org/opendaylight/genius/interfacemanager/test/IfmUtilTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * Copyright (c) 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, @@ -21,7 +21,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeCon public class IfmUtilTest { - @Mock NodeConnectorId ncId; + @Mock + NodeConnectorId ncId; @Before public void setUp() { @@ -30,9 +31,9 @@ public class IfmUtilTest { @Test public void testDpnConversions() { - String NodeId = IfmUtil.buildDpnNodeId(BigInteger.valueOf(101)).getValue(); - assertEquals("openflow:101", NodeId); + String nodeId = IfmUtil.buildDpnNodeId(BigInteger.valueOf(101)).getValue(); + assertEquals("openflow:101", nodeId); when(ncId.getValue()).thenReturn("openflow:101:11"); - assertEquals(new BigInteger("101"),IfmUtil.getDpnFromNodeConnectorId(ncId)); + assertEquals(new BigInteger("101"), IfmUtil.getDpnFromNodeConnectorId(ncId)); } } diff --git a/interfacemanager/interfacemanager-impl/src/test/java/org/opendaylight/genius/interfacemanager/test/InterfaceManagerConfigurationTest.java b/interfacemanager/interfacemanager-impl/src/test/java/org/opendaylight/genius/interfacemanager/test/InterfaceManagerConfigurationTest.java index 017cdf08e..4ec7bac6d 100644 --- a/interfacemanager/interfacemanager-impl/src/test/java/org/opendaylight/genius/interfacemanager/test/InterfaceManagerConfigurationTest.java +++ b/interfacemanager/interfacemanager-impl/src/test/java/org/opendaylight/genius/interfacemanager/test/InterfaceManagerConfigurationTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Red Hat, Inc. and others. All rights reserved. + * Copyright (c) 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, @@ -7,7 +7,18 @@ */ package org.opendaylight.genius.interfacemanager.test; +import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION; +import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.OPERATIONAL; +import static org.opendaylight.genius.interfacemanager.test.InterfaceManagerTestUtil.INTERFACE_NAME; +import static org.opendaylight.genius.interfacemanager.test.InterfaceManagerTestUtil.PARENT_INTERFACE; +import static org.opendaylight.genius.interfacemanager.test.InterfaceManagerTestUtil.TUNNEL_INTERFACE_NAME; +import static org.opendaylight.genius.mdsalutil.NwConstants.DEFAULT_EGRESS_SERVICE_INDEX; +import static org.opendaylight.genius.mdsalutil.NwConstants.VLAN_INTERFACE_INGRESS_TABLE; +import static org.opendaylight.mdsal.binding.testutils.AssertDataObjects.assertEqualBeans; + import com.google.common.base.Optional; +import java.math.BigInteger; +import javax.inject.Inject; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -59,16 +70,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.N 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; -import javax.inject.Inject; -import java.math.BigInteger; - -import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION; -import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.OPERATIONAL; -import static org.opendaylight.genius.interfacemanager.test.InterfaceManagerTestUtil.*; -import static org.opendaylight.genius.mdsalutil.NwConstants.DEFAULT_EGRESS_SERVICE_INDEX; -import static org.opendaylight.genius.mdsalutil.NwConstants.VLAN_INTERFACE_INGRESS_TABLE; -import static org.opendaylight.mdsal.binding.testutils.AssertDataObjects.assertEqualBeans; - /** * Component tests for interface manager. * @@ -79,18 +80,20 @@ import static org.opendaylight.mdsal.binding.testutils.AssertDataObjects.assertE public class InterfaceManagerConfigurationTest { // Uncomment this, temporarily (never commit!), to see concurrency issues: - // public static @ClassRule RunUntilFailureRule repeater = new RunUntilFailureRule(); + // public static @ClassRule RunUntilFailureRule repeater = new + // RunUntilFailureRule(); public @Rule LogRule logRule = new LogRule(); public @Rule MethodRule guice = new GuiceRule(new InterfaceManagerTestModule()); - static final BigInteger dpnId = BigInteger.valueOf(1); + private static final BigInteger DPN_ID = BigInteger.valueOf(1); - @Inject DataBroker dataBroker; + @Inject + DataBroker dataBroker; @Before public void start() throws InterruptedException { - //Create the bridge and make sure it is ready + // Create the bridge and make sure it is ready setupAndAssertBridgeCreation(); } @@ -102,147 +105,168 @@ public class InterfaceManagerConfigurationTest { private void setupAndAssertBridgeDeletion() throws InterruptedException { OvsdbSouthboundTestUtil.deleteBridge(dataBroker); Thread.sleep(2000); - assertEqualBeans(InterfaceMetaUtils.getBridgeRefEntryFromOperDS(dpnId, dataBroker), null); + assertEqualBeans(InterfaceMetaUtils.getBridgeRefEntryFromOperDS(DPN_ID, dataBroker), null); } private void setupAndAssertBridgeCreation() throws InterruptedException { OvsdbSouthboundTestUtil.createBridge(dataBroker); Thread.sleep(2000); - // a) Check bridgeRefEntry in cache and OperDS are same and use the right dpnId - BridgeRefEntryKey bridgeRefEntryKey = new BridgeRefEntryKey(dpnId); + // a) Check bridgeRefEntry in cache and OperDS are same and use the + // right DPN_ID + BridgeRefEntryKey bridgeRefEntryKey = new BridgeRefEntryKey(DPN_ID); InstanceIdentifier bridgeRefEntryIid = InterfaceMetaUtils .getBridgeRefEntryIdentifier(bridgeRefEntryKey); - BridgeRefEntry bridgeRefEntry = IfmUtil.read(LogicalDatastoreType.OPERATIONAL, bridgeRefEntryIid, dataBroker).orNull(); - assertEqualBeans(InterfaceMetaUtils.getBridgeRefEntryFromCache(dpnId), bridgeRefEntry); - assertEqualBeans(bridgeRefEntry.getDpid(), dpnId); + BridgeRefEntry bridgeRefEntry = IfmUtil.read(LogicalDatastoreType.OPERATIONAL, bridgeRefEntryIid, dataBroker) + .orNull(); + assertEqualBeans(InterfaceMetaUtils.getBridgeRefEntryFromCache(DPN_ID), bridgeRefEntry); + assertEqualBeans(bridgeRefEntry.getDpid(), DPN_ID); } @Test public void vlanInterfaceTests() throws Exception { // 1. When - // i) parent-interface specified in above vlan configuration comes in operational/ietf-interfaces-state - InterfaceManagerTestUtil.putInterfaceState(dataBroker, parentInterface, null); + // i) parent-interface specified in above vlan configuration comes in + // operational/ietf-interfaces-state + InterfaceManagerTestUtil.putInterfaceState(dataBroker, PARENT_INTERFACE, null); Thread.sleep(1000); - // ii) Vlan interface written to config/ietf-interfaces DS and corresponding parent-interface is not present - // in operational/ietf-interface-state - ParentRefs parentRefs = new ParentRefsBuilder().setParentInterface(parentInterface).build(); - InterfaceManagerTestUtil.putInterfaceConfig(dataBroker, interfaceName, parentRefs, L2vlan.class); - // TODO Must think about proper solution for better synchronization here instead of silly wait()... - // TODO use TestDataStoreJobCoordinator.waitForAllJobs() when https://git.opendaylight.org/gerrit/#/c/48061/ is merged + // ii) Vlan interface written to config/ietf-interfaces DS and + // corresponding parent-interface is not present + // in operational/ietf-interface-state + ParentRefs parentRefs = new ParentRefsBuilder().setParentInterface(PARENT_INTERFACE).build(); + InterfaceManagerTestUtil.putInterfaceConfig(dataBroker, INTERFACE_NAME, parentRefs, L2vlan.class); + // TODO Must think about proper solution for better synchronization here + // instead of silly wait()... + // TODO use TestDataStoreJobCoordinator.waitForAllJobs() when + // https://git.opendaylight.org/gerrit/#/c/48061/ is merged Thread.sleep(2000); // 3. Then - // a) check expected interface-child entry mapping in odl-interface-meta/config/interface-child-info was created + // a) check expected interface-child entry mapping in + // odl-interface-meta/config/interface-child-info was created InstanceIdentifier interfaceChildEntryInstanceIdentifier = InterfaceMetaUtils - .getInterfaceChildEntryIdentifier(new InterfaceParentEntryKey(parentInterface), - new InterfaceChildEntryKey(interfaceName)); + .getInterfaceChildEntryIdentifier(new InterfaceParentEntryKey(PARENT_INTERFACE), + new InterfaceChildEntryKey(INTERFACE_NAME)); assertEqualBeans(ExpectedInterfaceChildEntry.interfaceChildEntry(), dataBroker.newReadOnlyTransaction() .read(CONFIGURATION, interfaceChildEntryInstanceIdentifier).checkedGet().get()); // Then - // a) check if operational/ietf-interfaces-state is populated for the vlan interface - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508 - .interfaces.state.Interface ifaceState = - dataBroker.newReadOnlyTransaction().read(OPERATIONAL, - IfmUtil.buildStateInterfaceId(interfaceName)).checkedGet().get(); + // a) check if operational/ietf-interfaces-state is populated for the + // vlan interface + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang + .ietf.interfaces.rev140508.interfaces.state.Interface ifaceState = dataBroker + .newReadOnlyTransaction().read(OPERATIONAL, IfmUtil.buildStateInterfaceId(INTERFACE_NAME)).checkedGet() + .get(); assertEqualBeans(ExpectedInterfaceState.newInterfaceState(), ifaceState); // b) check if lport-tag to interface mapping is created - InstanceIdentifier ifIndexInterfaceInstanceIdentifier = InstanceIdentifier.builder( - IfIndexesInterfaceMap.class).child( - IfIndexInterface.class, new IfIndexInterfaceKey(ifaceState.getIfIndex())).build(); - Assert.assertEquals(interfaceName, dataBroker.newReadOnlyTransaction().read(OPERATIONAL, - ifIndexInterfaceInstanceIdentifier).checkedGet().get().getInterfaceName()); + InstanceIdentifier ifIndexInterfaceInstanceIdentifier = InstanceIdentifier + .builder(IfIndexesInterfaceMap.class) + .child(IfIndexInterface.class, new IfIndexInterfaceKey(ifaceState.getIfIndex())).build(); + Assert.assertEquals(INTERFACE_NAME, dataBroker.newReadOnlyTransaction() + .read(OPERATIONAL, ifIndexInterfaceInstanceIdentifier).checkedGet().get().getInterfaceName()); - // c) check expected flow entries were created in Interface Ingress Table + // c) check expected flow entries were created in Interface Ingress + // Table BigInteger dpnId = BigInteger.valueOf(1); - String ingressFlowRef = FlowBasedServicesUtils.getFlowRef(VLAN_INTERFACE_INGRESS_TABLE, dpnId, interfaceName); + String ingressFlowRef = FlowBasedServicesUtils.getFlowRef(VLAN_INTERFACE_INGRESS_TABLE, dpnId, INTERFACE_NAME); FlowKey ingressFlowKey = new FlowKey(new FlowId(ingressFlowRef)); Node nodeDpn = InterfaceManagerTestUtil.buildInventoryDpnNode(dpnId); InstanceIdentifier ingressFlowInstanceId = InstanceIdentifier.builder(Nodes.class) .child(Node.class, nodeDpn.getKey()).augmentation(FlowCapableNode.class) - .child(Table.class, new TableKey(VLAN_INTERFACE_INGRESS_TABLE)) - .child(Flow.class,ingressFlowKey).build(); + .child(Table.class, new TableKey(VLAN_INTERFACE_INGRESS_TABLE)).child(Flow.class, ingressFlowKey) + .build(); assertEqualBeans(ExpectedFlowEntries.newIngressFlow(), dataBroker.newReadOnlyTransaction().read(CONFIGURATION, ingressFlowInstanceId).checkedGet().get()); // d) check if default egress service is bound on the interface - InstanceIdentifier boundServicesInstanceIdentifier = - InstanceIdentifier.builder(ServiceBindings.class) - .child(ServicesInfo.class, new ServicesInfoKey(interfaceName, ServiceModeEgress.class)) + InstanceIdentifier boundServicesInstanceIdentifier = InstanceIdentifier + .builder(ServiceBindings.class) + .child(ServicesInfo.class, new ServicesInfoKey(INTERFACE_NAME, ServiceModeEgress.class)) .child(BoundServices.class, new BoundServicesKey(DEFAULT_EGRESS_SERVICE_INDEX)).build(); assertEqualBeans(ExpectedServicesInfo.newboundService(), dataBroker.newReadOnlyTransaction() .read(CONFIGURATION, boundServicesInstanceIdentifier).checkedGet().get()); - //Delete test + // Delete test // iii) vlan interface is deleted from config/ietf-interfaces - InterfaceManagerTestUtil.deleteInterfaceConfig(dataBroker, interfaceName); + InterfaceManagerTestUtil.deleteInterfaceConfig(dataBroker, INTERFACE_NAME); Thread.sleep(4000); // 3. Then - // a) check expected interface-child entry mapping in odl-interface-meta/config/interface-child-info is deleted + // a) check expected interface-child entry mapping in + // odl-interface-meta/config/interface-child-info is deleted - // TODO Later use nicer abstraction for DB access here.. see ElanServiceTest - Assert.assertEquals(Optional.absent(), dataBroker.newReadOnlyTransaction() - .read(CONFIGURATION, interfaceChildEntryInstanceIdentifier).get()); + // TODO Later use nicer abstraction for DB access here.. see + // ElanServiceTest + Assert.assertEquals(Optional.absent(), + dataBroker.newReadOnlyTransaction().read(CONFIGURATION, interfaceChildEntryInstanceIdentifier).get()); // Then - // a) check if operational/ietf-interfaces-state is deleted for the vlan interface - Assert.assertEquals(Optional.absent(), dataBroker.newReadOnlyTransaction().read(OPERATIONAL, - IfmUtil.buildStateInterfaceId(interfaceName)).get()); + // a) check if operational/ietf-interfaces-state is deleted for the vlan + // interface + Assert.assertEquals(Optional.absent(), dataBroker.newReadOnlyTransaction() + .read(OPERATIONAL, IfmUtil.buildStateInterfaceId(INTERFACE_NAME)).get()); // b) check if lport-tag to interface mapping is deleted - Assert.assertEquals(Optional.absent(), dataBroker.newReadOnlyTransaction().read(OPERATIONAL, - ifIndexInterfaceInstanceIdentifier).get()); + Assert.assertEquals(Optional.absent(), + dataBroker.newReadOnlyTransaction().read(OPERATIONAL, ifIndexInterfaceInstanceIdentifier).get()); } - @Test public void newTunnelInterface() throws Exception { + @Test + public void newTunnelInterface() throws Exception { // 1. Given // 2. When - // i) dpn-id specified above configuration comes in operational/network-topology - // ii) Vlan interface written to config/ietf-interfaces DS and corresponding parent-interface is not present - // in operational/ietf-interface-state - ParentRefs parentRefs = new ParentRefsBuilder().setDatapathNodeIdentifier(dpnId).build(); - InterfaceManagerTestUtil.putInterfaceConfig(dataBroker, tunnelInterfaceName, parentRefs, Tunnel.class); - - // TODO Must think about proper solution for better synchronization here instead of silly wait()... - // TODO use TestDataStoreJobCoordinator.waitForAllJobs() when https://git.opendaylight.org/gerrit/#/c/48061/ is merged + // i) dpn-id specified above configuration comes in + // operational/network-topology + // ii) Vlan interface written to config/ietf-interfaces DS and + // corresponding parent-interface is not present + // in operational/ietf-interface-state + ParentRefs parentRefs = new ParentRefsBuilder().setDatapathNodeIdentifier(DPN_ID).build(); + InterfaceManagerTestUtil.putInterfaceConfig(dataBroker, TUNNEL_INTERFACE_NAME, parentRefs, Tunnel.class); + + // TODO Must think about proper solution for better synchronization here + // instead of silly wait()... + // TODO use TestDataStoreJobCoordinator.waitForAllJobs() when + // https://git.opendaylight.org/gerrit/#/c/48061/ is merged Thread.sleep(1000); // iii) tunnel interface comes up in operational/ietf-interfaces-state - InterfaceManagerTestUtil.putInterfaceState(dataBroker, tunnelInterfaceName, Tunnel.class); + InterfaceManagerTestUtil.putInterfaceState(dataBroker, TUNNEL_INTERFACE_NAME, Tunnel.class); Thread.sleep(1000); // 3. Then - // a) check expected bridge-interface mapping in odl-interface-meta/config/bridge-interface-info was created - BridgeEntryKey bridgeEntryKey = new BridgeEntryKey(dpnId); - BridgeInterfaceEntryKey bridgeInterfaceEntryKey = new BridgeInterfaceEntryKey(tunnelInterfaceName); - InstanceIdentifier bridgeInterfaceEntryIid = - InterfaceMetaUtils.getBridgeInterfaceEntryIdentifier(bridgeEntryKey, bridgeInterfaceEntryKey); - // TODO Later use nicer abstraction for DB access here.. see ElanServiceTest - assertEqualBeans(InterfaceMeta.newBridgeInterface(), dataBroker.newReadOnlyTransaction() - .read(CONFIGURATION, bridgeInterfaceEntryIid).checkedGet().get()); + // a) check expected bridge-interface mapping in + // odl-interface-meta/config/bridge-interface-info was created + BridgeEntryKey bridgeEntryKey = new BridgeEntryKey(DPN_ID); + BridgeInterfaceEntryKey bridgeInterfaceEntryKey = new BridgeInterfaceEntryKey(TUNNEL_INTERFACE_NAME); + InstanceIdentifier bridgeInterfaceEntryIid = InterfaceMetaUtils + .getBridgeInterfaceEntryIdentifier(bridgeEntryKey, bridgeInterfaceEntryKey); + // TODO Later use nicer abstraction for DB access here.. see + // ElanServiceTest + assertEqualBeans(InterfaceMeta.newBridgeInterface(), + dataBroker.newReadOnlyTransaction().read(CONFIGURATION, bridgeInterfaceEntryIid).checkedGet().get()); // Then - // a) check if termination end point is created in config/network-topology - final InstanceIdentifier bridgeIid = - OvsdbSouthboundTestUtil.createInstanceIdentifier("192.168.56.101", 6640, "s2"); + // a) check if termination end point is created in + // config/network-topology + final InstanceIdentifier bridgeIid = OvsdbSouthboundTestUtil + .createInstanceIdentifier("192.168.56.101", 6640, "s2"); InstanceIdentifier tpIid = InterfaceManagerTestUtil.getTerminationPointId(bridgeIid, - tunnelInterfaceName); + TUNNEL_INTERFACE_NAME); assertEqualBeans(ExpectedTerminationPoint.newTerminationPoint(), dataBroker.newReadOnlyTransaction().read(CONFIGURATION, tpIid).checkedGet().get()); // Delete test // iii) tunnel interface is deleted from config/ietf-interfaces - InterfaceManagerTestUtil.deleteInterfaceConfig(dataBroker, tunnelInterfaceName); + InterfaceManagerTestUtil.deleteInterfaceConfig(dataBroker, TUNNEL_INTERFACE_NAME); Thread.sleep(5000); // Then // a) check if tunnel is deleted from bridge-interface-info - Assert.assertEquals(Optional.absent(), dataBroker.newReadOnlyTransaction() - .read(CONFIGURATION, bridgeInterfaceEntryIid).get()); + Assert.assertEquals(Optional.absent(), + dataBroker.newReadOnlyTransaction().read(CONFIGURATION, bridgeInterfaceEntryIid).get()); - // b) check if termination end point is deleted in config/network-topology + // b) check if termination end point is deleted in + // config/network-topology Assert.assertEquals(Optional.absent(), dataBroker.newReadOnlyTransaction().read(CONFIGURATION, tpIid).get()); } } diff --git a/interfacemanager/interfacemanager-impl/src/test/java/org/opendaylight/genius/interfacemanager/test/InterfaceManagerTestModule.java b/interfacemanager/interfacemanager-impl/src/test/java/org/opendaylight/genius/interfacemanager/test/InterfaceManagerTestModule.java index b4940be5c..064d5ba84 100644 --- a/interfacemanager/interfacemanager-impl/src/test/java/org/opendaylight/genius/interfacemanager/test/InterfaceManagerTestModule.java +++ b/interfacemanager/interfacemanager-impl/src/test/java/org/opendaylight/genius/interfacemanager/test/InterfaceManagerTestModule.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Red Hat, Inc. and others. All rights reserved. + * Copyright (c) 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, @@ -45,13 +45,17 @@ import org.slf4j.LoggerFactory; /** * Dependency Injection Wiring for {@link InterfaceManagerConfigurationTest}. * - *

This class looks a little bit more complicated than it could and later will be - * just because interfacemanager is still using CSS instead of BP with @Inject. + *

+ * This class looks a little bit more complicated than it could and later will + * be just because interfacemanager is still using CSS instead of BP + * with @Inject. * - *

Please DO NOT copy/paste this class as-is into other projects; this is intended - * to be temporary, until interfacemanager is switch from CSS to BP. + *

+ * Please DO NOT copy/paste this class as-is into other projects; this is + * intended to be temporary, until interfacemanager is switch from CSS to BP. * - *

For "proper" *Module examples, please see the AclServiceModule and + *

+ * For "proper" *Module examples, please see the AclServiceModule and * AclServiceTestModule or ElanServiceTestModule instead. * * @author Michael Vorburger @@ -62,7 +66,8 @@ public class InterfaceManagerTestModule extends AbstractGuiceJsr250Module { @Override protected void configureBindings() throws UnknownHostException { - // TODO Ordering as below.. hard to do currently, because of interdeps. due to CSS + // TODO Ordering as below.. hard to do currently, because of interdeps. + // due to CSS // Bindings for services from this project // Bindings for external services to "real" implementations // Bindings to test infra (fakes & mocks) diff --git a/interfacemanager/interfacemanager-impl/src/test/java/org/opendaylight/genius/interfacemanager/test/InterfaceManagerTestUtil.java b/interfacemanager/interfacemanager-impl/src/test/java/org/opendaylight/genius/interfacemanager/test/InterfaceManagerTestUtil.java index e27d709db..7782e5fc8 100644 --- a/interfacemanager/interfacemanager-impl/src/test/java/org/opendaylight/genius/interfacemanager/test/InterfaceManagerTestUtil.java +++ b/interfacemanager/interfacemanager-impl/src/test/java/org/opendaylight/genius/interfacemanager/test/InterfaceManagerTestUtil.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * Copyright (c) 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, @@ -43,29 +43,35 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology. import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public class InterfaceManagerTestUtil { - public static final String parentInterface = "tap23701c04-7e"; - public static final String interfaceName = "23701c04-7e58-4c65-9425-78a80d49a218"; - public static final String tunnelInterfaceName = "tun414a856a7a4"; + public static final String PARENT_INTERFACE = "tap23701c04-7e"; + public static final String INTERFACE_NAME = "23701c04-7e58-4c65-9425-78a80d49a218"; + public static final String TUNNEL_INTERFACE_NAME = "tun414a856a7a4"; public static final TopologyId OVSDB_TOPOLOGY_ID = new TopologyId(new Uri("ovsdb:1")); - public static final NodeKey nodeKey = new NodeKey(new NodeId("openflow:1")); + public static final NodeKey NODE_KEY = new NodeKey(new NodeId("openflow:1")); - public static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface buildStateInterface( + public static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang + .ietf.interfaces.rev140508.interfaces.state.Interface buildStateInterface( String ifName, String dpnId, String portNo, String phyAddress, Class ifType) { - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceBuilder ifaceBuilder = - new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceBuilder(); - if(ifType != null) { + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang + .ietf.interfaces.rev140508.interfaces.state.InterfaceBuilder ifaceBuilder = + new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang + .ietf.interfaces.rev140508.interfaces.state.InterfaceBuilder(); + if (ifType != null) { ifaceBuilder.setType(ifType); } ifaceBuilder.setKey(IfmUtil.getStateInterfaceKeyFromName(ifName)); - ifaceBuilder.setOperStatus(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus.Up); - ifaceBuilder.setLowerLayerIf(Arrays.asList("openflow:"+dpnId+":"+portNo)); - if(phyAddress != null) { - ifaceBuilder.setPhysAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress.getDefaultInstance(phyAddress)); + ifaceBuilder.setOperStatus( + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang + .ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus.Up); + ifaceBuilder.setLowerLayerIf(Arrays.asList("openflow:" + dpnId + ":" + portNo)); + if (phyAddress != null) { + ifaceBuilder.setPhysAddress( + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress + .getDefaultInstance(phyAddress)); } return ifaceBuilder.build(); } - public static Node buildInventoryDpnNode(BigInteger dpnId) { NodeId nodeId = new NodeId("openflow:" + dpnId); Node nodeDpn = new NodeBuilder().setId(nodeId).setKey(new NodeKey(nodeId)).build(); @@ -74,71 +80,76 @@ public class InterfaceManagerTestUtil { } public static Interface buildInterface(String ifName, String desc, boolean enabled, Object ifType, - String parentInterface) { + String parentInterface) { InterfaceBuilder builder = new InterfaceBuilder().setKey(new InterfaceKey(ifName)).setName(ifName) .setDescription(desc).setEnabled(enabled).setType((Class) ifType); ParentRefs parentRefs = new ParentRefsBuilder().setParentInterface(parentInterface).build(); builder.addAugmentation(ParentRefs.class, parentRefs); - if(ifType.equals(L2vlan.class)){ + if (ifType.equals(L2vlan.class)) { IfL2vlan l2vlan = new IfL2vlanBuilder().setVlanId(VlanId.getDefaultInstance("0")) .setL2vlanMode(IfL2vlan.L2vlanMode.Trunk).build(); builder.addAugmentation(IfL2vlan.class, l2vlan); - }else if(ifType.equals(IfTunnel.class)){ - IfTunnel tunnel = new IfTunnelBuilder().setTunnelDestination(null).setTunnelGateway(null).setTunnelSource(null) - .setTunnelInterfaceType(null).build(); + } else if (ifType.equals(IfTunnel.class)) { + IfTunnel tunnel = new IfTunnelBuilder().setTunnelDestination(null).setTunnelGateway(null) + .setTunnelSource(null).setTunnelInterfaceType(null).build(); builder.addAugmentation(IfTunnel.class, tunnel); } return builder.build(); } - public static Interface buildTunnelInterface(BigInteger dpn, String ifName, String desc, boolean enabled, Class tunType, - String remoteIpStr, String localIpStr) { + public static Interface buildTunnelInterface(BigInteger dpn, String ifName, String desc, boolean enabled, + Class tunType, String remoteIpStr, String localIpStr) { InterfaceBuilder builder = new InterfaceBuilder().setKey(new InterfaceKey(ifName)).setName(ifName) .setDescription(desc).setEnabled(enabled).setType(Tunnel.class); ParentRefs parentRefs = new ParentRefsBuilder().setDatapathNodeIdentifier(dpn).build(); builder.addAugmentation(ParentRefs.class, parentRefs); IpAddress remoteIp = new IpAddress(Ipv4Address.getDefaultInstance(remoteIpStr)); - IpAddress localIp = new IpAddress(Ipv4Address.getDefaultInstance(localIpStr)); - IfTunnel tunnel = new IfTunnelBuilder().setTunnelDestination(remoteIp).setTunnelGateway(localIp).setTunnelSource(localIp) - .setTunnelInterfaceType( tunType).setInternal(true).setMonitorEnabled(false).build(); + IpAddress localIp = new IpAddress(Ipv4Address.getDefaultInstance(localIpStr)); + IfTunnel tunnel = new IfTunnelBuilder().setTunnelDestination(remoteIp).setTunnelGateway(localIp) + .setTunnelSource(localIp).setTunnelInterfaceType(tunType).setInternal(true).setMonitorEnabled(false) + .build(); builder.addAugmentation(IfTunnel.class, tunnel); return builder.build(); } - public static InstanceIdentifier getTerminationPointId(InstanceIdentifier bridgeIid, String portName){ + public static InstanceIdentifier getTerminationPointId(InstanceIdentifier bridgeIid, + String portName) { InstanceIdentifier tpIid = SouthboundUtils.createTerminationPointInstanceIdentifier( - InstanceIdentifier.keyOf(bridgeIid.firstIdentifierOf(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node.class)), portName); + InstanceIdentifier.keyOf(bridgeIid.firstIdentifierOf( + org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns + .yang.network.topology.rev131021.network.topology.topology.Node.class)), + portName); return tpIid; } - public static void deleteInterfaceConfig(DataBroker dataBroker, String ifaceName){ - InstanceIdentifier vlanInterfaceEnabledInterfaceInstanceIdentifier = IfmUtil.buildId( - ifaceName); + public static void deleteInterfaceConfig(DataBroker dataBroker, String ifaceName) { + InstanceIdentifier vlanInterfaceEnabledInterfaceInstanceIdentifier = IfmUtil.buildId(ifaceName); WriteTransaction tx = dataBroker.newWriteOnlyTransaction(); tx.delete(CONFIGURATION, vlanInterfaceEnabledInterfaceInstanceIdentifier); tx.submit(); } public static void putInterfaceConfig(DataBroker dataBroker, String ifaceName, ParentRefs parentRefs, - Class ifType){ + Class ifType) { Interface interfaceInfo; - if(!Tunnel.class.equals(ifType)) { - interfaceInfo = InterfaceManagerTestUtil.buildInterface( - ifaceName, ifaceName, true, ifType, parentRefs.getParentInterface()); - }else{ - interfaceInfo = buildTunnelInterface(parentRefs.getDatapathNodeIdentifier(),ifaceName, ifaceName, true, TunnelTypeVxlan.class, - "1.1.1.1", "2.2.2.2"); + if (!Tunnel.class.equals(ifType)) { + interfaceInfo = InterfaceManagerTestUtil.buildInterface(ifaceName, ifaceName, true, ifType, + parentRefs.getParentInterface()); + } else { + interfaceInfo = buildTunnelInterface(parentRefs.getDatapathNodeIdentifier(), ifaceName, ifaceName, true, + TunnelTypeVxlan.class, "1.1.1.1", "2.2.2.2"); } - InstanceIdentifier interfaceInstanceIdentifier = IfmUtil.buildId( - ifaceName); + InstanceIdentifier interfaceInstanceIdentifier = IfmUtil.buildId(ifaceName); WriteTransaction tx = dataBroker.newWriteOnlyTransaction(); tx.put(CONFIGURATION, interfaceInstanceIdentifier, interfaceInfo, true); tx.submit(); } - public static void putInterfaceState(DataBroker dataBroker, String interfaceName, Class ifType){ - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifaceState = - InterfaceManagerTestUtil.buildStateInterface(interfaceName, "1", "2", "AA:AA:AA:AA:AA:AA", ifType); + public static void putInterfaceState(DataBroker dataBroker, String interfaceName, + Class ifType) { + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508 + .interfaces.state.Interface ifaceState = InterfaceManagerTestUtil + .buildStateInterface(interfaceName, "1", "2", "AA:AA:AA:AA:AA:AA", ifType); WriteTransaction tx = dataBroker.newWriteOnlyTransaction(); tx.put(OPERATIONAL, IfmUtil.buildStateInterfaceId(interfaceName), ifaceState, true); tx.submit(); diff --git a/interfacemanager/interfacemanager-impl/src/test/java/org/opendaylight/genius/interfacemanager/test/OvsdbSouthboundTestUtil.java b/interfacemanager/interfacemanager-impl/src/test/java/org/opendaylight/genius/interfacemanager/test/OvsdbSouthboundTestUtil.java index 6cf021d4a..bc7ca7d0c 100644 --- a/interfacemanager/interfacemanager-impl/src/test/java/org/opendaylight/genius/interfacemanager/test/OvsdbSouthboundTestUtil.java +++ b/interfacemanager/interfacemanager-impl/src/test/java/org/opendaylight/genius/interfacemanager/test/OvsdbSouthboundTestUtil.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 - 2016 Red Hat, Inc. and others. All rights reserved. + * Copyright (c) 2015, 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, @@ -71,61 +71,66 @@ public class OvsdbSouthboundTestUtil { public static final String OVSDB_URI_PREFIX = "ovsdb"; public static final String BRIDGE_URI_PREFIX = "bridge"; - public static final ImmutableBiMap> OVSDB_INTERFACE_TYPE_MAP - = new ImmutableBiMap.Builder>() - .put("internal", InterfaceTypeInternal.class) - .put("vxlan", InterfaceTypeVxlan.class) - .put("vxlan-gpe", InterfaceTypeVxlanGpe.class) - .put("patch", InterfaceTypePatch.class) - .put("system", InterfaceTypeSystem.class) - .put("tap", InterfaceTypeTap.class) - .put("geneve", InterfaceTypeGeneve.class) - .put("gre", InterfaceTypeGre.class) - .put("ipsec_gre", InterfaceTypeIpsecGre.class) - .put("gre64", InterfaceTypeGre64.class) - .put("ipsec_gre64", InterfaceTypeIpsecGre64.class) - .put("lisp", InterfaceTypeLisp.class) - .put("dpdk", InterfaceTypeDpdk.class) - .put("dpdkr", InterfaceTypeDpdkr.class) - .put("dpdkvhost", InterfaceTypeDpdkvhost.class) - .put("dpdkvhostuser", InterfaceTypeDpdkvhostuser.class) + public static final ImmutableBiMap> + OVSDB_INTERFACE_TYPE_MAP = new ImmutableBiMap.Builder>() + .put("internal", InterfaceTypeInternal.class).put("vxlan", InterfaceTypeVxlan.class) + .put("vxlan-gpe", InterfaceTypeVxlanGpe.class).put("patch", InterfaceTypePatch.class) + .put("system", InterfaceTypeSystem.class).put("tap", InterfaceTypeTap.class) + .put("geneve", InterfaceTypeGeneve.class).put("gre", InterfaceTypeGre.class) + .put("ipsec_gre", InterfaceTypeIpsecGre.class).put("gre64", InterfaceTypeGre64.class) + .put("ipsec_gre64", InterfaceTypeIpsecGre64.class).put("lisp", InterfaceTypeLisp.class) + .put("dpdk", InterfaceTypeDpdk.class).put("dpdkr", InterfaceTypeDpdkr.class) + .put("dpdkvhost", InterfaceTypeDpdkvhost.class).put("dpdkvhostuser", InterfaceTypeDpdkvhostuser.class) .build(); - public static NodeId createNodeId(String ip, Integer port) { - String uriString = OVSDB_URI_PREFIX + "://" - + ip + ":" + port; + String uriString = OVSDB_URI_PREFIX + "://" + ip + ":" + port; Uri uri = new Uri(uriString); return new NodeId(uri); } - public static void createBridge(DataBroker dataBroker){ + public static void createBridge(DataBroker dataBroker) { final OvsdbBridgeName ovsdbBridgeName = new OvsdbBridgeName("s2"); - final InstanceIdentifier bridgeIid = - createInstanceIdentifier("192.168.56.101", 6640, ovsdbBridgeName); - final InstanceIdentifier ovsdbBridgeIid = - bridgeIid.builder().augmentation(OvsdbBridgeAugmentation.class).build(); + final InstanceIdentifier bridgeIid = createInstanceIdentifier("192.168.56.101", 6640, ovsdbBridgeName); + final InstanceIdentifier ovsdbBridgeIid = bridgeIid.builder() + .augmentation(OvsdbBridgeAugmentation.class).build(); final NodeId bridgeNodeId = createManagedNodeId(bridgeIid); final NodeBuilder bridgeCreateNodeBuilder = new NodeBuilder(); bridgeCreateNodeBuilder.setNodeId(bridgeNodeId); OvsdbBridgeAugmentationBuilder bridgeCreateAugmentationBuilder = new OvsdbBridgeAugmentationBuilder(); - bridgeCreateAugmentationBuilder.setBridgeName(ovsdbBridgeName).setDatapathId(new DatapathId("00:00:00:00:00:00:00:01")); - bridgeCreateNodeBuilder.addAugmentation(OvsdbBridgeAugmentation.class, - bridgeCreateAugmentationBuilder.build()); + bridgeCreateAugmentationBuilder.setBridgeName(ovsdbBridgeName) + .setDatapathId(new DatapathId("00:00:00:00:00:00:00:01")); + bridgeCreateNodeBuilder.addAugmentation(OvsdbBridgeAugmentation.class, bridgeCreateAugmentationBuilder.build()); LOG.debug("Built with the intent to store bridge data {}", bridgeCreateAugmentationBuilder.toString()); WriteTransaction tx = dataBroker.newWriteOnlyTransaction(); - tx.put(LogicalDatastoreType.OPERATIONAL, ovsdbBridgeIid, - bridgeCreateAugmentationBuilder.build(), true); + tx.put(LogicalDatastoreType.OPERATIONAL, ovsdbBridgeIid, bridgeCreateAugmentationBuilder.build(), true); tx.submit(); + } + public boolean deleteBridge(final ConnectionInfo connectionInfo, final String bridgeName) { + return deleteBridge(connectionInfo, bridgeName, OVSDB_UPDATE_TIMEOUT); } - public static void deleteBridge(DataBroker dataBroker){ + public boolean deleteBridge(final ConnectionInfo connectionInfo, final String bridgeName, long timeout) { + boolean result = true; + // mdsalUtils.delete(LogicalDatastoreType.CONFIGURATION, + // createInstanceIdentifier(connectionInfo, new + // OvsdbBridgeName(bridgeName))); + if (timeout != 0) { + try { + Thread.sleep(timeout); + } catch (InterruptedException e) { + LOG.warn("Interrupted while waiting after deleting bridge {}", bridgeName, e); + } + } + return result; + } + + public static void deleteBridge(DataBroker dataBroker) { final OvsdbBridgeName ovsdbBridgeName = new OvsdbBridgeName("s2"); - final InstanceIdentifier bridgeIid = - createInstanceIdentifier("192.168.56.101", 6640, ovsdbBridgeName); - final InstanceIdentifier ovsdbBridgeIid = - bridgeIid.builder().augmentation(OvsdbBridgeAugmentation.class).build(); + final InstanceIdentifier bridgeIid = createInstanceIdentifier("192.168.56.101", 6640, ovsdbBridgeName); + final InstanceIdentifier ovsdbBridgeIid = bridgeIid.builder() + .augmentation(OvsdbBridgeAugmentation.class).build(); LOG.debug("Built with the intent to delete bridge data {}", bridgeIid.toString()); WriteTransaction tx = dataBroker.newWriteOnlyTransaction(); tx.delete(LogicalDatastoreType.OPERATIONAL, ovsdbBridgeIid); @@ -134,47 +139,50 @@ public class OvsdbSouthboundTestUtil { } public static InstanceIdentifier createInstanceIdentifier(NodeId nodeId) { - return InstanceIdentifier - .create(NetworkTopology.class) - .child(Topology.class, new TopologyKey(OVSDB_TOPOLOGY_ID)) - .child(Node.class,new NodeKey(nodeId)); + return InstanceIdentifier.create(NetworkTopology.class) + .child(Topology.class, new TopologyKey(OVSDB_TOPOLOGY_ID)).child(Node.class, new NodeKey(nodeId)); + } + + public static InstanceIdentifier createInstanceIdentifier(String ip, Integer port) { + InstanceIdentifier path = InstanceIdentifier.create(NetworkTopology.class) + .child(Topology.class, new TopologyKey(OVSDB_TOPOLOGY_ID)).child(Node.class, createNodeKey(ip, port)); + LOG.debug("Created ovsdb path: {}", path); + return path; + } + + public static InstanceIdentifier createInstanceIdentifier(String remoteIp, Integer remotePort, + OvsdbBridgeName bridgeName) { + return createInstanceIdentifier(createManagedNodeId(remoteIp, remotePort, bridgeName)); } public static InstanceIdentifier createInstanceIdentifier(NodeKey ovsdbNodeKey, String bridgeName) { return createInstanceIdentifier(createManagedNodeId(ovsdbNodeKey.getNodeId(), bridgeName)); } - public static NodeId createManagedNodeId(NodeId ovsdbNodeId, String bridgeName) { - return new NodeId(ovsdbNodeId.getValue() - + "/" + BRIDGE_URI_PREFIX + "/" + bridgeName); + public static InstanceIdentifier createInstanceIdentifier(String ip, Integer port, String bridgeName) { + return createInstanceIdentifier(ip, port, new OvsdbBridgeName(bridgeName)); } - public static InstanceIdentifier createInstanceIdentifier(String ip, Integer port) { - InstanceIdentifier path = InstanceIdentifier - .create(NetworkTopology.class) - .child(Topology.class, new TopologyKey(OVSDB_TOPOLOGY_ID)) - .child(Node.class,createNodeKey(ip,port)); - LOG.debug("Created ovsdb path: {}",path); - return path; + public static NodeId createManagedNodeId(String ip, Integer port, OvsdbBridgeName bridgeName) { + return new NodeId(createNodeId(ip, port).getValue() + "/" + BRIDGE_URI_PREFIX + "/" + bridgeName.getValue()); } - public static InstanceIdentifier createInstanceIdentifier(String remoteIp, Integer remotePort,OvsdbBridgeName bridgeName) { - return createInstanceIdentifier(createManagedNodeId(remoteIp, remotePort, bridgeName)); + public static NodeId createManagedNodeId(InstanceIdentifier iid) { + NodeKey nodeKey = iid.firstKeyOf(Node.class); + return nodeKey.getNodeId(); } - public static InstanceIdentifier createInstanceIdentifier(String ip, Integer port, String bridgeName) { - return createInstanceIdentifier(ip, port, new OvsdbBridgeName(bridgeName)); + public static NodeId createManagedNodeId(NodeId ovsdbNodeId, String bridgeName) { + return new NodeId(ovsdbNodeId.getValue() + "/" + BRIDGE_URI_PREFIX + "/" + bridgeName); } - public InstanceIdentifier createTerminationPointInstanceIdentifier(Node node, String portName){ + public InstanceIdentifier createTerminationPointInstanceIdentifier(Node node, String portName) { - InstanceIdentifier terminationPointPath = InstanceIdentifier - .create(NetworkTopology.class) - .child(Topology.class, new TopologyKey(OVSDB_TOPOLOGY_ID)) - .child(Node.class,node.getKey()) + InstanceIdentifier terminationPointPath = InstanceIdentifier.create(NetworkTopology.class) + .child(Topology.class, new TopologyKey(OVSDB_TOPOLOGY_ID)).child(Node.class, node.getKey()) .child(TerminationPoint.class, new TerminationPointKey(new TpId(portName))); - LOG.debug("Termination point InstanceIdentifier generated : {}",terminationPointPath); + LOG.debug("Termination point InstanceIdentifier generated : {}", terminationPointPath); return terminationPointPath; } @@ -182,15 +190,19 @@ public class OvsdbSouthboundTestUtil { return new NodeKey(createNodeId(ip, port)); } + public static ConnectionInfo getConnectionInfo(final String addressStr, final String portStr) { + InetAddress inetAddress = null; + try { + inetAddress = InetAddress.getByName(addressStr); + } catch (UnknownHostException e) { + LOG.warn("Could not allocate InetAddress", e); + } - public static NodeId createManagedNodeId(String ip, Integer port, OvsdbBridgeName bridgeName) { - return new NodeId(createNodeId(ip,port).getValue() - + "/" + BRIDGE_URI_PREFIX + "/" + bridgeName.getValue()); - } + IpAddress address = createIpAddress(inetAddress); + PortNumber port = new PortNumber(Integer.parseInt(portStr)); - public static NodeId createManagedNodeId(InstanceIdentifier iid) { - NodeKey nodeKey = iid.firstKeyOf(Node.class); - return nodeKey.getNodeId(); + LOG.info("connectionInfo: {}", new ConnectionInfoBuilder().setRemoteIp(address).setRemotePort(port).build()); + return new ConnectionInfoBuilder().setRemoteIp(address).setRemotePort(port).build(); } public ConnectionInfo getConnectionInfo(Node ovsdbNode) { @@ -209,9 +221,9 @@ public class OvsdbSouthboundTestUtil { public static IpAddress createIpAddress(InetAddress address) { IpAddress ip = null; if (address instanceof Inet4Address) { - ip = createIpAddress((Inet4Address)address); + ip = createIpAddress((Inet4Address) address); } else if (address instanceof Inet6Address) { - ip = createIpAddress((Inet6Address)address); + ip = createIpAddress((Inet6Address) address); } return ip; } @@ -225,30 +237,9 @@ public class OvsdbSouthboundTestUtil { return new IpAddress(ipv6); } - public static ConnectionInfo getConnectionInfo(final String addressStr, final String portStr) { - InetAddress inetAddress = null; - try { - inetAddress = InetAddress.getByName(addressStr); - } catch (UnknownHostException e) { - LOG.warn("Could not allocate InetAddress", e); - } - - IpAddress address = createIpAddress(inetAddress); - PortNumber port = new PortNumber(Integer.parseInt(portStr)); - - LOG.info("connectionInfo: {}", new ConnectionInfoBuilder() - .setRemoteIp(address) - .setRemotePort(port) - .build()); - return new ConnectionInfoBuilder() - .setRemoteIp(address) - .setRemotePort(port) - .build(); - } - public static String connectionInfoToString(final ConnectionInfo connectionInfo) { - return String.valueOf( - connectionInfo.getRemoteIp().getValue()) + ":" + connectionInfo.getRemotePort().getValue(); + return String.valueOf(connectionInfo.getRemoteIp().getValue()) + ":" + + connectionInfo.getRemotePort().getValue(); } public boolean addOvsdbNode(final ConnectionInfo connectionInfo) { @@ -257,23 +248,23 @@ public class OvsdbSouthboundTestUtil { public boolean addOvsdbNode(final ConnectionInfo connectionInfo, long timeout) { boolean result = true; - //mdsalUtils.put(LogicalDatastoreType.CONFIGURATION, - //createInstanceIdentifier(connectionInfo), - //createNode(connectionInfo)); + // mdsalUtils.put(LogicalDatastoreType.CONFIGURATION, + // createInstanceIdentifier(connectionInfo), + // createNode(connectionInfo)); if (timeout != 0) { try { Thread.sleep(timeout); } catch (InterruptedException e) { - LOG.warn("Interrupted while waiting after adding OVSDB node {}", - connectionInfoToString(connectionInfo), e); + LOG.warn("Interrupted while waiting after adding OVSDB node {}", connectionInfoToString(connectionInfo), + e); } } return result; } public Node getOvsdbNode(final ConnectionInfo connectionInfo) { - //return mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, - // createInstanceIdentifier(connectionInfo)); + // return mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, + // createInstanceIdentifier(connectionInfo)); return null; } @@ -283,8 +274,8 @@ public class OvsdbSouthboundTestUtil { public boolean deleteOvsdbNode(final ConnectionInfo connectionInfo, long timeout) { boolean result = true; - //mdsalUtils.delete(LogicalDatastoreType.CONFIGURATION, - //createInstanceIdentifier(connectionInfo)); + // mdsalUtils.delete(LogicalDatastoreType.CONFIGURATION, + // createInstanceIdentifier(connectionInfo)); if (timeout != 0) { try { Thread.sleep(timeout); @@ -319,9 +310,7 @@ public class OvsdbSouthboundTestUtil { public List createControllerEntry(String controllerTarget) { List controllerEntriesList = new ArrayList<>(); - controllerEntriesList.add(new ControllerEntryBuilder() - .setTarget(new Uri(controllerTarget)) - .build()); + controllerEntriesList.add(new ControllerEntryBuilder().setTarget(new Uri(controllerTarget)).build()); return controllerEntriesList; } @@ -335,23 +324,4 @@ public class OvsdbSouthboundTestUtil { } return node.getAugmentation(OvsdbBridgeAugmentation.class); } - - public boolean deleteBridge(final ConnectionInfo connectionInfo, final String bridgeName) { - return deleteBridge(connectionInfo, bridgeName, OVSDB_UPDATE_TIMEOUT); - } - - public boolean deleteBridge(final ConnectionInfo connectionInfo, final String bridgeName, long timeout) { - boolean result = true; - //mdsalUtils.delete(LogicalDatastoreType.CONFIGURATION, - //createInstanceIdentifier(connectionInfo, new OvsdbBridgeName(bridgeName))); - if (timeout != 0) { - try { - Thread.sleep(timeout); - } catch (InterruptedException e) { - LOG.warn("Interrupted while waiting after deleting bridge {}", bridgeName, e); - } - } - return result; - } - } -- 2.36.6