/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
 * Copyright (c) 2014-2017,  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 "../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
