/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
 * Copyright (c) 2014-2019,  The University of Memphis,
 *                           Regents of the University of California,
 *                           Arizona Board of Regents.
 *
 * This file is part of NLSR (Named-data Link State Routing).
 * See AUTHORS.md for complete list of NLSR authors and contributors.
 *
 * NLSR is free software: you can redistribute it and/or modify it under the terms
 * of the GNU General Public License as published by the Free Software Foundation,
 * either version 3 of the License, or (at your option) any later version.
 *
 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * NLSR, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
 **/

#include "tlv/adjacency-lsa.hpp"

#include "tests/boost-test.hpp"

namespace nlsr {
namespace tlv {
namespace test {

BOOST_AUTO_TEST_SUITE(TlvTestAdjacencyLsa)

const uint8_t AdjacencyLsaWithAdjacenciesData[] =
{
  // Header
  0x83, 0x3d,
  // LsaInfo
  0x80, 0x11, 0x81, 0x08, 0x07, 0x06, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x82, 0x01,
  0x80, 0x8b, 0x02, 0x27, 0x10,
  // Adjacency
  0x84, 0x13, 0x07, 0x07, 0x08, 0x05, 0x74, 0x65, 0x73, 0x74, 0x31, 0x8d, 0x05, 0x74,
  0x65, 0x73, 0x74, 0x31, 0x8c, 0x01, 0x80,
  // Adjacency
  0x84, 0x13, 0x07, 0x07, 0x08, 0x05, 0x74, 0x65, 0x73, 0x74, 0x32, 0x8d, 0x05, 0x74,
  0x65, 0x73, 0x74, 0x32, 0x8c, 0x01, 0x80
};

const uint8_t AdjacencyLsaWithoutAdjacenciesData[] =
{
  // Header
  0x83, 0x13,
  // LsaInfo
  0x80, 0x11, 0x81, 0x08, 0x07, 0x06, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x82, 0x01,
  0x80, 0x8b, 0x02, 0x27, 0x10
};

BOOST_AUTO_TEST_CASE(AdjacencyLsaEncodeWithAdjacencies)
{
  AdjacencyLsa adjacencyLsa;

  LsaInfo lsaInfo;
  lsaInfo.setOriginRouter("test");
  lsaInfo.setSequenceNumber(128);
  lsaInfo.setExpirationPeriod(ndn::time::milliseconds(10000));
  adjacencyLsa.setLsaInfo(lsaInfo);

  Adjacency adjacency1;
  adjacency1.setName("test1");
  adjacency1.setUri("test1");
  adjacency1.setCost(128);
  adjacencyLsa.addAdjacency(adjacency1);

  Adjacency adjacency2;
  adjacency2.setName("test2");
  adjacency2.setUri("test2");
  adjacency2.setCost(128);
  adjacencyLsa.addAdjacency(adjacency2);

  const ndn::Block& wire = adjacencyLsa.wireEncode();

  BOOST_REQUIRE_EQUAL_COLLECTIONS(AdjacencyLsaWithAdjacenciesData,
                                  AdjacencyLsaWithAdjacenciesData +
                                    sizeof(AdjacencyLsaWithAdjacenciesData),
                                  wire.begin(), wire.end());
}

BOOST_AUTO_TEST_CASE(AdjacencyLsaDecodeWithAdjacencies)
{
  AdjacencyLsa adjacencyLsa;

  adjacencyLsa.wireDecode(ndn::Block(AdjacencyLsaWithAdjacenciesData,
                                      sizeof(AdjacencyLsaWithAdjacenciesData)));

  LsaInfo lsaInfo = adjacencyLsa.getLsaInfo();
  BOOST_CHECK_EQUAL(lsaInfo.getOriginRouter(), "test");
  BOOST_CHECK_EQUAL(lsaInfo.getSequenceNumber(), 128);
  BOOST_CHECK_EQUAL(lsaInfo.getExpirationPeriod(), ndn::time::milliseconds(10000));

  BOOST_CHECK_EQUAL(adjacencyLsa.hasAdjacencies(), true);
  std::list<Adjacency> adjacencies = adjacencyLsa.getAdjacencies();
  std::list<Adjacency>::const_iterator it = adjacencies.begin();
  BOOST_CHECK_EQUAL(it->getName(), "test1");
  BOOST_CHECK_EQUAL(it->getUri(), "test1");
  BOOST_CHECK_EQUAL(it->getCost(), 128);

  it++;
  BOOST_CHECK_EQUAL(it->getName(), "test2");
  BOOST_CHECK_EQUAL(it->getUri(), "test2");
  BOOST_CHECK_EQUAL(it->getCost(), 128);
}

BOOST_AUTO_TEST_CASE(AdjacencyLsaEncodeWithoutAdjacencies)
{
  AdjacencyLsa adjacencyLsa;

  LsaInfo lsaInfo;
  lsaInfo.setOriginRouter("test");
  lsaInfo.setSequenceNumber(128);
  lsaInfo.setExpirationPeriod(ndn::time::milliseconds(10000));
  adjacencyLsa.setLsaInfo(lsaInfo);

  const ndn::Block& wire = adjacencyLsa.wireEncode();

  BOOST_REQUIRE_EQUAL_COLLECTIONS(AdjacencyLsaWithoutAdjacenciesData,
                                  AdjacencyLsaWithoutAdjacenciesData +
                                    sizeof(AdjacencyLsaWithoutAdjacenciesData),
                                  wire.begin(), wire.end());
}

BOOST_AUTO_TEST_CASE(AdjacencyLsaDecodeWithoutAdjacencies)
{
  AdjacencyLsa adjacencyLsa;

  adjacencyLsa.wireDecode(ndn::Block(AdjacencyLsaWithoutAdjacenciesData,
                                      sizeof(AdjacencyLsaWithoutAdjacenciesData)));

  LsaInfo lsaInfo = adjacencyLsa.getLsaInfo();
  BOOST_CHECK_EQUAL(lsaInfo.getOriginRouter(), "test");
  BOOST_CHECK_EQUAL(lsaInfo.getSequenceNumber(), 128);
  BOOST_CHECK_EQUAL(lsaInfo.getExpirationPeriod(), ndn::time::milliseconds(10000));

  BOOST_CHECK_EQUAL(adjacencyLsa.hasAdjacencies(), false);
}


BOOST_AUTO_TEST_CASE(AdjacencyLsaClear)
{
  AdjacencyLsa adjacencyLsa;

  LsaInfo lsaInfo;
  lsaInfo.setOriginRouter("test");
  lsaInfo.setSequenceNumber(128);
  lsaInfo.setExpirationPeriod(ndn::time::milliseconds(10000));
  adjacencyLsa.setLsaInfo(lsaInfo);

  Adjacency adjacency1;
  adjacency1.setName("test1");
  adjacency1.setUri("test1");
  adjacency1.setCost(128);
  adjacencyLsa.addAdjacency(adjacency1);
  BOOST_CHECK_EQUAL(adjacencyLsa.getAdjacencies().size(), 1);

  std::list<Adjacency> adjacencies = adjacencyLsa.getAdjacencies();
  std::list<Adjacency>::const_iterator it = adjacencies.begin();
  BOOST_CHECK_EQUAL(it->getName(), "test1");
  BOOST_CHECK_EQUAL(it->getUri(), "test1");
  BOOST_CHECK_EQUAL(it->getCost(), 128);

  adjacencyLsa.clearAdjacencies();
  BOOST_CHECK_EQUAL(adjacencyLsa.getAdjacencies().size(), 0);

  Adjacency adjacency2;
  adjacency2.setName("test2");
  adjacency2.setUri("test2");
  adjacency2.setCost(128);
  adjacencyLsa.addAdjacency(adjacency2);
  BOOST_CHECK_EQUAL(adjacencyLsa.getAdjacencies().size(), 1);

  adjacencies = adjacencyLsa.getAdjacencies();
  it = adjacencies.begin();
  BOOST_CHECK_EQUAL(it->getName(), "test2");
  BOOST_CHECK_EQUAL(it->getUri(), "test2");
  BOOST_CHECK_EQUAL(it->getCost(), 128);
}

BOOST_AUTO_TEST_CASE(AdjacencyLsaOutputStream)
{
  AdjacencyLsa adjacencyLsa;

  LsaInfo lsaInfo;
  lsaInfo.setOriginRouter("test");
  lsaInfo.setSequenceNumber(128);
  lsaInfo.setExpirationPeriod(ndn::time::milliseconds(10000));
  adjacencyLsa.setLsaInfo(lsaInfo);

  Adjacency adjacency1;
  adjacency1.setName("test1");
  adjacency1.setUri("test1");
  adjacency1.setCost(128);
  adjacencyLsa.addAdjacency(adjacency1);

  Adjacency adjacency2;
  adjacency2.setName("test2");
  adjacency2.setUri("test2");
  adjacency2.setCost(128);
  adjacencyLsa.addAdjacency(adjacency2);

  std::ostringstream os;
  os << adjacencyLsa;

  BOOST_CHECK_EQUAL(os.str(), "AdjacencyLsa("
                                "LsaInfo("
                                  "OriginRouter: /test, "
                                  "SequenceNumber: 128, "
                                  "ExpirationPeriod: 10000 milliseconds), "
                                "Adjacency(Name: /test1, Uri: test1, Cost: 128), "
                                "Adjacency(Name: /test2, Uri: test2, Cost: 128))");
}

BOOST_AUTO_TEST_SUITE_END()

} // namespace test
} // namespace tlv
} // namespace nlsr
