*/
package org.opendaylight.openflowplugin.openflow.md.core.translator;
-import java.math.BigInteger;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.concurrent.CopyOnWriteArrayList;
-
+import org.opendaylight.openflowplugin.openflow.md.OFConstants;
import org.opendaylight.openflowplugin.openflow.md.core.IMDMessageTranslator;
import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDistinguisher;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchConvertorImpl;
import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext;
+import org.opendaylight.openflowplugin.openflow.md.util.ByteUtil;
import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
+import org.opendaylight.openflowplugin.openflow.md.util.OpenflowVersion;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6FlowLabel;
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.service.rev130819.SwitchFlowRemovedBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.RemovedReasonFlags;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.mod.removed.Match;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.mod.removed.MatchBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpSrc;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanPcp;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanVid;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntries;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.math.BigInteger;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.concurrent.CopyOnWriteArrayList;
+
public class FlowRemovedTranslator implements IMDMessageTranslator<OfHeader, List<DataObject>> {
protected static final Logger LOG = LoggerFactory.getLogger(FlowRemovedTranslator.class);
SwitchFlowRemovedBuilder salFlowRemoved = new SwitchFlowRemovedBuilder();
- salFlowRemoved.setCookie(ofFlow.getCookie());
+ salFlowRemoved.setCookie(new FlowCookie(ofFlow.getCookie()));
salFlowRemoved.setPriority(ofFlow.getPriority());
if (ofFlow.getTableId() != null) {
FlowRemovedReason.OFPRRHARDTIMEOUT.equals(ofFlow.getReason()),
FlowRemovedReason.OFPRRIDLETIMEOUT.equals(ofFlow.getReason())
);
-
+
salFlowRemoved.setRemovedReason(removeReasonFlag);
-
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.match.grouping.Match ofMatch = ofFlow
+
+ OpenflowVersion ofVersion = OpenflowVersion.get(sc.getPrimaryConductor().getVersion());
+ org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.Match ofMatch = ofFlow
.getMatch();
if (ofMatch != null) {
- salFlowRemoved.setMatch(fromMatch(ofMatch,sc.getFeatures().getDatapathId()));
+ salFlowRemoved.setMatch(fromMatch(ofMatch, sc.getFeatures().getDatapathId(), ofVersion));
}
else if(ofFlow.getMatchV10() != null){
- MatchBuilder matchBuilder = new MatchBuilder(MatchConvertorImpl.fromOFMatchV10ToSALMatch(ofFlow.getMatchV10(),sc.getFeatures().getDatapathId()));
+ MatchBuilder matchBuilder = new MatchBuilder(MatchConvertorImpl.fromOFMatchV10ToSALMatch(ofFlow.getMatchV10(), sc.getFeatures().getDatapathId(), ofVersion));
salFlowRemoved.setMatch(matchBuilder.build());
}
salFlowRemoved.setNode(new NodeRef(InventoryDataServiceUtil.identifierFromDatapathId(sc.getFeatures()
return Collections.emptyList();
}
}
-
-
- public Match fromMatch(
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.match.grouping.Match ofMatch,BigInteger datapathid) {
+
+
+ public Match fromMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.Match ofMatch,
+ BigInteger datapathid, OpenflowVersion ofVersion) {
MatchBuilder matchBuilder = new MatchBuilder();
EthernetMatchBuilder ethernetMatch = null;
VlanMatchBuilder vlanMatch = null;
for (MatchEntries entry : ofMatch.getMatchEntries()) {
Class<? extends MatchField> field = entry.getOxmMatchField();
if (field.equals(InPort.class)) {
- matchBuilder.setInPort(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(datapathid,entry.getAugmentation(PortNumberMatchEntry.class).getPortNumber().getValue()
- .longValue()));
+ matchBuilder.setInPort(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(datapathid,
+ entry.getAugmentation(PortNumberMatchEntry.class).getPortNumber().getValue().longValue(), ofVersion));
} else if (field.equals(InPhyPort.class)) {
- matchBuilder.setInPhyPort(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(datapathid,entry.getAugmentation(PortNumberMatchEntry.class).getPortNumber().getValue()
- .longValue()));
+ matchBuilder.setInPhyPort(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(datapathid,
+ entry.getAugmentation(PortNumberMatchEntry.class).getPortNumber().getValue().longValue(), ofVersion));
} else if (field.equals(Metadata.class)) {
MetadataBuilder metadata = new MetadataBuilder();
metadata.setMetadata(new BigInteger(1, entry.getAugmentation(MetadataMatchEntry.class).getMetadata()));
if (entry.isHasMask()) {
- metadata.setMetadataMask(entry.getAugmentation(MaskMatchEntry.class).getMask());
+ metadata.setMetadataMask(new BigInteger(OFConstants.SIGNUM_UNSIGNED, entry.getAugmentation(MaskMatchEntry.class).getMask()));
}
matchBuilder.setMetadata(metadata.build());
} else if (field.equals(EthDst.class) || field.equals(EthSrc.class) || field.equals(EthType.class)) {
EthernetDestinationBuilder ethDst = new EthernetDestinationBuilder();
ethDst.setAddress(entry.getAugmentation(MacAddressMatchEntry.class).getMacAddress());
if (entry.isHasMask()) {
- ethDst.setMask(entry.getAugmentation(MaskMatchEntry.class).getMask());
+ ethDst.setMask(new MacAddress(ByteUtil.bytesToHexstring(entry.getAugmentation(MaskMatchEntry.class).getMask(),":")));
}
ethernetMatch.setEthernetDestination(ethDst.build());
} else if (field.equals(EthSrc.class)) {
EthernetSourceBuilder ethSrc = new EthernetSourceBuilder();
ethSrc.setAddress(entry.getAugmentation(MacAddressMatchEntry.class).getMacAddress());
if (entry.isHasMask()) {
- ethSrc.setMask(entry.getAugmentation(MaskMatchEntry.class).getMask());
+ ethSrc.setMask(new MacAddress(ByteUtil.bytesToHexstring(entry.getAugmentation(MaskMatchEntry.class).getMask(),":")));
}
ethernetMatch.setEthernetSource(ethSrc.build());
} else if (field.equals(EthType.class)) {
ArpSourceHardwareAddressBuilder arpSha = new ArpSourceHardwareAddressBuilder();
arpSha.setAddress(entry.getAugmentation(MacAddressMatchEntry.class).getMacAddress());
if (entry.isHasMask()) {
- arpSha.setMask(entry.getAugmentation(MaskMatchEntry.class).getMask());
+ arpSha.setMask(new MacAddress(ByteUtil.bytesToHexstring(entry.getAugmentation(MaskMatchEntry.class).getMask(),":")));
}
arpMatch.setArpSourceHardwareAddress(arpSha.build());
} else if (field.equals(ArpTha.class)) {
ArpTargetHardwareAddressBuilder arpTha = new ArpTargetHardwareAddressBuilder();
arpTha.setAddress(entry.getAugmentation(MacAddressMatchEntry.class).getMacAddress());
if (entry.isHasMask()) {
- arpTha.setMask(entry.getAugmentation(MaskMatchEntry.class).getMask());
+ arpTha.setMask(new MacAddress(ByteUtil.bytesToHexstring(entry.getAugmentation(MaskMatchEntry.class).getMask(),":")));
}
arpMatch.setArpTargetHardwareAddress(arpTha.build());
}
Ipv6LabelBuilder ipv6Label = new Ipv6LabelBuilder();
ipv6Label.setIpv6Flabel(entry.getAugmentation(Ipv6FlabelMatchEntry.class).getIpv6Flabel());
if (entry.isHasMask()) {
- ipv6Label.setFlabelMask(entry.getAugmentation(MaskMatchEntry.class).getMask());
+ ipv6Label.setFlabelMask(new Ipv6FlowLabel(ByteUtil.bytesToUnsignedInt(entry.getAugmentation(MaskMatchEntry.class).getMask())));
}
ipv6Match.setIpv6Label(ipv6Label.build());
} else if (field.equals(Ipv6NdTarget.class)) {
int bitmap = fillBitMaskFromMap(map);
ipv6ExtHeaderBuilder.setIpv6Exthdr(bitmap);
if (entry.isHasMask()) {
- ipv6ExtHeaderBuilder.setIpv6ExthdrMask(entry.getAugmentation(MaskMatchEntry.class).getMask());
+ ipv6ExtHeaderBuilder.setIpv6ExthdrMask(
+ ByteUtil.bytesToUnsignedShort(entry.getAugmentation(MaskMatchEntry.class).getMask()));
}
ipv6Match.setIpv6ExtHeader(ipv6ExtHeaderBuilder.build());
}
PbbBuilder pbb = new PbbBuilder();
pbb.setPbbIsid(entry.getAugmentation(IsidMatchEntry.class).getIsid());
if (entry.isHasMask()) {
- pbb.setPbbMask(entry.getAugmentation(MaskMatchEntry.class).getMask());
+ pbb.setPbbMask(ByteUtil.bytesToUnsignedInt(entry.getAugmentation(MaskMatchEntry.class).getMask()));
}
protocolMatchFields.setPbb(pbb.build());
}
TunnelBuilder tunnel = new TunnelBuilder();
tunnel.setTunnelId(new BigInteger(1, entry.getAugmentation(MetadataMatchEntry.class).getMetadata()));
if (entry.isHasMask()) {
- tunnel.setTunnelMask(entry.getAugmentation(MaskMatchEntry.class).getMask());
+ tunnel.setTunnelMask(new BigInteger(OFConstants.SIGNUM_UNSIGNED, entry.getAugmentation(MaskMatchEntry.class).getMask()));
}
matchBuilder.setTunnel(tunnel.build());
}