2 * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
10 import static org.junit.Assert.assertEquals;
12 import org.junit.Test;
13 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
14 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.IetfYangUtil;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSourceBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
22 public class EthernetSourceEntrySerializerTest extends AbstractMatchEntrySerializerTest {
24 public void testSerialize() {
25 final MacAddress address = new MacAddress("00:01:02:03:04:05");
26 final MacAddress mask = new MacAddress("00:00:00:00:00:00");
28 final Match match = new MatchBuilder()
29 .setEthernetMatch(new EthernetMatchBuilder()
30 .setEthernetSource(new EthernetSourceBuilder()
37 assertMatch(match, true, (out) -> {
38 final byte[] addressBytes = new byte[6];
39 out.readBytes(addressBytes);
40 assertEquals(address, IetfYangUtil.macAddressFor(addressBytes));
42 final byte[] maskBytes = new byte[6];
43 out.readBytes(maskBytes);
44 assertEquals(mask, IetfYangUtil.macAddressFor(maskBytes));
47 final Match matchNoMask = new MatchBuilder()
48 .setEthernetMatch(new EthernetMatchBuilder()
49 .setEthernetSource(new EthernetSourceBuilder()
55 assertMatch(matchNoMask, false, (out) -> {
56 final byte[] addressBytes = new byte[6];
57 out.readBytes(addressBytes);
58 assertEquals(address, IetfYangUtil.macAddressFor(addressBytes));
63 protected short getLength() {
64 return EncodeConstants.MAC_ADDRESS_LENGTH;
68 protected int getOxmFieldCode() {
69 return OxmMatchConstants.ETH_SRC;
73 protected int getOxmClassCode() {
74 return OxmMatchConstants.OPENFLOW_BASIC_CLASS;