use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatch in project openflowplugin by opendaylight.
the class VlanVidEntryDeserializer method deserializeEntry.
@Override
public void deserializeEntry(ByteBuf message, MatchBuilder builder) {
final boolean hasMask = processHeader(message);
final VlanIdBuilder vlanIdBuilder = new VlanIdBuilder();
final int vlanVidValue = message.readUnsignedShort();
if (hasMask) {
// Skip mask
message.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
vlanIdBuilder.setVlanId(new VlanId(0)).setVlanIdPresent(true);
} else {
final boolean vidPresent = (vlanVidValue & (1 << 12)) != 0;
vlanIdBuilder.setVlanId(new VlanId((vidPresent ? vlanVidValue & ((1 << 12) - 1) : vlanVidValue))).setVlanIdPresent(vidPresent);
}
if (Objects.isNull(builder.getVlanMatch())) {
builder.setVlanMatch(new VlanMatchBuilder().setVlanId(vlanIdBuilder.build()).build());
} else if (Objects.isNull(builder.getVlanMatch().getVlanId())) {
builder.setVlanMatch(new VlanMatchBuilder(builder.getVlanMatch()).setVlanId(vlanIdBuilder.build()).build());
} else {
throwErrorOnMalformed(builder, "vlanMatch", "vlanVid");
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatch in project openflowplugin by opendaylight.
the class VlanPcpEntryDeserializer method deserializeEntry.
@Override
public void deserializeEntry(ByteBuf message, MatchBuilder builder) {
processHeader(message);
final short pcp = message.readUnsignedByte();
if (Objects.isNull(builder.getVlanMatch())) {
builder.setVlanMatch(new VlanMatchBuilder().setVlanPcp(new VlanPcp(pcp)).build());
} else if (Objects.isNull(builder.getVlanMatch().getVlanPcp())) {
builder.setVlanMatch(new VlanMatchBuilder(builder.getVlanMatch()).setVlanPcp(new VlanPcp(pcp)).build());
} else {
throwErrorOnMalformed(builder, "vlanMatch", "vlanPcp");
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatch in project openflowplugin by opendaylight.
the class MatchConvertor method convert.
@Override
public List<MatchEntry> convert(final Match source, final VersionConvertorData data) {
List<MatchEntry> result = new ArrayList<>();
if (source == null) {
return result;
}
final ExtensionConverterProvider extensionConvertorProvider = OFSessionUtil.getExtensionConvertorProvider();
inPortMatch(result, source.getInPort());
inPhyPortMatch(result, source.getInPhyPort());
metadataMatch(result, source.getMetadata());
ethernetMatch(result, source.getEthernetMatch());
vlanMatch(result, source.getVlanMatch());
ipMatch(result, source.getIpMatch());
layer4Match(result, source.getLayer4Match(), getConvertorExecutor(), extensionConvertorProvider);
icmpv4Match(result, source.getIcmpv4Match());
icmpv6Match(result, source.getIcmpv6Match());
layer3Match(result, source.getLayer3Match(), getConvertorExecutor(), extensionConvertorProvider);
protocolMatchFields(result, source.getProtocolMatchFields());
tunnelMatch(result, source.getTunnel());
tcpFlagsMatch(result, source.getTcpFlagsMatch());
/*
* TODO: EXTENSION PROPOSAL (source, MD-SAL to OFJava)
* - we might need version for conversion and for key
*/
Optional<GeneralExtensionListGrouping> extensionListOpt = ExtensionResolvers.getMatchExtensionResolver().getExtension(source);
if (extensionListOpt.isPresent()) {
List<ExtensionList> extensionListList = extensionListOpt.get().getExtensionList();
for (ExtensionList extensionItem : extensionListList) {
// TODO: get real version
ConverterExtensionKey<? extends ExtensionKey> key = new ConverterExtensionKey<>(extensionItem.getExtensionKey(), OFConstants.OFP_VERSION_1_3);
ConvertorToOFJava<MatchEntry> convertor = extensionConvertorProvider.getConverter(key);
if (convertor == null) {
throw new IllegalStateException("No converter found for key: " + key.toString());
}
MatchEntry ofMatch = convertor.convert(extensionItem.getExtension());
result.add(ofMatch);
}
}
return result;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatch in project openflowplugin by opendaylight.
the class MatchResponseConvertorTest method testFromOFMatchToSALMatch.
/**
* Test method for {@link MatchResponseConvertor#convert(MatchEntriesGrouping, VersionDatapathIdConvertorData)} }.
*/
@Test
public void testFromOFMatchToSALMatch() {
List<MatchEntry> entries = createDefaultMatchEntry();
int[] vids = { // Match packet with VLAN tag regardless of its value.
-1, // Match untagged frame.
0, // Match packet with VLAN tag and VID equals the specified value.
1, 20, 4095 };
for (int vid : vids) {
List<MatchEntry> matchEntry = new ArrayList<>(entries);
matchEntry.add(toOfVlanVid(vid));
org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.Match ofMatch = createOFMatch(matchEntry);
final VersionDatapathIdConvertorData data = new VersionDatapathIdConvertorData(OFConstants.OFP_VERSION_1_3);
data.setDatapathId(DPID);
final MatchBuilder builder = convert(ofMatch, data);
checkDefault(builder);
VlanMatch vlanMatch = builder.getVlanMatch();
int expectedVid = vid < 0 ? 0 : vid;
Boolean expectedCfi = vid != 0;
assertEquals(expectedVid, vlanMatch.getVlanId().getVlanId().getValue().intValue());
assertEquals(expectedCfi, vlanMatch.getVlanId().isVlanIdPresent());
assertEquals(null, vlanMatch.getVlanPcp());
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatch in project openflowplugin by opendaylight.
the class MatchResponseConvertorTest method checkDefaultV10.
private static void checkDefaultV10(final Match match, final FlowWildcardsV10 wc, final int vid) {
EthernetMatch ethMatch = match.getEthernetMatch();
if (wc.isDLSRC()) {
if (ethMatch != null) {
assertEquals(null, ethMatch.getEthernetSource());
}
} else {
assertEquals(MAC_SRC, ethMatch.getEthernetSource().getAddress());
}
if (ethMatch != null) {
if (wc.isDLDST()) {
assertEquals(null, ethMatch.getEthernetDestination());
} else {
assertNotEquals(null, ethMatch.getEthernetDestination());
assertEquals(MAC_DST, ethMatch.getEthernetDestination().getAddress());
}
}
if (wc.isDLTYPE()) {
if (ethMatch != null) {
assertEquals(null, ethMatch.getEthernetType());
}
assertEquals(null, match.getLayer3Match());
} else {
assert ethMatch != null;
assertEquals(ETHTYPE_IPV4, ethMatch.getEthernetType().getType().getValue().intValue());
Ipv4Match ipv4Match = (Ipv4Match) match.getLayer3Match();
assertEquals(IPV4_SRC.getValue() + "/32", ipv4Match.getIpv4Source().getValue());
assertEquals(IPV4_DST.getValue() + "/32", ipv4Match.getIpv4Destination().getValue());
}
VlanMatch vlanMatch = match.getVlanMatch();
if (wc.isDLVLAN()) {
assertEquals(null, vlanMatch);
} else {
int expectedVid;
Boolean expectedCfi;
if (vid == DL_VLAN_NONE) {
expectedVid = 0;
expectedCfi = Boolean.FALSE;
} else {
expectedVid = vid;
expectedCfi = Boolean.TRUE;
}
assertEquals(expectedVid, vlanMatch.getVlanId().getVlanId().getValue().intValue());
assertEquals(expectedCfi, vlanMatch.getVlanId().isVlanIdPresent());
if (wc.isDLVLANPCP()) {
assertEquals(null, vlanMatch.getVlanPcp());
} else {
assertEquals(VLAN_PCP, vlanMatch.getVlanPcp().getValue().shortValue());
}
}
}
Aggregations