Search in sources :

Example 1 with VlanMatch

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");
    }
}
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) VlanId(org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId)

Example 2 with VlanMatch

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");
    }
}
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)

Example 3 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 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;
}
Also used : MatchEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry) ExtensionConverterProvider(org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterProvider) ExtensionList(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.list.grouping.ExtensionList) ArrayList(java.util.ArrayList) GeneralExtensionListGrouping(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralExtensionListGrouping) ConverterExtensionKey(org.opendaylight.openflowplugin.extension.api.ConverterExtensionKey)

Example 4 with VlanMatch

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());
    }
}
Also used : MatchEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry) VersionDatapathIdConvertorData(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData) ArrayList(java.util.ArrayList) VlanMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatch) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder) Test(org.junit.Test)

Example 5 with VlanMatch

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());
        }
    }
}
Also used : EthernetMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch) VlanMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatch) Ipv4Match(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match)

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