X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fcompatibility%2Fsal-compatibility%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fcompatibility%2FFromSalConversionsUtils.java;h=1b648dc98c36c0c6e05bfce6740b294dd730e8b8;hb=7e24111a0842d66187c752022aa975c411b42cca;hp=cc86659657883ad48d01ef45609d076d6cf7e590;hpb=f27f2337e171c9f944de55a3ac6650b3b1ec0af2;p=controller.git diff --git a/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/FromSalConversionsUtils.java b/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/FromSalConversionsUtils.java index cc86659657..1b648dc98c 100644 --- a/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/FromSalConversionsUtils.java +++ b/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/FromSalConversionsUtils.java @@ -1,5 +1,16 @@ +/* + * Copyright (c) 2014 Cisco Systems, 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, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ package org.opendaylight.controller.sal.compatibility; +import static org.opendaylight.controller.sal.compatibility.ProtocolConstants.CRUDP; +import static org.opendaylight.controller.sal.compatibility.ProtocolConstants.ETHERNET_ARP; +import static org.opendaylight.controller.sal.compatibility.ProtocolConstants.TCP; +import static org.opendaylight.controller.sal.compatibility.ProtocolConstants.UDP; import static org.opendaylight.controller.sal.match.MatchType.DL_DST; import static org.opendaylight.controller.sal.match.MatchType.DL_SRC; import static org.opendaylight.controller.sal.match.MatchType.DL_TYPE; @@ -8,12 +19,7 @@ import java.net.Inet4Address; import java.net.Inet6Address; import java.net.InetAddress; - -import org.opendaylight.controller.sal.compatibility.MDFlowMapping; import org.opendaylight.controller.sal.core.NodeConnector; - - - import org.opendaylight.controller.sal.match.Match; import org.opendaylight.controller.sal.match.MatchField; import org.opendaylight.controller.sal.match.MatchType; @@ -23,14 +29,12 @@ 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.inet.types.rev100924.Ipv6Prefix; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetNodeConnectorStatisticsInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetNodeConnectorStatisticsInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.Address; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4Builder; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv6Builder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId; import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType; import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId; import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp; @@ -54,9 +58,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatchBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder; + import com.google.common.net.InetAddresses; -import static org.opendaylight.controller.sal.compatibility.NodeMapping.*; -import static org.opendaylight.controller.sal.compatibility.ProtocolConstants.*; public class FromSalConversionsUtils { @@ -64,19 +67,7 @@ public class FromSalConversionsUtils { } - public static GetNodeConnectorStatisticsInput nodeConnectorStatistics( - NodeConnector connector) { - GetNodeConnectorStatisticsInputBuilder target = new GetNodeConnectorStatisticsInputBuilder(); - - NodeRef nodeRef = toNodeRef(connector.getNode()); - target.setNode(nodeRef); - - NodeConnectorRef nodeConnectorRef = toNodeConnectorRef(connector); - target.setNodeConnector(nodeConnectorRef); - - return target.build(); - } - + @SuppressWarnings("unused") private static Address addressFromAction(InetAddress inetAddress) { String strInetAddresss = InetAddresses.toAddrString(inetAddress); if (inetAddress instanceof Inet4Address) { @@ -101,6 +92,7 @@ public class FromSalConversionsUtils { targetBuilder.setVlanMatch(vlanMatch(sourceMatch)); targetBuilder.setLayer3Match(layer3Match(sourceMatch)); targetBuilder.setLayer4Match(layer4Match(sourceMatch)); + targetBuilder.setInPort(inPortMatch(sourceMatch)); return targetBuilder.build(); } @@ -108,6 +100,15 @@ public class FromSalConversionsUtils { } + private static NodeConnectorId inPortMatch(Match sourceMatch) { + MatchField inPort = sourceMatch.getField(MatchType.IN_PORT); + if(inPort != null && inPort.getValue() != null && (inPort.getValue() instanceof NodeConnector)) { + NodeConnector port = (NodeConnector)inPort.getValue(); + return (NodeConnectorId)MDFlowMapping.toUri(port); + } + return null; + } + private static Layer4Match layer4Match(final Match sourceMatch) { MatchField nwProto = sourceMatch.getField(MatchType.NW_PROTO); Short nwProtocolSource = null; @@ -118,7 +119,7 @@ public class FromSalConversionsUtils { return Layer4MatchAsTcp(sourceMatch); case UDP: return Layer4MatchAsUdp(sourceMatch); - case SCTP: + case CRUDP: return Layer4MatchAsSctp(sourceMatch); } } @@ -139,8 +140,10 @@ public class FromSalConversionsUtils { sctpMatchBuilder.setSctpDestinationPort(new PortNumber( destinationPort)); } - - return sctpMatchBuilder.build(); + if(sourcePort != null || destinationPort != null) { + return sctpMatchBuilder.build(); + } + return null; } private static Layer4Match Layer4MatchAsUdp(final Match sourceMatch) { @@ -158,8 +161,10 @@ public class FromSalConversionsUtils { udpMatchBuilder.setUdpDestinationPort(new PortNumber( destinationPort)); } - - return udpMatchBuilder.build(); + if(sourcePort != null || destinationPort != null) { + return udpMatchBuilder.build(); + } + return null; } private static Layer4Match Layer4MatchAsTcp(final Match sourceMatch) { @@ -176,8 +181,10 @@ public class FromSalConversionsUtils { tcpMatchBuilder.setTcpDestinationPort(new PortNumber( destinationPort)); } - - return tcpMatchBuilder.build(); + if(sourcePort != null || destinationPort != null) { + return tcpMatchBuilder.build(); + } + return null; } private static Integer transportPort(final Match sourceMatch, @@ -197,8 +204,11 @@ public class FromSalConversionsUtils { MatchField vlan = sourceMatch.getField(MatchType.DL_VLAN); if (vlan != null && vlan.getValue() != null) { VlanIdBuilder vlanIDBuilder = new VlanIdBuilder(); - vlanIDBuilder.setVlanId(new VlanId((int) (NetUtils - .getUnsignedShort((short) vlan.getValue())))); + short vid = (short)vlan.getValue(); + boolean present = (vid != MatchType.DL_VLAN_NONE); + vlanIDBuilder.setVlanId(new VlanId((NetUtils + .getUnsignedShort(vid)))); + vlanIDBuilder.setVlanIdPresent(present); vlanMatchBuild.setVlanId(vlanIDBuilder.build()); } @@ -207,8 +217,10 @@ public class FromSalConversionsUtils { vlanMatchBuild.setVlanPcp(new VlanPcp((short) ((byte) vlanPriority .getValue()))); } - - return vlanMatchBuild.build(); + if((vlan != null && vlan.getValue() != null) || (vlanPriority != null && vlanPriority.getValue() != null)) { + return vlanMatchBuild.build(); + } + return null; } private static IpMatch ipMatch(final Match sourceMatch) { @@ -226,21 +238,24 @@ public class FromSalConversionsUtils { targetIpMatchBuild.setIpProtocol((short) ((byte) protocol .getValue())); } - - return targetIpMatchBuild.build(); - + if((networkTos != null && networkTos.getValue() != null) || (protocol != null && protocol.getValue() != null)) { + return targetIpMatchBuild.build(); + } + return null; } private static EthernetMatch ethernetMatch(final Match sourceMatch) { final EthernetMatchBuilder targetEthMatchBuild = new EthernetMatchBuilder(); - - EthernetSourceBuilder ethSourBuild = new EthernetSourceBuilder() - .setAddress(ethernetSourceAddress(sourceMatch)); - targetEthMatchBuild.setEthernetSource(ethSourBuild.build()); - - EthernetDestinationBuilder ethDestBuild = new EthernetDestinationBuilder() - .setAddress(ethernetDestAddress(sourceMatch)); - targetEthMatchBuild.setEthernetDestination(ethDestBuild.build()); + if(sourceMatch.getField(DL_SRC) != null && sourceMatch.getField(DL_SRC).getValue() != null) { + EthernetSourceBuilder ethSourBuild = new EthernetSourceBuilder() + .setAddress(ethernetSourceAddress(sourceMatch)); + targetEthMatchBuild.setEthernetSource(ethSourBuild.build()); + } + if(sourceMatch.getField(DL_DST) != null && sourceMatch.getField(DL_DST).getValue() != null) { + EthernetDestinationBuilder ethDestBuild = new EthernetDestinationBuilder() + .setAddress(ethernetDestAddress(sourceMatch)); + targetEthMatchBuild.setEthernetDestination(ethDestBuild.build()); + } final MatchField dataLinkType = sourceMatch.getField(MatchType.DL_TYPE); if (dataLinkType != null && dataLinkType.getValue() != null) { @@ -250,7 +265,12 @@ public class FromSalConversionsUtils { .setType(etherType); targetEthMatchBuild.setEthernetType(ethType.build()); } - return targetEthMatchBuild.build(); + if((sourceMatch.getField(DL_SRC) != null && sourceMatch.getField(DL_SRC).getValue() != null) || + (sourceMatch.getField(DL_DST) != null && sourceMatch.getField(DL_DST).getValue() != null)|| + dataLinkType != null ) { + return targetEthMatchBuild.build(); + } + return null; } private static MacAddress ethernetSourceAddress(final Match sourceMatch) { @@ -271,12 +291,12 @@ public class FromSalConversionsUtils { InetAddress inetDestAddress = null; MatchField netDest = sourceMatch.getField(MatchType.NW_DST); - if (netSource != null && netSource.getValue() != null) { + if (netDest != null && netDest.getValue() != null) { inetDestAddress = (InetAddress) (netDest.getValue()); } if ((inetSourceAddress instanceof Inet4Address) - && (inetDestAddress instanceof Inet4Address)) { + || (inetDestAddress instanceof Inet4Address)) { MatchField dataLinkType = sourceMatch.getField(DL_TYPE); Short dLType = null; if (dataLinkType != null && dataLinkType.getValue() != null) { @@ -291,7 +311,7 @@ public class FromSalConversionsUtils { (Inet4Address) inetDestAddress); } } else if ((inetSourceAddress instanceof Inet6Address) - && (inetDestAddress instanceof Inet6Address)) { + || (inetDestAddress instanceof Inet6Address)) { return setLayer3MatchAsIpv6((Inet6Address) inetSourceAddress, (Inet6Address) inetDestAddress); } @@ -345,15 +365,18 @@ public class FromSalConversionsUtils { private static Layer3Match setLayer3MatchAsIpv4( final Inet4Address inetSourceAddress, final Inet4Address inetDestAddress) { - String inetSrcAddressString = InetAddresses - .toAddrString(inetSourceAddress); - String inetDstAddressString = InetAddresses - .toAddrString(inetDestAddress); - Ipv4MatchBuilder layer4MatchBuild = new Ipv4MatchBuilder(); - layer4MatchBuild.setIpv4Source(new Ipv4Prefix(inetSrcAddressString)); - layer4MatchBuild - .setIpv4Destination(new Ipv4Prefix(inetDstAddressString)); + if(inetSourceAddress != null) { + String inetSrcAddressString = InetAddresses + .toAddrString(inetSourceAddress); + layer4MatchBuild.setIpv4Source(new Ipv4Prefix(inetSrcAddressString)); + } + if(inetDestAddress != null) { + String inetDstAddressString = InetAddresses + .toAddrString(inetDestAddress); + layer4MatchBuild + .setIpv4Destination(new Ipv4Prefix(inetDstAddressString)); + } return layer4MatchBuild.build(); } @@ -361,16 +384,90 @@ public class FromSalConversionsUtils { private static Layer3Match setLayer3MatchAsIpv6( final Inet6Address inetSourceAddress, final Inet6Address inetDestAddress) { - String inetSrcAddressString = InetAddresses - .toAddrString(inetSourceAddress); - String inetDstAddressString = InetAddresses - .toAddrString(inetDestAddress); Ipv6MatchBuilder layer6MatchBuild = new Ipv6MatchBuilder(); - - layer6MatchBuild.setIpv6Source(new Ipv6Prefix(inetSrcAddressString)); - layer6MatchBuild - .setIpv6Destination(new Ipv6Prefix(inetDstAddressString)); + if(inetSourceAddress != null) { + String inetSrcAddressString = InetAddresses + .toAddrString(inetSourceAddress); + layer6MatchBuild.setIpv6Source(new Ipv6Prefix(inetSrcAddressString)); + } + if(inetDestAddress != null) { + String inetDstAddressString = InetAddresses + .toAddrString(inetDestAddress); + layer6MatchBuild + .setIpv6Destination(new Ipv6Prefix(inetDstAddressString)); + } return layer6MatchBuild.build(); } + public static boolean flowEquals(Flow statsFlow, Flow storedFlow) { + if (statsFlow.getClass() != storedFlow.getClass()) { + return false; + } + if (statsFlow.getBufferId()== null) { + if (storedFlow.getBufferId() != null) { + return false; + } + } else if(!statsFlow.getBufferId().equals(storedFlow.getBufferId())) { + return false; + } + if (statsFlow.getContainerName()== null) { + if (storedFlow.getContainerName()!= null) { + return false; + } + } else if(!statsFlow.getContainerName().equals(storedFlow.getContainerName())) { + return false; + } + if (statsFlow.getCookie()== null) { + if (storedFlow.getCookie()!= null) { + return false; + } + } else if(!statsFlow.getCookie().equals(storedFlow.getCookie())) { + return false; + } + if (statsFlow.getMatch()== null) { + if (storedFlow.getMatch() != null) { + return false; + } + } else if(!statsFlow.getMatch().equals(storedFlow.getMatch())) { + return false; + } + if (statsFlow.getCookie()== null) { + if (storedFlow.getCookie()!= null) { + return false; + } + } else if(!statsFlow.getCookie().equals(storedFlow.getCookie())) { + return false; + } + if (statsFlow.getHardTimeout() == null) { + if (storedFlow.getHardTimeout() != null) { + return false; + } + } else if(!statsFlow.getHardTimeout().equals(storedFlow.getHardTimeout() )) { + return false; + } + if (statsFlow.getIdleTimeout()== null) { + if (storedFlow.getIdleTimeout() != null) { + return false; + } + } else if(!statsFlow.getIdleTimeout().equals(storedFlow.getIdleTimeout())) { + return false; + } + if (statsFlow.getPriority() == null) { + if (storedFlow.getPriority() != null) { + return false; + } + } else if(!statsFlow.getPriority().equals(storedFlow.getPriority())) { + return false; + } + if (statsFlow.getTableId() == null) { + if (storedFlow.getTableId() != null) { + return false; + } + } else if(!statsFlow.getTableId().equals(storedFlow.getTableId())) { + return false; + } + return true; + } + + }