Skip to content

Commit

Permalink
Merge remote branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
haripk committed Jan 14, 2014
2 parents 93eea3b + cb78f57 commit 04cf43f
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 93 deletions.
4 changes: 2 additions & 2 deletions src/vnsw/agent/cmn/agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include <uve/uve_client.h>
#include <vgw/vgw.h>

#include <diag/diag_table.h>
#include <diag/diag.h>

const std::string Agent::null_str_ = "";
const std::string Agent::fabric_vn_name_ =
Expand Down Expand Up @@ -331,7 +331,7 @@ void Agent::InitDone() {

// Diag module needs PktModule
if (pkt_.get()) {
diag_=std::auto_ptr<DiagTable>(new DiagTable(this));
diag_table_ = std::auto_ptr<DiagTable>(new DiagTable(this));
}

if (init_->create_vhost()) {
Expand Down
6 changes: 3 additions & 3 deletions src/vnsw/agent/cmn/agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -502,8 +502,8 @@ class Agent {
void Shutdown() {
}

DiagTable *diag() {
return diag_.get();
DiagTable *diag_table() const {
return diag_table_.get();
}
void CreateLifetimeManager();
void ShutdownLifetimeManager();
Expand Down Expand Up @@ -544,7 +544,7 @@ class Agent {
std::auto_ptr<ServicesModule> services_;
std::auto_ptr<VirtualGateway> vgw_;
std::auto_ptr<OperDB> oper_db_;
std::auto_ptr<DiagTable> diag_;
std::auto_ptr<DiagTable> diag_table_;

EventManager *event_mgr_;
AgentXmppChannel *agent_xmpp_channel_[MAX_XMPP_SERVERS];
Expand Down
3 changes: 2 additions & 1 deletion src/vnsw/agent/diag/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ if sys.platform != 'darwin':
sandesh_objs +
[
'diag.cc',
'ping.cc'
'ping.cc',
'diag_pkt_handler.cc'
])
75 changes: 8 additions & 67 deletions src/vnsw/agent/diag/diag.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "cmn/agent_cmn.h"
#include "pkt/proto.h"
#include "pkt/proto_handler.h"
#include "diag/diag_table.h"
#include "diag/diag.h"
#include "diag/diag_proto.h"
#include "diag/ping.h"
#include "oper/mirror_table.h"
Expand All @@ -18,23 +18,22 @@ const std::string KDiagName("DiagTimeoutHandler");

////////////////////////////////////////////////////////////////////////////////

DiagEntry::DiagEntry(int timeout, int count,DiagTable *diag):
diag_(diag),timeout_(timeout),
timer_(TimerManager::CreateTimer(*(diag->GetAgent()->GetEventManager())->io_service(),
DiagEntry::DiagEntry(int timeout, int count,DiagTable *diag_table):
diag_table_(diag_table) , timeout_(timeout),
timer_(TimerManager::CreateTimer(*(diag_table->GetAgent()->GetEventManager())->io_service(),
"DiagTimeoutHandler")), count_(count), seq_no_(0) {
}

DiagEntry::~DiagEntry() {
timer_->Cancel();
TimerManager::DeleteTimer(timer_);
//Delete entry in DiagTable
diag_->Delete(this);
diag_table_->Delete(this);
}

void DiagEntry::Init() {
DiagEntryOp *entry_op = new DiagEntryOp(DiagEntryOp::ADD, this);
entry_op->de_->diag_=diag_;
diag_->Enqueue(entry_op);
diag_table_->Enqueue(entry_op);
}

void DiagEntry::RestartTimer() {
Expand All @@ -51,8 +50,7 @@ bool DiagEntry::TimerExpiry( uint32_t seq_no) {
} else {
op = new DiagEntryOp(DiagEntryOp::RETRY, this);
}
op->de_->diag_=diag_;
diag_->Enqueue(op);
diag_table_->Enqueue(op);
return false;
}

Expand All @@ -61,62 +59,6 @@ void DiagEntry::Retry() {
RestartTimer();
}

void DiagPktHandler::SetReply() {
AgentDiagPktData *ad = (AgentDiagPktData *)pkt_info_->data;
ad->op_ = htonl(AgentDiagPktData::DIAG_REPLY);
}

void DiagPktHandler::SetDiagChkSum() {
pkt_info_->ip->check = 0xffff;
}

void DiagPktHandler::Reply() {
SetReply();
Swap();
SetDiagChkSum();
Send(GetLen() - (2 * IPC_HDR_LEN), GetIntf(), GetVrf(),
AGENT_CMD_ROUTE, PktHandler::DIAG);
}

bool DiagPktHandler::Run() {
AgentDiagPktData *ad = (AgentDiagPktData *)pkt_info_->data;

if (!ad) {
//Ignore if packet doesnt have proper L4 header
return true;
}

if (ntohl(ad->op_) == AgentDiagPktData::DIAG_REQUEST) {
//Request received swap the packet
//and dump the packet back
Reply();
return false;
}

if (ntohl(ad->op_) != AgentDiagPktData::DIAG_REPLY) {
return true;
}

//Reply for a query we sent
DiagEntry::DiagKey key = ntohl(ad->key_);
DiagEntry *entry = diag_->Find(key);
if (!entry) {
return true;
}

entry->HandleReply(this);

if (entry->GetSeqNo() == entry->GetCount()) {
DiagEntryOp *op;
op = new DiagEntryOp(DiagEntryOp::DELETE, entry);
entry->GetDiag()->Enqueue(op);
} else {
entry->Retry();
}

return true;
}

bool DiagTable::Process(DiagEntryOp *op) {
switch (op->op_) {
case DiagEntryOp::ADD:
Expand All @@ -139,8 +81,7 @@ bool DiagTable::Process(DiagEntryOp *op) {
return true;
}

DiagTable::DiagTable(Agent *agent) {
agent_=agent;
DiagTable::DiagTable(Agent *agent):agent_(agent) {
diag_proto_.reset(
new DiagProto(agent, *(agent->GetEventManager())->io_service()));
entry_op_queue_ = new WorkQueue<DiagEntryOp *>
Expand Down
15 changes: 6 additions & 9 deletions src/vnsw/agent/diag/diag_table.h → src/vnsw/agent/diag/diag.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/

#ifndef vnsw_agent_diag_diag_table_hpp
#define vnsw_agent_diag_diag_table_hpp
#ifndef vnsw_agent_diag_diag_hpp
#define vnsw_agent_diag_diag_hpp

#include <base/logging.h>
#include <net/address.h>
Expand All @@ -19,7 +19,7 @@ class DiagEntry {
typedef uint32_t DiagKey;
typedef Timer DiagTimer;

DiagEntry(int timeout, int count,DiagTable *diag);
DiagEntry(int timeout, int count, DiagTable *diag_table);
virtual ~DiagEntry();
void Init();
virtual void SendRequest() = 0;
Expand All @@ -36,15 +36,12 @@ class DiagEntry {
bool TimerCancel() {
return timer_->Cancel();
}
void SetDiagTable(DiagTable *diag) {
diag_ = diag;
}
DiagTable* GetDiag() {
return diag_;
DiagTable* diag_table() const {
return diag_table_;
}

protected:
DiagTable *diag_;
DiagTable *diag_table_;
DiagKey key_;
int timeout_;
DiagTimer *timer_;
Expand Down
68 changes: 68 additions & 0 deletions src/vnsw/agent/diag/diag_pkt_handler.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
* */

#include <map>
#include "vr_defs.h"
#include "base/timer.h"
#include "cmn/agent_cmn.h"
#include "pkt/proto.h"
#include "pkt/proto_handler.h"
#include "diag/diag.h"
#include "diag/diag_proto.h"
#include "diag/ping.h"
#include "oper/mirror_table.h"


void DiagPktHandler::SetReply() {
AgentDiagPktData *ad = (AgentDiagPktData *)pkt_info_->data;
ad->op_ = htonl(AgentDiagPktData::DIAG_REPLY);
}

void DiagPktHandler::SetDiagChkSum() {
pkt_info_->ip->check = 0xffff;
}

void DiagPktHandler::Reply() {
SetReply();
Swap();
SetDiagChkSum();
Send(GetLen() - (2 * IPC_HDR_LEN), GetIntf(), GetVrf(),
AGENT_CMD_ROUTE, PktHandler::DIAG);
}
bool DiagPktHandler::Run() {
AgentDiagPktData *ad = (AgentDiagPktData *)pkt_info_->data;

if (!ad) {
//Ignore if packet doesnt have proper L4 header
return true;
}
if (ntohl(ad->op_) == AgentDiagPktData::DIAG_REQUEST) {
//Request received swap the packet
//and dump the packet back
Reply();
return false;
}

if (ntohl(ad->op_) != AgentDiagPktData::DIAG_REPLY) {
return true;
}
//Reply for a query we sent
DiagEntry::DiagKey key = ntohl(ad->key_);
DiagEntry *entry = diag_table_->Find(key);
if (!entry) {
return true;
}

entry->HandleReply(this);

if (entry->GetSeqNo() == entry->GetCount()) {
DiagEntryOp *op;
op = new DiagEntryOp(DiagEntryOp::DELETE, entry);
entry->diag_table()->Enqueue(op);
} else {
entry->Retry();
}

return true;
}
7 changes: 5 additions & 2 deletions src/vnsw/agent/diag/diag_pkt_handler.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/*
* * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
* */
#ifndef vnsw_agent_diag_diag_pkt_handler_hpp
#define vnsw_agent_diag_diag_pkt_handler_hpp

Expand All @@ -12,7 +15,7 @@ class DiagPktHandler : public ProtoHandler {
public:
DiagPktHandler(Agent *agent, boost::shared_ptr<PktInfo> info,
boost::asio::io_service &io):
ProtoHandler(agent, info, io), diag_(agent->diag()) {}
ProtoHandler(agent, info, io), diag_table_(agent->diag_table()) {}
virtual bool Run();
void SetReply();
void SetDiagChkSum();
Expand All @@ -22,7 +25,7 @@ class DiagPktHandler : public ProtoHandler {
}

private:
DiagTable *diag_;
DiagTable *diag_table_;
};

#endif
8 changes: 4 additions & 4 deletions src/vnsw/agent/diag/ping.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
#include "pkt/proto.h"
#include "pkt/proto_handler.h"
#include "diag/diag_types.h"
#include "diag/diag_table.h"
#include "diag/diag.h"
#include "diag/ping.h"

using namespace boost::posix_time;

Ping::Ping(const PingReq *ping_req,DiagTable *diag):
DiagEntry(ping_req->get_interval() * 100, ping_req->get_count(),diag),
Ping::Ping(const PingReq *ping_req,DiagTable *diag_table):
DiagEntry(ping_req->get_interval() * 100, ping_req->get_count(),diag_table),
sip_(Ip4Address::from_string(ping_req->get_source_ip(), ec_)),
dip_(Ip4Address::from_string(ping_req->get_dest_ip(), ec_)),
proto_(ping_req->get_protocol()), sport_(ping_req->get_source_port()),
Expand Down Expand Up @@ -238,7 +238,7 @@ void PingReq::HandleRequest() const {
goto error;
}
}
ping = new Ping(this, Agent::GetInstance()->diag());
ping = new Ping(this, Agent::GetInstance()->diag_table());
ping->Init();
return;

Expand Down
4 changes: 2 additions & 2 deletions src/vnsw/agent/diag/ping.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef vnsw_agent_diag_ping_hpp
#define vnsw_agent_diag_ping_hpp

#include "diag/diag_table.h"
#include "diag/diag.h"
#include "diag/diag_types.h"
class DiagTable;
class Ping: public DiagEntry {
Expand All @@ -14,7 +14,7 @@ class Ping: public DiagEntry {
sizeof(iphdr) + sizeof(udphdr) + IPC_HDR_LEN;
static const uint32_t KPingTcpHdr = sizeof(ethhdr) +
sizeof(iphdr) + sizeof(tcphdr) + IPC_HDR_LEN;
Ping(const PingReq *pr,DiagTable *diag);
Ping(const PingReq *pr,DiagTable *diag_table);
virtual ~Ping();
virtual void SendRequest();
virtual void HandleReply(DiagPktHandler *handler);
Expand Down
2 changes: 1 addition & 1 deletion src/vnsw/agent/init/agent_init.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#include <kstate/kstate.h>
#include <pkt/proto.h>
#include <pkt/proto_handler.h>
#include <diag/diag_table.h>
#include <diag/diag.h>
#include <vgw/cfg_vgw.h>
#include <vgw/vgw.h>

Expand Down
2 changes: 1 addition & 1 deletion src/vnsw/agent/init/test/test_agent_init.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#include <kstate/kstate.h>
#include <pkt/proto.h>
#include <pkt/proto_handler.h>
#include <diag/diag_table.h>
#include <diag/diag.h>
#include <vgw/vgw.h>

namespace opt = boost::program_options;
Expand Down
2 changes: 1 addition & 1 deletion src/vnsw/agent/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include <uve/uve_client.h>
#include <kstate/kstate.h>
#include <pkt/proto.h>
#include <diag/diag_table.h>
#include <diag/diag.h>
#include <vgw/vgw.h>

namespace opt = boost::program_options;
Expand Down

0 comments on commit 04cf43f

Please sign in to comment.