forked from sonic-net/sonic-buildimage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[swssplayer]: Add swssplayer to replay the swss record file (sonic-ne…
…t#238) Usage: swssplayer <file> The file is the SwSS record file get from orchagent. This module enables better debugging to replay all application tasks to orchagent. It is a similar tool as saiplayer but dedicated for orchagent.
- Loading branch information
Shuotian Cheng
authored
Jun 9, 2017
1 parent
0e9b855
commit 6fe29db
Showing
3 changed files
with
91 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,5 +48,6 @@ portsyncd/portsyncd | |
orchagent/orchagent | ||
orchagent/routeresync | ||
swssconfig/swssconfig | ||
swssconfig/swssplayer | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#include <fstream> | ||
#include <iostream> | ||
|
||
#include <dbconnector.h> | ||
#include <producerstatetable.h> | ||
#include <schema.h> | ||
#include <tokenize.h> | ||
|
||
using namespace std; | ||
using namespace swss; | ||
|
||
constexpr int DB_PORT = 6379; | ||
constexpr char* DB_HOSTNAME = "localhost"; | ||
|
||
static int line_index = 0; | ||
static DBConnector db(APPL_DB, DB_HOSTNAME, DB_PORT, 0); | ||
|
||
void usage() | ||
{ | ||
cout << "Usage: swssplayer <file>" << endl; | ||
/* TODO: Add sample input file */ | ||
} | ||
|
||
vector<FieldValueTuple> processFieldsValuesTuple(string s) | ||
{ | ||
vector<FieldValueTuple> result; | ||
|
||
auto tuples = tokenize(s, '|'); | ||
for (auto tuple : tuples) | ||
{ | ||
auto v_tuple = tokenize(tuple, ':', 1); | ||
auto field = v_tuple[0]; | ||
auto value = v_tuple.size() == 1 ? "" : v_tuple[1]; | ||
result.push_back(FieldValueTuple(field, value)); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
void processTokens(vector<string> tokens) | ||
{ | ||
auto key = tokens[1]; | ||
|
||
/* Process the key */ | ||
auto v_key = tokenize(key, ':', 1); | ||
auto table_name = v_key[0]; | ||
auto key_name = v_key[1]; | ||
|
||
ProducerStateTable producer(&db, table_name); | ||
|
||
/* Process the operation */ | ||
auto op = tokens[2]; | ||
if (op == SET_COMMAND) | ||
{ | ||
auto tuples = processFieldsValuesTuple(tokens[3]); | ||
producer.set(key_name, tuples, SET_COMMAND); | ||
} | ||
else if (op == DEL_COMMAND) | ||
{ | ||
producer.del(key_name, DEL_COMMAND); | ||
} | ||
} | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
if (argc != 2) | ||
{ | ||
usage(); | ||
exit(EXIT_FAILURE); | ||
} | ||
|
||
ifstream file(argv[1]); | ||
string line; | ||
|
||
while (getline(file, line)) | ||
{ | ||
auto tokens = tokenize(line, '|', 3); | ||
processTokens(tokens); | ||
|
||
line_index++; | ||
} | ||
} |