openflow: Fix clang-tidy warnings
This commit is contained in:
@@ -31,7 +31,8 @@ namespace ofi
|
||||
Stats::Stats(ofp_stats_types _type, size_t body_len)
|
||||
{
|
||||
type = _type;
|
||||
size_t min_body = 0, max_body = 0;
|
||||
size_t min_body = 0;
|
||||
size_t max_body = 0;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
@@ -378,7 +379,7 @@ Stats::PortStatsDump(Ptr<OpenFlowSwitchNetDevice> swtch, PortStatsState* s, ofpb
|
||||
// lookup the virtual port
|
||||
vport_table_t vt = swtch->GetVPortTable();
|
||||
vport_table_entry* vpe = vport_table_lookup(&vt, port);
|
||||
if (vpe == 0)
|
||||
if (!vpe)
|
||||
{
|
||||
NS_LOG_ERROR("vport entry not found!");
|
||||
continue;
|
||||
@@ -588,12 +589,12 @@ VPortAction::Execute(ofp_vport_action_type type,
|
||||
{
|
||||
case OFPPAT_POP_MPLS: {
|
||||
ofp_vport_action_pop_mpls* opapm = (ofp_vport_action_pop_mpls*)ah;
|
||||
pop_mpls_act(0, buffer, key, &opapm->apm);
|
||||
pop_mpls_act(nullptr, buffer, key, &opapm->apm);
|
||||
break;
|
||||
}
|
||||
case OFPPAT_PUSH_MPLS: {
|
||||
ofp_vport_action_push_mpls* opapm = (ofp_vport_action_push_mpls*)ah;
|
||||
push_mpls_act(0, buffer, key, &opapm->apm);
|
||||
push_mpls_act(nullptr, buffer, key, &opapm->apm);
|
||||
break;
|
||||
}
|
||||
case OFPPAT_SET_MPLS_LABEL: {
|
||||
@@ -658,12 +659,12 @@ EricssonAction::Execute(er_action_type type,
|
||||
{
|
||||
case ERXT_POP_MPLS: {
|
||||
er_action_pop_mpls* erapm = (er_action_pop_mpls*)ah;
|
||||
pop_mpls_act(0, buffer, key, &erapm->apm);
|
||||
pop_mpls_act(nullptr, buffer, key, &erapm->apm);
|
||||
break;
|
||||
}
|
||||
case ERXT_PUSH_MPLS: {
|
||||
er_action_push_mpls* erapm = (er_action_push_mpls*)ah;
|
||||
push_mpls_act(0, buffer, key, &erapm->apm);
|
||||
push_mpls_act(nullptr, buffer, key, &erapm->apm);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -766,7 +767,7 @@ Controller::GetPacketType(ofpbuf* buffer)
|
||||
void
|
||||
Controller::StartDump(StatsDumpCallback* cb)
|
||||
{
|
||||
if (cb != 0)
|
||||
if (cb)
|
||||
{
|
||||
int error = 1;
|
||||
while (error > 0) // Switch's StatsDump returns 1 if the reply isn't complete.
|
||||
@@ -819,8 +820,13 @@ DropController::ReceiveFromSwitch(Ptr<OpenFlowSwitchNetDevice> swtch, ofpbuf* bu
|
||||
key.wildcards = 0;
|
||||
flow_extract(buffer, port != -1 ? port : OFPP_NONE, &key.flow);
|
||||
|
||||
ofp_flow_mod* ofm =
|
||||
BuildFlow(key, opi->buffer_id, OFPFC_ADD, 0, 0, OFP_FLOW_PERMANENT, OFP_FLOW_PERMANENT);
|
||||
ofp_flow_mod* ofm = BuildFlow(key,
|
||||
opi->buffer_id,
|
||||
OFPFC_ADD,
|
||||
nullptr,
|
||||
0,
|
||||
OFP_FLOW_PERMANENT,
|
||||
OFP_FLOW_PERMANENT);
|
||||
SendToSwitch(swtch, ofm, ofm->header.length);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ struct Port
|
||||
Port()
|
||||
: config(0),
|
||||
state(0),
|
||||
netdev(0),
|
||||
netdev(nullptr),
|
||||
rx_packets(0),
|
||||
tx_packets(0),
|
||||
rx_bytes(0),
|
||||
@@ -405,7 +405,7 @@ class Controller : public Object
|
||||
*/
|
||||
static TypeId GetTypeId();
|
||||
/** Destructor. */
|
||||
virtual ~Controller();
|
||||
~Controller() override;
|
||||
|
||||
/**
|
||||
* Adds a switch to the controller.
|
||||
@@ -508,7 +508,7 @@ class DropController : public Controller
|
||||
*/
|
||||
static TypeId GetTypeId();
|
||||
|
||||
void ReceiveFromSwitch(Ptr<OpenFlowSwitchNetDevice> swtch, ofpbuf* buffer);
|
||||
void ReceiveFromSwitch(Ptr<OpenFlowSwitchNetDevice> swtch, ofpbuf* buffer) override;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -528,12 +528,12 @@ class LearningController : public Controller
|
||||
*/
|
||||
static TypeId GetTypeId();
|
||||
|
||||
virtual ~LearningController()
|
||||
~LearningController() override
|
||||
{
|
||||
m_learnState.clear();
|
||||
}
|
||||
|
||||
void ReceiveFromSwitch(Ptr<OpenFlowSwitchNetDevice> swtch, ofpbuf* buffer);
|
||||
void ReceiveFromSwitch(Ptr<OpenFlowSwitchNetDevice> swtch, ofpbuf* buffer) override;
|
||||
|
||||
protected:
|
||||
/// Learned state
|
||||
|
||||
@@ -99,7 +99,7 @@ OpenFlowSwitchNetDevice::GetTypeId()
|
||||
}
|
||||
|
||||
OpenFlowSwitchNetDevice::OpenFlowSwitchNetDevice()
|
||||
: m_node(0),
|
||||
: m_node(nullptr),
|
||||
m_ifIndex(0),
|
||||
m_mtu(0xffff)
|
||||
{
|
||||
@@ -110,11 +110,11 @@ OpenFlowSwitchNetDevice::OpenFlowSwitchNetDevice()
|
||||
time_init(); // OFSI's clock; needed to use the buffer storage system.
|
||||
// m_lastTimeout = time_now ();
|
||||
|
||||
m_controller = 0;
|
||||
m_controller = nullptr;
|
||||
// m_listenPVConn = 0;
|
||||
|
||||
m_chain = chain_create();
|
||||
if (m_chain == 0)
|
||||
if (!m_chain)
|
||||
{
|
||||
NS_LOG_ERROR("Not enough memory to create the flow table.");
|
||||
}
|
||||
@@ -136,16 +136,16 @@ OpenFlowSwitchNetDevice::DoDispose()
|
||||
for (Ports_t::iterator b = m_ports.begin(), e = m_ports.end(); b != e; b++)
|
||||
{
|
||||
SendPortStatus(*b, OFPPR_DELETE);
|
||||
b->netdev = 0;
|
||||
b->netdev = nullptr;
|
||||
}
|
||||
m_ports.clear();
|
||||
|
||||
m_controller = 0;
|
||||
m_controller = nullptr;
|
||||
|
||||
chain_destroy(m_chain);
|
||||
RBTreeDestroy(m_vportTable.table);
|
||||
m_channel = 0;
|
||||
m_node = 0;
|
||||
m_channel = nullptr;
|
||||
m_node = nullptr;
|
||||
NetDevice::DoDispose();
|
||||
}
|
||||
|
||||
@@ -418,7 +418,7 @@ OpenFlowSwitchNetDevice::AddVPort(const ofp_vport_mod* ovpm)
|
||||
|
||||
// check whether port table entry exists for specified port number
|
||||
vport_table_entry* vpe = vport_table_lookup(&m_vportTable, vport);
|
||||
if (vpe != 0)
|
||||
if (vpe)
|
||||
{
|
||||
NS_LOG_ERROR("vport " << vport << " already exists!");
|
||||
SendErrorMsg(OFPET_BAD_ACTION, OFPET_VPORT_MOD_FAILED, ovpm, ntohs(ovpm->header.length));
|
||||
@@ -478,7 +478,9 @@ OpenFlowSwitchNetDevice::BufferFromPacket(Ptr<const Packet> constPacket,
|
||||
ofpbuf* buffer = ofpbuf_new(headroom + hard_header + mtu);
|
||||
buffer->data = (char*)buffer->data + headroom + hard_header;
|
||||
|
||||
int l2_length = 0, l3_length = 0, l4_length = 0;
|
||||
int l2_length = 0;
|
||||
int l3_length = 0;
|
||||
int l4_length = 0;
|
||||
|
||||
// Parse Ethernet header
|
||||
buffer->l2 = new eth_header;
|
||||
@@ -707,19 +709,24 @@ OpenFlowSwitchNetDevice::ReceiveFromDevice(Ptr<NetDevice> netdev,
|
||||
|
||||
// If any flows have expired, delete them and notify the controller.
|
||||
List deleted = LIST_INITIALIZER(&deleted);
|
||||
sw_flow *f, *n;
|
||||
sw_flow* f;
|
||||
sw_flow* n;
|
||||
chain_timeout(m_chain, &deleted);
|
||||
LIST_FOR_EACH_SAFE(f, n, sw_flow, node, &deleted)
|
||||
{
|
||||
std::ostringstream str;
|
||||
str << "Flow [";
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
str << (i != 0 ? ":" : "") << std::hex << f->key.flow.dl_src[i] / 16
|
||||
<< f->key.flow.dl_src[i] % 16;
|
||||
}
|
||||
str << " -> ";
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
str << (i != 0 ? ":" : "") << std::hex << f->key.flow.dl_dst[i] / 16
|
||||
<< f->key.flow.dl_dst[i] % 16;
|
||||
}
|
||||
str << "] expired.";
|
||||
|
||||
NS_LOG_INFO(str.str());
|
||||
@@ -1014,7 +1021,7 @@ OpenFlowSwitchNetDevice::FlowTableLookup(sw_flow_key key,
|
||||
bool send_to_controller)
|
||||
{
|
||||
sw_flow* flow = chain_lookup(m_chain, &key);
|
||||
if (flow != 0)
|
||||
if (flow)
|
||||
{
|
||||
NS_LOG_INFO("Flow matched");
|
||||
flow_used(flow, buffer);
|
||||
@@ -1120,7 +1127,7 @@ OpenFlowSwitchNetDevice::RunThroughVPortTable(uint32_t packet_uid, int port, uin
|
||||
{
|
||||
m_vportTable.port_match_count++;
|
||||
}
|
||||
while (vpe != 0)
|
||||
while (vpe)
|
||||
{
|
||||
ofi::ExecuteVPortActions(this,
|
||||
packet_uid,
|
||||
@@ -1129,7 +1136,7 @@ OpenFlowSwitchNetDevice::RunThroughVPortTable(uint32_t packet_uid, int port, uin
|
||||
vpe->port_acts->actions,
|
||||
vpe->port_acts->actions_len);
|
||||
vport_used(vpe, buffer); // update counters for virtual port
|
||||
if (vpe->parent_port_ptr == 0)
|
||||
if (!vpe->parent_port_ptr)
|
||||
{
|
||||
// if a port table's parent_port_ptr is 0 then
|
||||
// the parent_port should be a physical port
|
||||
@@ -1220,7 +1227,7 @@ OpenFlowSwitchNetDevice::ReceivePacketOut(const void* msg)
|
||||
else
|
||||
{
|
||||
buffer = retrieve_buffer(ntohl(opo->buffer_id));
|
||||
if (buffer == 0)
|
||||
if (!buffer)
|
||||
{
|
||||
return -ESRCH;
|
||||
}
|
||||
@@ -1316,7 +1323,7 @@ OpenFlowSwitchNetDevice::AddFlow(const ofp_flow_mod* ofm)
|
||||
|
||||
// Allocate memory.
|
||||
sw_flow* flow = flow_alloc(actions_len);
|
||||
if (flow == 0)
|
||||
if (!flow)
|
||||
{
|
||||
if (ntohl(ofm->buffer_id) != (uint32_t)-1)
|
||||
{
|
||||
@@ -1540,7 +1547,7 @@ OpenFlowSwitchNetDevice::ReceiveStatsRequest(const void* oh)
|
||||
int body_len = rq_len - offsetof(ofp_stats_request, body);
|
||||
ofi::Stats* st = new ofi::Stats((ofp_stats_types)type, (unsigned)body_len);
|
||||
|
||||
if (st == 0)
|
||||
if (!st)
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
@@ -1549,7 +1556,7 @@ OpenFlowSwitchNetDevice::ReceiveStatsRequest(const void* oh)
|
||||
cb.done = false;
|
||||
cb.rq = (ofp_stats_request*)xmemdup(rq, rq_len);
|
||||
cb.s = st;
|
||||
cb.state = 0;
|
||||
cb.state = nullptr;
|
||||
cb.swtch = this;
|
||||
|
||||
if (cb.s)
|
||||
@@ -1646,7 +1653,7 @@ OpenFlowSwitchNetDevice::ForwardControlInput(const void* msg, size_t length)
|
||||
error = -EINVAL;
|
||||
}
|
||||
|
||||
if (msg != 0)
|
||||
if (msg)
|
||||
{
|
||||
free((ofpbuf*)msg);
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ class OpenFlowSwitchNetDevice : public NetDevice
|
||||
/**@}*/
|
||||
|
||||
OpenFlowSwitchNetDevice();
|
||||
virtual ~OpenFlowSwitchNetDevice();
|
||||
~OpenFlowSwitchNetDevice() override;
|
||||
|
||||
/**
|
||||
* \brief Set up the Switch's controller connection.
|
||||
@@ -232,36 +232,36 @@ class OpenFlowSwitchNetDevice : public NetDevice
|
||||
vport_table_t GetVPortTable();
|
||||
|
||||
// From NetDevice
|
||||
virtual void SetIfIndex(const uint32_t index);
|
||||
virtual uint32_t GetIfIndex() const;
|
||||
virtual Ptr<Channel> GetChannel() const;
|
||||
virtual void SetAddress(Address address);
|
||||
virtual Address GetAddress() const;
|
||||
virtual bool SetMtu(const uint16_t mtu);
|
||||
virtual uint16_t GetMtu() const;
|
||||
virtual bool IsLinkUp() const;
|
||||
virtual void AddLinkChangeCallback(Callback<void> callback);
|
||||
virtual bool IsBroadcast() const;
|
||||
virtual Address GetBroadcast() const;
|
||||
virtual bool IsMulticast() const;
|
||||
virtual Address GetMulticast(Ipv4Address multicastGroup) const;
|
||||
virtual bool IsPointToPoint() const;
|
||||
virtual bool IsBridge() const;
|
||||
virtual bool Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber);
|
||||
virtual bool SendFrom(Ptr<Packet> packet,
|
||||
const Address& source,
|
||||
const Address& dest,
|
||||
uint16_t protocolNumber);
|
||||
virtual Ptr<Node> GetNode() const;
|
||||
virtual void SetNode(Ptr<Node> node);
|
||||
virtual bool NeedsArp() const;
|
||||
virtual void SetReceiveCallback(NetDevice::ReceiveCallback cb);
|
||||
virtual void SetPromiscReceiveCallback(NetDevice::PromiscReceiveCallback cb);
|
||||
virtual bool SupportsSendFrom() const;
|
||||
virtual Address GetMulticast(Ipv6Address addr) const;
|
||||
void SetIfIndex(const uint32_t index) override;
|
||||
uint32_t GetIfIndex() const override;
|
||||
Ptr<Channel> GetChannel() const override;
|
||||
void SetAddress(Address address) override;
|
||||
Address GetAddress() const override;
|
||||
bool SetMtu(const uint16_t mtu) override;
|
||||
uint16_t GetMtu() const override;
|
||||
bool IsLinkUp() const override;
|
||||
void AddLinkChangeCallback(Callback<void> callback) override;
|
||||
bool IsBroadcast() const override;
|
||||
Address GetBroadcast() const override;
|
||||
bool IsMulticast() const override;
|
||||
Address GetMulticast(Ipv4Address multicastGroup) const override;
|
||||
bool IsPointToPoint() const override;
|
||||
bool IsBridge() const override;
|
||||
bool Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber) override;
|
||||
bool SendFrom(Ptr<Packet> packet,
|
||||
const Address& source,
|
||||
const Address& dest,
|
||||
uint16_t protocolNumber) override;
|
||||
Ptr<Node> GetNode() const override;
|
||||
void SetNode(Ptr<Node> node) override;
|
||||
bool NeedsArp() const override;
|
||||
void SetReceiveCallback(NetDevice::ReceiveCallback cb) override;
|
||||
void SetPromiscReceiveCallback(NetDevice::PromiscReceiveCallback cb) override;
|
||||
bool SupportsSendFrom() const override;
|
||||
Address GetMulticast(Ipv6Address addr) const override;
|
||||
|
||||
protected:
|
||||
virtual void DoDispose();
|
||||
void DoDispose() override;
|
||||
|
||||
/**
|
||||
* Called when a packet is received on one of the switch's ports.
|
||||
|
||||
@@ -41,7 +41,7 @@ class SwitchFlowTableTestCase : public TestCase
|
||||
m_chain = chain_create();
|
||||
}
|
||||
|
||||
virtual ~SwitchFlowTableTestCase()
|
||||
~SwitchFlowTableTestCase() override
|
||||
{
|
||||
chain_destroy(m_chain);
|
||||
}
|
||||
@@ -64,8 +64,10 @@ SwitchFlowTableTestCase::DoRun()
|
||||
size_t actions_len = 0; // Flow is created with 0 actions.
|
||||
int output_port = 0; // Flow will be modified later with an action to output on port 0.
|
||||
|
||||
Mac48Address dl_src("00:00:00:00:00:00"), dl_dst("00:00:00:00:00:01");
|
||||
Ipv4Address nw_src("192.168.1.1"), nw_dst("192.168.1.2");
|
||||
Mac48Address dl_src("00:00:00:00:00:00");
|
||||
Mac48Address dl_dst("00:00:00:00:00:01");
|
||||
Ipv4Address nw_src("192.168.1.1");
|
||||
Ipv4Address nw_dst("192.168.1.2");
|
||||
int tp_src = 5000;
|
||||
int tp_dst = 80;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user