use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatch in project openflowplugin by opendaylight.
the class FlowConvertor method handleSetVlanIdForOF13.
/**
* A) If user provided flow's match includes vlan match and action has set_vlan_field
* Install following rules.
* 1) match on (OFPVID_PRESENT |value) without mask + action [set_field]
* <p/>
* B) if user provided flow's match doesn't include vlan match but action has set_vlan field
* 1) Match on (OFPVID_NONE ) without mask + action [push vlan tag + set_field]
* 2) Match on (OFPVID_PRESENT) with mask (OFPVID_PRESENT ) + action [ set_field]
*/
private List<FlowModInputBuilder> handleSetVlanIdForOF13(Flow srcFlow, VersionDatapathIdConvertorData versionDatapathIdConverterData) {
List<FlowModInputBuilder> list = new ArrayList<>(2);
final Match srcMatch = Preconditions.checkNotNull(srcFlow.getMatch());
final VlanMatch srcVlanMatch = srcMatch.getVlanMatch();
if (srcVlanMatch != null) {
// create flow with setfield and match
// match on vlan tag or vlanid with no mask
VlanMatchBuilder vlanMatchBuilder = new VlanMatchBuilder(srcVlanMatch);
VlanIdBuilder vlanIdBuilder = new VlanIdBuilder();
vlanIdBuilder.setVlanIdPresent(srcVlanMatch.getVlanId().isVlanIdPresent());
vlanIdBuilder.setVlanId(srcVlanMatch.getVlanId().getVlanId());
vlanMatchBuilder.setVlanId(vlanIdBuilder.build());
Match match = new MatchBuilder(srcMatch).setVlanMatch(vlanMatchBuilder.build()).build();
Optional<? extends Flow> optional = injectMatchToFlow(srcFlow, match);
if (optional.isPresent()) {
list.add(toFlowModInput(optional.get(), versionDatapathIdConverterData));
}
} else {
// create 2 flows
// flow 1
// match on no vlan tag with no mask
Match match1 = new MatchBuilder(srcMatch).setVlanMatch(VLAN_MATCH_FALSE).build();
Optional<? extends Flow> optional1 = injectMatchAndAction(srcFlow, match1);
if (optional1.isPresent()) {
list.add(toFlowModInput(optional1.get(), versionDatapathIdConverterData));
}
// flow2
// match on vlan tag with mask
Match match2 = new MatchBuilder(srcMatch).setVlanMatch(VLAN_MATCH_TRUE).build();
Optional<? extends Flow> optional2 = injectMatchToFlow(srcFlow, match2);
if (optional2.isPresent()) {
list.add(toFlowModInput(optional2.get(), versionDatapathIdConverterData));
}
}
return list;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatch in project openflowplugin by opendaylight.
the class VlanVidEntryDeserializerTest method deserializeEntry.
@Test
public void deserializeEntry() throws Exception {
final ByteBuf in = UnpooledByteBufAllocator.DEFAULT.buffer();
final int vlanVid = 8;
final byte[] vlanMask = new byte[] { 16, 0 };
writeHeader(in, false);
in.writeShort(vlanVid | (1 << 12));
VlanMatch vlanMatch = deserialize(in).getVlanMatch();
assertEquals(vlanVid, vlanMatch.getVlanId().getVlanId().getValue().intValue());
assertTrue(vlanMatch.getVlanId().isVlanIdPresent());
assertEquals(0, in.readableBytes());
writeHeader(in, true);
in.writeShort(vlanVid);
in.writeBytes(vlanMask);
vlanMatch = deserialize(in).getVlanMatch();
assertEquals(0, vlanMatch.getVlanId().getVlanId().getValue().intValue());
assertTrue(vlanMatch.getVlanId().isVlanIdPresent());
assertEquals(0, in.readableBytes());
writeHeader(in, false);
in.writeShort(vlanVid);
vlanMatch = deserialize(in).getVlanMatch();
assertEquals(vlanVid, vlanMatch.getVlanId().getVlanId().getValue().intValue());
assertFalse(vlanMatch.getVlanId().isVlanIdPresent());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatch in project openflowplugin by opendaylight.
the class VlanPcpEntrySerializerTest method testSerialize.
@Test
public void testSerialize() throws Exception {
final short vlan = (short) 1;
final Match vlanMatch = new MatchBuilder().setVlanMatch(new VlanMatchBuilder().setVlanPcp(new VlanPcp(vlan)).build()).build();
assertMatch(vlanMatch, false, (out) -> assertEquals(out.readUnsignedByte(), vlan));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatch in project openflowplugin by opendaylight.
the class MatchConvertor method vlanMatch.
private static void vlanMatch(final List<MatchEntry> matchEntryList, final VlanMatch vlanMatch) {
if (vlanMatch == null) {
return;
}
if (vlanMatch.getVlanId() != null) {
VlanId vlanId = vlanMatch.getVlanId();
MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
matchEntryBuilder.setOxmMatchField(VlanVid.class);
VlanVidBuilder vlanVidBuilder = new VlanVidBuilder();
boolean setCfiBit = false;
Integer vidEntryValue = 0;
boolean hasmask = false;
if (Boolean.TRUE.equals(vlanId.isVlanIdPresent())) {
setCfiBit = true;
if (vlanId.getVlanId() != null) {
vidEntryValue = vlanId.getVlanId().getValue();
}
hasmask = vidEntryValue == 0;
if (hasmask) {
vlanVidBuilder.setMask(VLAN_VID_MASK);
}
}
vlanVidBuilder.setCfiBit(setCfiBit);
vlanVidBuilder.setVlanVid(vidEntryValue);
VlanVidCaseBuilder vlanVidCaseBuilder = new VlanVidCaseBuilder();
vlanVidCaseBuilder.setVlanVid(vlanVidBuilder.build());
matchEntryBuilder.setMatchEntryValue(vlanVidCaseBuilder.build());
matchEntryBuilder.setHasMask(hasmask);
matchEntryList.add(matchEntryBuilder.build());
}
if (vlanMatch.getVlanPcp() != null) {
matchEntryList.add(MatchConvertorUtil.toOfVlanPcp(vlanMatch.getVlanPcp()));
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatch in project openflowplugin by opendaylight.
the class VlanVidEntrySerializerTest method testSerialize.
@Test
public void testSerialize() throws Exception {
final int vlan = (short) 1;
final Match vlanMatch = new MatchBuilder().setVlanMatch(new VlanMatchBuilder().setVlanId(new VlanIdBuilder().setVlanId(new VlanId(vlan)).setVlanIdPresent(true).build()).build()).build();
assertMatch(vlanMatch, false, (out) -> assertEquals(out.readShort(), vlan | (1 << 12)));
final Match vlanMatchMaskOnly = new MatchBuilder().setVlanMatch(new VlanMatchBuilder().setVlanId(new VlanIdBuilder().setVlanIdPresent(true).build()).build()).build();
assertMatch(vlanMatchMaskOnly, true, out -> {
assertEquals(out.readShort(), (1 << 12));
byte[] mask = new byte[2];
out.readBytes(mask);
assertArrayEquals(mask, new byte[] { 16, 0 });
});
}
Aggregations