// Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior University
// Copyright (c) 2011, 2012 Open Networking Foundation
// Copyright (c) 2012, 2013 Big Switch Networks, Inc.
// This library was generated by the LoxiGen Compiler.
// See the file LICENSE.txt which should have been included in the source distribution

// Automatically generated by LOXI from template unit_test.java
// Do not modify

package org.projectfloodlight.openflow.protocol.ver15;

import org.projectfloodlight.openflow.protocol.*;
import org.projectfloodlight.openflow.protocol.action.*;
import org.projectfloodlight.openflow.protocol.actionid.*;
import org.projectfloodlight.openflow.protocol.bsntlv.*;
import org.projectfloodlight.openflow.protocol.errormsg.*;
import org.projectfloodlight.openflow.protocol.meterband.*;
import org.projectfloodlight.openflow.protocol.instruction.*;
import org.projectfloodlight.openflow.protocol.instructionid.*;
import org.projectfloodlight.openflow.protocol.match.*;
import org.projectfloodlight.openflow.protocol.stat.*;
import org.projectfloodlight.openflow.protocol.oxm.*;
import org.projectfloodlight.openflow.protocol.oxs.*;
import org.projectfloodlight.openflow.protocol.queueprop.*;
import org.projectfloodlight.openflow.types.*;
import org.projectfloodlight.openflow.util.*;
import org.projectfloodlight.openflow.exceptions.*;
import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.Before;
import java.util.Set;
import com.google.common.collect.ImmutableSet;
import java.util.List;
import com.google.common.collect.ImmutableList;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.hamcrest.CoreMatchers;



public class OFPortStatsReplyVer15Test {
    OFFactory factory;

    final static byte[] PORT_STATS_REPLY_SERIALIZED =
        new byte[] { 0x6, 0x13, 0x0, (byte) 0x88, 0x12, 0x34, 0x56, 0x78, 0x0, 0x4, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x78, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x3, (byte) 0xb2, (byte) 0xd0, 0x5e, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x28, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1a, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1b, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1c, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1d };

    @Before
    public void setup() {
        factory = OFFactoryVer15.INSTANCE;
    }

    @Test
    public void testWrite() {
        OFPortStatsReply.Builder builder = factory.buildPortStatsReply();
        builder
        .setXid(0x12345678)
        .setFlags(ImmutableSet.<OFStatsReplyFlags>of(OFStatsReplyFlags.REPLY_MORE))
        .setEntries(ImmutableList.<OFPortStatsEntry>of(factory.buildPortStatsEntry().setPortNo(OFPort.of(1))
                                                                                    .setDurationSec(3)
                                                                                    .setDurationNsec(3000000000L)
                                                                                    .setRxPackets(U64.of(10))
                                                                                    .setTxPackets(U64.of(7))
                                                                                    .setRxBytes(U64.of(10))
                                                                                    .setTxBytes(U64.of(7))
                                                                                    .setRxDropped(U64.of(2))
                                                                                    .setTxDropped(U64.of(1))
                                                                                    .setRxErrors(U64.of(1))
                                                                                    .setTxErrors(U64.of(1))
                                                                                    .setProperties(ImmutableList.<OFPortStatsProp>of(factory.buildPortStatsPropEthernet()
                                                                                                                                            .setRxFrameErr(U64.of(26))
                                                                                                                                            .setRxOverErr(U64.of(27))
                                                                                                                                            .setRxCrcErr(U64.of(28))
                                                                                                                                            .setCollisions(U64.of(29))
                                                                                                                                            .build()))
                                                                                    .build()))
        .build();
        OFPortStatsReply portStatsReply = builder.build();
        ByteBuf bb = Unpooled.buffer();
        portStatsReply.writeTo(bb);
        byte[] written = new byte[bb.readableBytes()];
        bb.readBytes(written);

        assertThat(written, CoreMatchers.equalTo(PORT_STATS_REPLY_SERIALIZED));
    }

    @Test
    public void testRead() throws Exception {
        OFPortStatsReply.Builder builder = factory.buildPortStatsReply();
        builder
        .setXid(0x12345678)
        .setFlags(ImmutableSet.<OFStatsReplyFlags>of(OFStatsReplyFlags.REPLY_MORE))
        .setEntries(ImmutableList.<OFPortStatsEntry>of(factory.buildPortStatsEntry().setPortNo(OFPort.of(1))
                                                                                    .setDurationSec(3)
                                                                                    .setDurationNsec(3000000000L)
                                                                                    .setRxPackets(U64.of(10))
                                                                                    .setTxPackets(U64.of(7))
                                                                                    .setRxBytes(U64.of(10))
                                                                                    .setTxBytes(U64.of(7))
                                                                                    .setRxDropped(U64.of(2))
                                                                                    .setTxDropped(U64.of(1))
                                                                                    .setRxErrors(U64.of(1))
                                                                                    .setTxErrors(U64.of(1))
                                                                                    .setProperties(ImmutableList.<OFPortStatsProp>of(factory.buildPortStatsPropEthernet()
                                                                                                                                            .setRxFrameErr(U64.of(26))
                                                                                                                                            .setRxOverErr(U64.of(27))
                                                                                                                                            .setRxCrcErr(U64.of(28))
                                                                                                                                            .setCollisions(U64.of(29))
                                                                                                                                            .build()))
                                                                                    .build()))
        .build();
        OFPortStatsReply portStatsReplyBuilt = builder.build();

        ByteBuf input = Unpooled.copiedBuffer(PORT_STATS_REPLY_SERIALIZED);

        // FIXME should invoke the overall reader once implemented
        OFPortStatsReply portStatsReplyRead = OFPortStatsReplyVer15.READER.readFrom(input);
        assertEquals(PORT_STATS_REPLY_SERIALIZED.length, input.readerIndex());

        assertEquals(portStatsReplyBuilt, portStatsReplyRead);
   }

   @Test
   public void testReadWrite() throws Exception {
       ByteBuf input = Unpooled.copiedBuffer(PORT_STATS_REPLY_SERIALIZED);

       // FIXME should invoke the overall reader once implemented
       OFPortStatsReply portStatsReply = OFPortStatsReplyVer15.READER.readFrom(input);
       assertEquals(PORT_STATS_REPLY_SERIALIZED.length, input.readerIndex());

       // write message again
       ByteBuf bb = Unpooled.buffer();
       portStatsReply.writeTo(bb);
       byte[] written = new byte[bb.readableBytes()];
       bb.readBytes(written);

       assertThat(written, CoreMatchers.equalTo(PORT_STATS_REPLY_SERIALIZED));
   }

}
