/*****************************************************************************
 *
 * Copyright (c) 2018-19, Eduard Gerlits, Paula Herber, Josef Treus
 * Westfälische Wilhelms-Universität Münster, AG Embedded Systems 
 * All rights reserved.
 *
 * This file is part of SysCSec
 *
 * SysCSec 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.
 *
 * SysCSec 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 SysCSec.  If not, see <http://www.gnu.org/licenses/>.
 *
 *
 *  Please report any problems or bugs to: sysc.sec@uni-muenster.de
 *
 ****************************************************************************/

#include <systemc.h>
#include "Client.h"
#include "Server.h"
#include "CA.h"

#define __TIMEOUT__ 100000

int sc_main(int sc_argc, char* sc_argv[]){
	
	// 1.Elaboration

	// Clock
	//sc_clock clk("clk", 100, SC_MS);

	// Modules
	Client client_inst("client_inst");
	Server server_inst("server_inst");
	CertificateAuthority ca_inst("ca_inst");
	
	// Fifos
	sc_fifo<sc_biguint<960> > fifo_client_ca;
	sc_fifo<sc_biguint<960> > fifo_ca_client;
	sc_fifo<sc_biguint<960> > fifo_server_ca;
	sc_fifo<sc_biguint<960> > fifo_ca_server;
	sc_fifo<sc_biguint<960> > fifo_client_server;
	sc_fifo<sc_biguint<960> > fifo_server_client;

	// connect fifos

	/// CA
	//ca_inst.clk(clk);
	ca_inst.in_client(fifo_client_ca);
	ca_inst.in_server(fifo_server_ca);
	ca_inst.out_client(fifo_ca_client);
	ca_inst.out_server(fifo_ca_server);

	/// Client
	//client_inst.clk(clk);
	client_inst.in_ca(fifo_ca_client);
	client_inst.in_server(fifo_server_client);
	client_inst.out_ca(fifo_client_ca);
	client_inst.out_server(fifo_client_server);

	/// Server
	//server_inst.clk(clk);
	server_inst.in_ca(fifo_ca_server);
	server_inst.in_client(fifo_client_server);
	server_inst.out_ca(fifo_server_ca);
	server_inst.out_client(fifo_server_client);

	// 2.Execution

	// set seed for random number generator
	srand(time(0));
	std::cout << "[" << sc_time_stamp() << "]" << "[System]" << ": " << "Initialize System with the following elliptic curve parameters: " << std::endl;
	std::cout << "\t" << "Elliptic curve: [y^2 = x^3 + x + 1]" << std::endl;
	std::cout << "\t" << "Prime field: GF(17)" << std::endl;
	std::cout << "\t" << "Point on curve: (2,8)" << std::endl;
	std::cout << "\t" << "Order of the point: 17" << std::endl;
	sc_start(__TIMEOUT__, SC_NS);

	
	return 0;
}
