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.deserialization.match;
10 import static org.junit.Assert.assertEquals;
12 import io.netty.buffer.ByteBuf;
13 import io.netty.buffer.UnpooledByteBufAllocator;
14 import java.util.Iterator;
15 import org.junit.Test;
16 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
17 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.IpConversionUtil;
18 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchConvertorUtil;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IetfInetUtil;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatch;
24 public class ArpSourceTransportAddressEntryDeserializerTest extends AbstractMatchEntryDeserializerTest {
26 public void deserializeEntry() {
27 final ByteBuf in = UnpooledByteBufAllocator.DEFAULT.buffer();
28 final Ipv4Prefix arpSourceTransportAddress = new Ipv4Prefix("192.168.0.0/24");
29 final Ipv4Prefix arpSourceTransportAddressNoMask = new Ipv4Prefix("192.168.0.0/32");
31 writeHeader(in, false);
32 Iterator<String> addressParts = IpConversionUtil.splitToParts(arpSourceTransportAddressNoMask);
33 in.writeBytes(IetfInetUtil.ipv4AddressBytes(new Ipv4Address(addressParts.next())));
35 assertEquals(arpSourceTransportAddressNoMask.getValue(),
36 ((ArpMatch) deserialize(in).getLayer3Match()).getArpSourceTransportAddress().getValue());
37 assertEquals(0, in.readableBytes());
39 writeHeader(in, true);
40 addressParts = IpConversionUtil.splitToParts(arpSourceTransportAddress);
41 in.writeBytes(IetfInetUtil.ipv4AddressBytes(new Ipv4Address(addressParts.next())));
42 in.writeBytes(MatchConvertorUtil.extractIpv4Mask(addressParts));
44 final Ipv4Prefix desAddress =
45 ((ArpMatch) deserialize(in).getLayer3Match()).getArpSourceTransportAddress();
46 assertEquals(arpSourceTransportAddress.getValue(), desAddress.getValue());
47 assertEquals(0, in.readableBytes());
51 protected int getOxmClassCode() {
52 return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
56 protected int getOxmFieldCode() {
57 return OxmMatchConstants.ARP_SPA;
61 protected int getValueLength() {