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
9 package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
11 import static org.junit.Assert.assertEquals;
13 import org.junit.Test;
14 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
15 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
16 import org.opendaylight.openflowjava.util.ByteBufUtils;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestinationBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
23 public class EthernetDestinationEntrySerializerTest extends AbstractMatchEntrySerializerTest {
25 public void testSerialize() throws Exception {
26 final MacAddress address = new MacAddress("00:01:02:03:04:05");
27 final MacAddress mask = new MacAddress("00:00:00:00:00:00");
29 final Match match = new MatchBuilder()
30 .setEthernetMatch(new EthernetMatchBuilder()
31 .setEthernetDestination(new EthernetDestinationBuilder()
38 assertMatch(match, true, (out) -> {
39 final byte[] addressBytes = new byte[6];
40 out.readBytes(addressBytes);
41 assertEquals(new MacAddress(ByteBufUtils.macAddressToString(addressBytes)).getValue(), address.getValue());
43 final byte[] maskBytes = new byte[6];
44 out.readBytes(maskBytes);
45 assertEquals(new MacAddress(ByteBufUtils.macAddressToString(maskBytes)).getValue(), mask.getValue());
48 final Match matchNoMask = new MatchBuilder()
49 .setEthernetMatch(new EthernetMatchBuilder()
50 .setEthernetDestination(new EthernetDestinationBuilder()
56 assertMatch(matchNoMask, false, (out) -> {
57 final byte[] addressBytes = new byte[6];
58 out.readBytes(addressBytes);
59 assertEquals(new MacAddress(ByteBufUtils.macAddressToString(addressBytes)).getValue(), address.getValue());
64 protected short getLength() {
65 return EncodeConstants.MAC_ADDRESS_LENGTH;
69 protected int getOxmFieldCode() {
70 return OxmMatchConstants.ETH_DST;
74 protected int getOxmClassCode() {
75 return OxmMatchConstants.OPENFLOW_BASIC_CLASS;