Search in sources :

Example 6 with VlanMatch

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;
}
Also used : ArrayList(java.util.ArrayList) VlanMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatch) VlanMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder) FlowModInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder) VlanIdBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder) VlanMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder) Match(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match) VlanMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatch)

Example 7 with VlanMatch

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());
}
Also used : VlanMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatch) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 8 with VlanMatch

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));
}
Also used : VlanPcp(org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp) VlanMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder) VlanMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder) Match(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match) Test(org.junit.Test)

Example 9 with VlanMatch

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()));
    }
}
Also used : VlanVidBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.vlan.vid._case.VlanVidBuilder) VlanVidCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.VlanVidCaseBuilder) MatchEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder) VlanId(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanId)

Example 10 with VlanMatch

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 });
    });
}
Also used : VlanMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder) VlanIdBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder) VlanMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder) VlanId(org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId) Match(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match) Test(org.junit.Test)

Aggregations

VlanMatch (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatch)5 VlanMatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder)5 Test (org.junit.Test)4 MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder)4 ArrayList (java.util.ArrayList)3 VlanIdBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder)3 VlanId (org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId)2 VlanPcp (org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp)2 Match (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match)2 EthernetMatch (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch)2 Ipv4Match (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match)2 MatchEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry)2 ByteBuf (io.netty.buffer.ByteBuf)1 ConverterExtensionKey (org.opendaylight.openflowplugin.extension.api.ConverterExtensionKey)1 ExtensionConverterProvider (org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterProvider)1 VersionDatapathIdConvertorData (org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData)1 Match (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match)1 NodeConnectorId (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId)1 Icmpv4Match (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4Match)1 IpMatch (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatch)1