use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10 in project openflowplugin by opendaylight.
the class MatchResponseConvertorTest method testFromOFMatchV10ToSALMatch.
/**
* Test method for {@link MatchV10ResponseConvertor#convert(MatchV10, VersionDatapathIdConvertorData)} }.
*/
@Test
public void testFromOFMatchV10ToSALMatch() {
int[] vids = { // Match untagged frame.
DL_VLAN_NONE, // Match packet with VLAN tag and VID equals the specified value.
1, 20, 4095 };
short[] dscps = { 0, 1, 20, 40, 62, 63 };
FlowWildcardsV10Builder wcBuilder = new FlowWildcardsV10Builder();
for (int vid : vids) {
for (short dscp : dscps) {
short tos = (short) (dscp << 2);
MatchV10Builder builder = new MatchV10Builder();
builder.setDlSrc(MAC_SRC).setDlDst(MAC_DST).setDlVlan(vid).setDlVlanPcp(VLAN_PCP).setDlType(ETHTYPE_IPV4).setInPort(IN_PORT.intValue()).setNwSrc(IPV4_SRC).setNwDst(IPV4_DST).setNwTos(tos);
wcBuilder.setAll(false).setNwProto(true).setTpSrc(true).setTpDst(true);
if (vid == DL_VLAN_NONE) {
wcBuilder.setDlVlanPcp(true);
}
FlowWildcardsV10 wc = wcBuilder.build();
MatchV10 ofMatch = builder.setWildcards(wc).build();
final VersionDatapathIdConvertorData data = new VersionDatapathIdConvertorData(OFConstants.OFP_VERSION_1_0);
data.setDatapathId(DPID);
Match match = convert(ofMatch, data).build();
checkDefaultV10(match, wc, vid);
IpMatch ipMatch = match.getIpMatch();
assertEquals(null, ipMatch.getIpProtocol());
assertEquals(dscp, ipMatch.getIpDscp().getValue().shortValue());
assertEquals(null, ipMatch.getIpEcn());
// Set all wildcard bits.
wc = wcBuilder.setAll(true).build();
ofMatch = builder.setWildcards(wc).build();
match = convert(ofMatch, data).build();
checkDefaultV10(match, wc, vid);
assertEquals(null, match.getIpMatch());
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10 in project openflowplugin by opendaylight.
the class MatchV10ResponseConvertor method convert.
@Override
public MatchBuilder convert(MatchV10 source, VersionDatapathIdConvertorData datapathIdConvertorData) {
MatchBuilder matchBuilder = new MatchBuilder();
EthernetMatchBuilder ethMatchBuilder = new EthernetMatchBuilder();
VlanMatchBuilder vlanMatchBuilder = new VlanMatchBuilder();
Ipv4MatchBuilder ipv4MatchBuilder = new Ipv4MatchBuilder();
IpMatchBuilder ipMatchBuilder = new IpMatchBuilder();
OpenflowVersion ofVersion = OpenflowVersion.get(datapathIdConvertorData.getVersion());
BigInteger datapathid = datapathIdConvertorData.getDatapathId();
if (!source.getWildcards().isINPORT() && source.getInPort() != null) {
matchBuilder.setInPort(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(datapathid, (long) source.getInPort(), ofVersion));
}
if (!source.getWildcards().isDLSRC() && source.getDlSrc() != null) {
EthernetSourceBuilder ethSrcBuilder = new EthernetSourceBuilder();
ethSrcBuilder.setAddress(source.getDlSrc());
ethMatchBuilder.setEthernetSource(ethSrcBuilder.build());
matchBuilder.setEthernetMatch(ethMatchBuilder.build());
}
if (!source.getWildcards().isDLDST() && source.getDlDst() != null) {
EthernetDestinationBuilder ethDstBuilder = new EthernetDestinationBuilder();
ethDstBuilder.setAddress(source.getDlDst());
ethMatchBuilder.setEthernetDestination(ethDstBuilder.build());
matchBuilder.setEthernetMatch(ethMatchBuilder.build());
}
if (!source.getWildcards().isDLTYPE() && source.getDlType() != null) {
EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
ethTypeBuilder.setType(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType((long) source.getDlType()));
ethMatchBuilder.setEthernetType(ethTypeBuilder.build());
matchBuilder.setEthernetMatch(ethMatchBuilder.build());
}
if (!source.getWildcards().isDLVLAN() && source.getDlVlan() != null) {
VlanIdBuilder vlanIdBuilder = new VlanIdBuilder();
int vlanId = source.getDlVlan() == 0xffff ? 0 : source.getDlVlan();
vlanIdBuilder.setVlanId(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId(vlanId));
vlanIdBuilder.setVlanIdPresent(vlanId != 0);
vlanMatchBuilder.setVlanId(vlanIdBuilder.build());
matchBuilder.setVlanMatch(vlanMatchBuilder.build());
}
if (!source.getWildcards().isDLVLANPCP() && source.getDlVlanPcp() != null) {
vlanMatchBuilder.setVlanPcp(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp(source.getDlVlanPcp()));
matchBuilder.setVlanMatch(vlanMatchBuilder.build());
}
if (!source.getWildcards().isDLTYPE() && source.getNwSrc() != null) {
final Ipv4Prefix prefix;
if (source.getNwSrcMask() != null) {
prefix = IetfInetUtil.INSTANCE.ipv4PrefixFor(source.getNwSrc(), source.getNwSrcMask());
} else {
// Openflow Spec : 1.3.2
// An all-one-bits oxm_mask is equivalent to specifying 0 for oxm_hasmask and omitting oxm_mask.
// So when user specify 32 as a mast, switch omit that mast and we get null as a mask in flow
// statistics response.
prefix = IetfInetUtil.INSTANCE.ipv4PrefixFor(source.getNwSrc());
}
if (!NO_IP.equals(prefix.getValue())) {
ipv4MatchBuilder.setIpv4Source(prefix);
matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
}
}
if (!source.getWildcards().isDLTYPE() && source.getNwDst() != null) {
final Ipv4Prefix prefix;
if (source.getNwDstMask() != null) {
prefix = IetfInetUtil.INSTANCE.ipv4PrefixFor(source.getNwDst(), source.getNwDstMask());
} else {
// Openflow Spec : 1.3.2
// An all-one-bits oxm_mask is equivalent to specifying 0 for oxm_hasmask and omitting oxm_mask.
// So when user specify 32 as a mast, switch omit that mast and we get null as a mask in flow
// statistics response.
prefix = IetfInetUtil.INSTANCE.ipv4PrefixFor(source.getNwDst());
}
if (!NO_IP.equals(prefix.getValue())) {
ipv4MatchBuilder.setIpv4Destination(prefix);
matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
}
}
if (!source.getWildcards().isNWPROTO() && source.getNwProto() != null) {
Short nwProto = source.getNwProto();
ipMatchBuilder.setIpProtocol(nwProto);
matchBuilder.setIpMatch(ipMatchBuilder.build());
int proto = nwProto.intValue();
if (proto == PROTO_TCP) {
TcpMatchBuilder tcpMatchBuilder = new TcpMatchBuilder();
boolean hasTcp = false;
if (!source.getWildcards().isTPSRC() && source.getTpSrc() != null) {
tcpMatchBuilder.setTcpSourcePort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber(source.getTpSrc()));
hasTcp = true;
}
if (!source.getWildcards().isTPDST() && source.getTpDst() != null) {
tcpMatchBuilder.setTcpDestinationPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber(source.getTpDst()));
hasTcp = true;
}
if (hasTcp) {
matchBuilder.setLayer4Match(tcpMatchBuilder.build());
}
} else if (proto == PROTO_UDP) {
UdpMatchBuilder udpMatchBuilder = new UdpMatchBuilder();
boolean hasUdp = false;
if (!source.getWildcards().isTPSRC() && source.getTpSrc() != null) {
udpMatchBuilder.setUdpSourcePort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber(source.getTpSrc()));
hasUdp = true;
}
if (!source.getWildcards().isTPDST() && source.getTpDst() != null) {
udpMatchBuilder.setUdpDestinationPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber(source.getTpDst()));
hasUdp = true;
}
if (hasUdp) {
matchBuilder.setLayer4Match(udpMatchBuilder.build());
}
} else if (proto == PROTO_ICMPV4) {
Icmpv4MatchBuilder icmpv4MatchBuilder = new Icmpv4MatchBuilder();
boolean hasIcmpv4 = false;
if (!source.getWildcards().isTPSRC()) {
Integer type = source.getTpSrc();
if (type != null) {
icmpv4MatchBuilder.setIcmpv4Type(type.shortValue());
hasIcmpv4 = true;
}
}
if (!source.getWildcards().isTPDST()) {
Integer code = source.getTpDst();
if (code != null) {
icmpv4MatchBuilder.setIcmpv4Code(code.shortValue());
hasIcmpv4 = true;
}
}
if (hasIcmpv4) {
matchBuilder.setIcmpv4Match(icmpv4MatchBuilder.build());
}
}
}
if (!source.getWildcards().isNWTOS() && source.getNwTos() != null) {
Short dscp = ActionUtil.tosToDscp(source.getNwTos());
ipMatchBuilder.setIpDscp(new Dscp(dscp));
matchBuilder.setIpMatch(ipMatchBuilder.build());
}
return matchBuilder;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10 in project openflowplugin by opendaylight.
the class OF10StatsReplyMessageFactory method setFlow.
private MultipartReplyFlowCase setFlow(ByteBuf input) {
MultipartReplyFlowCaseBuilder caseBuilder = new MultipartReplyFlowCaseBuilder();
MultipartReplyFlowBuilder flowBuilder = new MultipartReplyFlowBuilder();
List<FlowStats> flowStatsList = new ArrayList<>();
while (input.readableBytes() > 0) {
FlowStatsBuilder flowStatsBuilder = new FlowStatsBuilder();
final int length = input.readUnsignedShort();
flowStatsBuilder.setTableId(input.readUnsignedByte());
input.skipBytes(PADDING_IN_FLOW_STATS_HEADER);
OFDeserializer<MatchV10> matchDeserializer = registry.getDeserializer(new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, EncodeConstants.EMPTY_VALUE, MatchV10.class));
flowStatsBuilder.setMatchV10(matchDeserializer.deserialize(input));
flowStatsBuilder.setDurationSec(input.readUnsignedInt());
flowStatsBuilder.setDurationNsec(input.readUnsignedInt());
flowStatsBuilder.setPriority(input.readUnsignedShort());
flowStatsBuilder.setIdleTimeout(input.readUnsignedShort());
flowStatsBuilder.setHardTimeout(input.readUnsignedShort());
input.skipBytes(PADDING_IN_FLOW_STATS_HEADER_02);
byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(cookie);
flowStatsBuilder.setCookie(new BigInteger(1, cookie));
byte[] packetCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(packetCount);
flowStatsBuilder.setPacketCount(new BigInteger(1, packetCount));
byte[] byteCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(byteCount);
flowStatsBuilder.setByteCount(new BigInteger(1, byteCount));
CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF10_VERSION_ID);
List<Action> actions = ListDeserializer.deserializeList(EncodeConstants.OF10_VERSION_ID, length - LENGTH_OF_FLOW_STATS, input, keyMaker, registry);
flowStatsBuilder.setAction(actions);
flowStatsList.add(flowStatsBuilder.build());
}
flowBuilder.setFlowStats(flowStatsList);
caseBuilder.setMultipartReplyFlow(flowBuilder.build());
return caseBuilder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10 in project openflowplugin by opendaylight.
the class DeserializerRegistryImpl method init.
/**
* Decoder table provisioning.
*/
@Override
public void init() {
registry = new HashMap<>();
// register message deserializers
MessageDeserializerInitializer.registerMessageDeserializers(this);
// register additional message deserializers
AdditionalMessageDeserializerInitializer.registerMessageDeserializers(this);
// register common structure deserializers
registerDeserializer(new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, EncodeConstants.EMPTY_VALUE, MatchV10.class), new OF10MatchDeserializer());
registerDeserializer(new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, EncodeConstants.EMPTY_VALUE, Match.class), new MatchDeserializer());
// register match entry deserializers
MatchEntryDeserializerInitializer.registerMatchEntryDeserializers(this);
// register action deserializers
ActionDeserializerInitializer.registerDeserializers(this);
// register instruction deserializers
InstructionDeserializerInitializer.registerDeserializers(this);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10 in project openflowplugin by opendaylight.
the class OF10StatsRequestInputFactory method serializeFlowBody.
private void serializeFlowBody(final MultipartRequestBody multipartRequestBody, final ByteBuf output) {
MultipartRequestFlowCase flowCase = (MultipartRequestFlowCase) multipartRequestBody;
MultipartRequestFlow flow = flowCase.getMultipartRequestFlow();
OFSerializer<MatchV10> matchSerializer = registry.getSerializer(new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, MatchV10.class));
matchSerializer.serialize(flow.getMatchV10(), output);
output.writeByte(flow.getTableId().shortValue());
output.writeZero(PADDING_IN_MULTIPART_REQUEST_FLOW_BODY);
output.writeShort(flow.getOutPort().intValue());
}
Aggregations