Skip to content

Commit

Permalink
General changes for Windows
Browse files Browse the repository at this point in the history
Mixed changes related to schema, xmpp, vnsw/agent/{kstate, vgw, test-xml}:
1. boost::array<uint8_t, X> to IpYAddress::bytes_type where applicable.
   IpYAddress::bytes_type is std::array if c++11 and boost::array
   otherwise and on Windows we compile with c++11.
2. add linking with advapi32 and gdi32 on Windows
   (needed by OpenSSL)
3. do not link with librt on Windows
4. use multiplatform boost::filesystem instead of open/stat/read
5. add missing 'return' to some functions
6. add missing include
7. and more various bugs

Initial changes:
  https://github.com/sagarkchitnis/windows/commits/master/controller/src
Further work and cleanup:
  https://github.com/codilime/contrail-controller/commits/windows3.1/src

Change-Id: Ifa9a6182300a16c4210d3dc866a333048317b944
Partial-Bug: #1737177
  • Loading branch information
jablonskim committed Dec 15, 2017
1 parent 7f644a1 commit 05212ee
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/schema/test/SConscript
Expand Up @@ -36,7 +36,7 @@ env.Prepend(LIBS = ['sandesh', 'http', 'http_parser', 'curl', 'db',
'process_info', 'sandeshvns', 'io', 'base',
'ssl', 'crypto', 'gunit', 'pugixml'])

if sys.platform != 'darwin':
if sys.platform not in ['win32', 'darwin']:
env.Append(LIBS = ['rt'])

env.Append(CPPPATH = [env['TOP']])
Expand Down
4 changes: 2 additions & 2 deletions src/vnsw/agent/kstate/kstate.cc
Expand Up @@ -233,14 +233,14 @@ const std::string KState::PrefixToString(const std::vector<int8_t> &prefix) {
int size = prefix.size();
string str = "unknown";
if (size <= 4) {
boost::array<unsigned char, 4> bytes = { {0, 0, 0, 0} };
Ip4Address::bytes_type bytes = { {0, 0, 0, 0} };
for (int i = 0; i < size; i++) {
bytes[i] = prefix.at(i);
}
Ip4Address addr4(bytes);
str = addr4.to_string();
} else {
boost::array<unsigned char, 16> bytes =
Ip6Address::bytes_type bytes =
{ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} };
for (int i = 0; i < size; i++) {
bytes[i] = prefix.at(i);
Expand Down
1 change: 1 addition & 0 deletions src/vnsw/agent/kstate/nh_kstate.cc
Expand Up @@ -6,6 +6,7 @@
#include "nh_kstate.h"
#include "vr_nexthop.h"
#include <net/ethernet.h>
#include <netinet/if_ether.h>
#include <iomanip>
#include <sstream>

Expand Down
34 changes: 17 additions & 17 deletions src/vnsw/agent/test-xml/test_xml.cc
Expand Up @@ -5,6 +5,7 @@
#include <iostream>
#include <fstream>
#include <pugixml/pugixml.hpp>
#include <boost/filesystem.hpp>
#include <boost/uuid/uuid.hpp>

#include <test/test_cmn_util.h>
Expand Down Expand Up @@ -118,6 +119,7 @@ xml_node AddXmlNodeWithValue(xml_node *parent, const char *name,
const string &value) {
xml_node n = parent->append_child(name);
n.append_child(pugi::node_pcdata).set_value(value.c_str());
return n;
}

xml_node AddXmlNodeWithIntValue(xml_node *parent, const char *name,
Expand All @@ -126,6 +128,7 @@ xml_node AddXmlNodeWithIntValue(xml_node *parent, const char *name,
s << val;
xml_node n = parent->append_child(name);
n.append_child(pugi::node_pcdata).set_value(s.str().c_str());
return n;
}
}

Expand Down Expand Up @@ -203,36 +206,33 @@ bool AgentUtXmlTest::ReadXml() {
}

bool AgentUtXmlTest::Load() {
struct stat s;
if (stat(file_name_.c_str(), &s)) {
cout << "Error <" << strerror(errno) << "> opening file "
<< file_name_ << endl;
boost::system::error_code ec;
boost::filesystem::path file_path(file_name_);
uintmax_t file_size = boost::filesystem::file_size(file_path, ec);
if (ec) {
cout << "Error <" << ec << "> opening file" << file_name_ << endl;
return false;
}

int fd = open(file_name_.c_str(), O_RDONLY);
if (fd < 0) {
cout << "Error <" << strerror(errno) << "> opening file "
<< file_name_ << endl;
std::fstream file(file_name_.c_str(), std::ios::binary | std::ios_base::in);
if (!file) {
cout << "Error <fstream error> opening file" << file_name_ << endl;
return false;
}

char data[s.st_size + 1];
if (read(fd, data, s.st_size) < s.st_size) {
cout << "Error <" << strerror(errno) << "> reading file "
<< file_name_ << endl;
close(fd);
std::vector<char> data(file_size + 1, 0);
file.read(data.data(), file_size);
if (!file || file.gcount() < file_size) {
cout << "Error <fstream::read> reading file" << file_name_ << endl;
return false;
}
close(fd);
data[s.st_size] = '\0';

xml_parse_result result = doc_.load(data);
xml_parse_result result = doc_.load(data.data());
if (result) {
cout << "Loaded data file successfully" << endl;
} else {
cout << "Error in XML string at offset <: " << result.offset
<< "> (error at [..." << (data + result.offset) << "])" << endl;
<< "> (error at [..." << (data.data() + result.offset) << "])" << endl;
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/vnsw/agent/test-xml/test_xml.h
Expand Up @@ -121,7 +121,7 @@ class AgentUtXmlNode {
virtual bool ToXml(pugi::xml_node *parent) = 0;
virtual std::string NodeType() = 0;
virtual void ToString(std::string *str);
virtual bool Run() { assert(0); }
virtual bool Run() { assert(0); return false; }

void set_gen_xml(bool val) { gen_xml_ = val; }
bool gen_xml() const { return gen_xml_; }
Expand Down
3 changes: 3 additions & 0 deletions src/vnsw/agent/test-xml/test_xml_oper.cc
Expand Up @@ -880,6 +880,7 @@ bool AgentUtXmlNova::ReadXml() {

bool AgentUtXmlNova::ToXml(xml_node *parent) {
assert(0);
return false;
}

void AgentUtXmlNova::ToString(string *str) {
Expand Down Expand Up @@ -1514,6 +1515,7 @@ bool AgentUtXmlL2Route::Run() {
Ip4Address::from_string(ip_),
vxlan_id_, data);
}
return true;
}

/////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -1671,6 +1673,7 @@ bool AgentUtXmlL3Route::Run() {
Ip4Address::from_string(src_ip_), plen_,
data);
}
return true;
}

AgentUtXmlL3RouteValidate::AgentUtXmlL3RouteValidate(const string &name,
Expand Down
2 changes: 1 addition & 1 deletion src/vnsw/agent/vgw/SConscript
Expand Up @@ -11,7 +11,7 @@ env = AgentEnv.Clone()
except_files = [ 'cfg_vgw.cc' ]
except_objs = AgentEnv.BuildExceptionCcObj(env, except_files)

libvgw = env.Library('libvgw',
libvgw = env.Library('vgw',
except_objs +
[ 'vgw.cc' ])

Expand Down
4 changes: 2 additions & 2 deletions src/xmpp/SConscript
Expand Up @@ -26,8 +26,8 @@ for src in sandesh_files:
obj = env.Object(objname, 'sandesh/' + src)
sandesh_files_.append(obj)

xmpp_session = except_env.Object('xmpp_session.o', 'xmpp_session.cc')
xmpp_init = except_env.Object('xmpp_init.o', 'xmpp_init.cc')
xmpp_session = except_env.Object('xmpp_session.cc')
xmpp_init = except_env.Object('xmpp_init.cc')

libxmpp = env.Library('xmpp',
[
Expand Down
5 changes: 4 additions & 1 deletion src/xmpp/test/SConscript
Expand Up @@ -31,7 +31,10 @@ env.Prepend(LIBS = ['task_test', 'gunit', 'xmpp', 'xml', 'pugixml', 'sandesh',
'cassandra', 'gendb', 'SimpleAmqpClient', 'rabbitmq',
'base', 'boost_regex', 'xmpptest', 'db', 'sandesh'])

if sys.platform != 'darwin':
if sys.platform == 'win32':
env.Append(LIBS = ['advapi32', 'gdi32'])

if sys.platform not in ['win32', 'darwin']:
env.Append(LIBS = ['rt'])

xmpp_server_test = env.UnitTest('xmpp_server_test', ['xmpp_server_test.cc'])
Expand Down

0 comments on commit 05212ee

Please sign in to comment.