X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fcompatibility%2Fsal-compatibility%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fcompatibility%2FFromSalConversionsUtils.java;h=8468c2d7f5fc333da47ff314eb9d9c1d2d7b0919;hp=eba4aa901bdc1d2496a485c9676024bb01002f3b;hb=da19620fa7bf6af3ab28c90ebd4df8eec920ec2c;hpb=91d7c1ee52322acad08e9f81228ac36b3aa684f5 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 eba4aa901b..8468c2d7f5 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,3 +1,10 @@ +/* + * 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; @@ -54,10 +61,16 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026 import com.google.common.net.InetAddresses; -public class FromSalConversionsUtils { +/** + * MD-SAL to AD-SAL conversions collection + */ +public final class FromSalConversionsUtils { - private FromSalConversionsUtils() { + /** http://en.wikipedia.org/wiki/IPv4#Packet_structure (end of octet number 1, bit 14.+15.) */ + public static final int ENC_FIELD_BIT_SIZE = 2; + private FromSalConversionsUtils() { + throw new IllegalAccessError("forcing no instance for factory"); } @SuppressWarnings("unused") @@ -96,7 +109,8 @@ 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)) { - return new NodeConnectorId(((NodeConnector) inPort.getValue()).getNodeConnectorIdAsString()); + NodeConnector port = (NodeConnector)inPort.getValue(); + return (NodeConnectorId)MDFlowMapping.toUri(port); } return null; } @@ -196,8 +210,11 @@ public class FromSalConversionsUtils { MatchField vlan = sourceMatch.getField(MatchType.DL_VLAN); if (vlan != null && vlan.getValue() != null) { VlanIdBuilder vlanIDBuilder = new VlanIdBuilder(); + short vid = (short)vlan.getValue(); + boolean present = (vid != MatchType.DL_VLAN_NONE); vlanIDBuilder.setVlanId(new VlanId((NetUtils - .getUnsignedShort((short) vlan.getValue())))); + .getUnsignedShort(vid)))); + vlanIDBuilder.setVlanIdPresent(present); vlanMatchBuild.setVlanId(vlanIDBuilder.build()); } @@ -254,11 +271,11 @@ public class FromSalConversionsUtils { .setType(etherType); targetEthMatchBuild.setEthernetType(ethType.build()); } - if((sourceMatch.getField(DL_SRC) != null && sourceMatch.getField(DL_SRC).getValue() != null) || - (sourceMatch.getField(DL_DST) != null && sourceMatch.getField(DL_DST).getValue() != null)|| + 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 targetEthMatchBuild.build(); + } return null; } @@ -314,11 +331,11 @@ public class FromSalConversionsUtils { final Inet4Address inetDestAddress) { String inetSourceAddressStr = InetAddresses .toAddrString(inetSourceAddress); - Ipv4Prefix ipv4SourcePrefix = new Ipv4Prefix(inetSourceAddressStr); + Ipv4Prefix ipv4SourcePrefix = new Ipv4Prefix(inetSourceAddressStr + "/32"); String inetDestAddressValue = InetAddresses .toAddrString(inetDestAddress); - Ipv4Prefix ipv4DestPrefix = new Ipv4Prefix(inetDestAddressValue); + Ipv4Prefix ipv4DestPrefix = new Ipv4Prefix(inetDestAddressValue + "/32"); ArpMatchBuilder arpMatchBuilder = new ArpMatchBuilder(); @@ -358,14 +375,14 @@ public class FromSalConversionsUtils { if(inetSourceAddress != null) { String inetSrcAddressString = InetAddresses .toAddrString(inetSourceAddress); - layer4MatchBuild.setIpv4Source(new Ipv4Prefix(inetSrcAddressString)); + layer4MatchBuild.setIpv4Source(new Ipv4Prefix(inetSrcAddressString + "/32")); } if(inetDestAddress != null) { String inetDstAddressString = InetAddresses .toAddrString(inetDestAddress); layer4MatchBuild - .setIpv4Destination(new Ipv4Prefix(inetDstAddressString)); - } + .setIpv4Destination(new Ipv4Prefix(inetDstAddressString + "/32")); + } return layer4MatchBuild.build(); } @@ -377,17 +394,17 @@ public class FromSalConversionsUtils { if(inetSourceAddress != null) { String inetSrcAddressString = InetAddresses .toAddrString(inetSourceAddress); - layer6MatchBuild.setIpv6Source(new Ipv6Prefix(inetSrcAddressString)); + layer6MatchBuild.setIpv6Source(new Ipv6Prefix(inetSrcAddressString + "/128")); } if(inetDestAddress != null) { String inetDstAddressString = InetAddresses - .toAddrString(inetDestAddress); + .toAddrString(inetDestAddress); layer6MatchBuild - .setIpv6Destination(new Ipv6Prefix(inetDstAddressString)); + .setIpv6Destination(new Ipv6Prefix(inetDstAddressString + "/128")); } return layer6MatchBuild.build(); } - + public static boolean flowEquals(Flow statsFlow, Flow storedFlow) { if (statsFlow.getClass() != storedFlow.getClass()) { return false; @@ -458,5 +475,12 @@ public class FromSalConversionsUtils { return true; } + /** + * @param nwDscp NW-DSCP + * @return shifted to NW-TOS (with empty ECN part) + */ + public static int dscpToTos(int nwDscp) { + return (short) (nwDscp << ENC_FIELD_BIT_SIZE); + } }