openflow coding style changes

This commit is contained in:
Josh Pelkey
2011-05-13 14:58:28 -04:00
parent 43bb41007c
commit 0efa9719f0
6 changed files with 107 additions and 107 deletions

View File

@@ -69,9 +69,9 @@ bool
SetTimeout (std::string value)
{
try {
timeout = ns3::Seconds (atof (value.c_str ()));
return true;
}
timeout = ns3::Seconds (atof (value.c_str ()));
return true;
}
catch (...) { return false; }
return false;
}
@@ -91,7 +91,7 @@ main (int argc, char *argv[])
cmd.AddValue ("drop", "Use Drop Controller (Learning if not specified).", MakeCallback (&SetDrop));
cmd.AddValue ("t", "Learning Controller Timeout (has no effect if drop controller is specified).", MakeCallback( &SetTimeout));
cmd.AddValue ("timeout", "Learning Controller Timeout (has no effect if drop controller is specified).", MakeCallback( &SetTimeout));
cmd.Parse (argc, argv);
if (verbose)
@@ -129,18 +129,18 @@ main (int argc, char *argv[])
// Create the switch netdevice, which will do the packet switching
Ptr<Node> switchNode = csmaSwitch.Get (0);
OpenFlowSwitchHelper swtch;
if (use_drop)
{
Ptr<ns3::ofi::DropController> controller = CreateObject<ns3::ofi::DropController> ();
swtch.Install (switchNode, switchDevices, controller);
}
{
Ptr<ns3::ofi::DropController> controller = CreateObject<ns3::ofi::DropController> ();
swtch.Install (switchNode, switchDevices, controller);
}
else
{
Ptr<ns3::ofi::LearningController> controller = CreateObject<ns3::ofi::LearningController> ();
if (!timeout.IsZero ()) controller->SetAttribute ("ExpirationTime", TimeValue (timeout));
swtch.Install (switchNode, switchDevices, controller);
}
{
Ptr<ns3::ofi::LearningController> controller = CreateObject<ns3::ofi::LearningController> ();
if (!timeout.IsZero ()) controller->SetAttribute ("ExpirationTime", TimeValue (timeout));
swtch.Install (switchNode, switchDevices, controller);
}
// Add internet stack to the terminals
InternetStackHelper internet;

View File

@@ -43,7 +43,7 @@ public:
* Construct a OpenFlowSwitchHelper
*/
OpenFlowSwitchHelper ();
/**
* Set an attribute on each ns3::OpenFlowSwitchNetDevice created by
* OpenFlowSwitchHelper::Install
@@ -81,7 +81,7 @@ public:
*/
NetDeviceContainer
Install (Ptr<Node> node, NetDeviceContainer c);
/**
* This method creates an ns3::OpenFlowSwitchNetDevice with the attributes
* configured by OpenFlowSwitchHelper::SetDeviceAttribute, adds the device
@@ -94,7 +94,7 @@ public:
*/
NetDeviceContainer
Install (std::string nodeName, NetDeviceContainer c);
private:
ObjectFactory m_deviceFactory;
};

View File

@@ -25,14 +25,14 @@ namespace ns3 {
namespace ofi {
NS_LOG_COMPONENT_DEFINE ("OpenFlowInterface");
Stats::Stats (ofp_stats_types _type, size_t body_len)
{
type = _type;
size_t min_body = 0, max_body = 0;
switch (type)
{
{
case OFPST_DESC:
break;
case OFPST_FLOW:
@@ -51,13 +51,13 @@ Stats::Stats (ofp_stats_types _type, size_t body_len)
break;
default:
NS_LOG_ERROR ("received stats request of unknown type " << type);
return;// -EINVAL;
}
return; // -EINVAL;
}
if ((min_body != 0 || max_body != 0) && (body_len < min_body || body_len > max_body))
{
NS_LOG_ERROR ("stats request type " << type << " with bad body length " << body_len);
return;// -EINVAL;
return; // -EINVAL;
}
}
@@ -65,7 +65,7 @@ int
Stats::DoInit (const void *body, int body_len, void **state)
{
switch (type)
{
{
case OFPST_DESC:
return 0;
case OFPST_FLOW:
@@ -80,8 +80,8 @@ Stats::DoInit (const void *body, int body_len, void **state)
return 0;
case OFPST_VENDOR:
return 0;
}
}
return 0;
}
@@ -89,7 +89,7 @@ int
Stats::DoDump (Ptr<OpenFlowSwitchNetDevice> swtch, void *state, ofpbuf *buffer)
{
switch (type)
{
{
case OFPST_DESC:
return DescStatsDump (state, buffer);
case OFPST_FLOW:
@@ -104,8 +104,8 @@ Stats::DoDump (Ptr<OpenFlowSwitchNetDevice> swtch, void *state, ofpbuf *buffer)
return PortTableStatsDump (swtch, state, buffer);
case OFPST_VENDOR:
return 0;
}
}
return 0;
}
@@ -113,7 +113,7 @@ void
Stats::DoCleanup (void *state)
{
switch (type)
{
{
case OFPST_DESC:
break;
case OFPST_FLOW:
@@ -132,9 +132,9 @@ Stats::DoCleanup (void *state)
break;
case OFPST_VENDOR:
break;
}
}
}
int
Stats::DescStatsDump (void *state, ofpbuf *buffer)
{
@@ -245,10 +245,10 @@ Stats::AggregateStatsDump (Ptr<OpenFlowSwitchNetDevice> swtch, ofp_aggregate_sta
sw_flow_key match_key;
flow_extract_match (&match_key, &rq->match);
int table_idx = rq->table_id == 0xff ? 0 : rq->table_id;
sw_table_position position;
memset (&position, 0, sizeof position);
while (table_idx < swtch->GetChain ()->n_tables
&& (rq->table_id == 0xff || rq->table_id == table_idx))
{
@@ -722,14 +722,14 @@ Controller::StartDump (StatsDumpCallback* cb)
{
int error = 1;
while (error > 0) // Switch's StatsDump returns 1 if the reply isn't complete.
{
error = cb->swtch->StatsDump (cb);
}
{
error = cb->swtch->StatsDump (cb);
}
if (error != 0) // When the reply is complete, error will equal zero if there's no errors.
{
NS_LOG_WARN ("Dump Callback Error: " << strerror (-error));
}
{
NS_LOG_WARN ("Dump Callback Error: " << strerror (-error));
}
// Clean up
cb->swtch->StatsDone (cb);
@@ -766,13 +766,13 @@ DropController::ReceiveFromSwitch (Ptr<OpenFlowSwitchNetDevice> swtch, ofpbuf* b
TypeId LearningController::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::ofi::LearningController")
.SetParent (Controller::GetTypeId())
.AddConstructor<LearningController> ()
.AddAttribute ("ExpirationTime",
"Time it takes for learned MAC state entry/created flow to expire.",
TimeValue (Seconds (0)),
MakeTimeAccessor (&LearningController::m_expirationTime),
MakeTimeChecker ())
.SetParent (Controller::GetTypeId())
.AddConstructor<LearningController> ()
.AddAttribute ("ExpirationTime",
"Time it takes for learned MAC state entry/created flow to expire.",
TimeValue (Seconds (0)),
MakeTimeAccessor (&LearningController::m_expirationTime),
MakeTimeChecker ())
;
return tid;
}
@@ -810,7 +810,7 @@ LearningController::ReceiveFromSwitch (Ptr<OpenFlowSwitchNetDevice> swtch, ofpbu
LearnState_t::iterator st = m_learnState.find (dst_addr);
if (st != m_learnState.end ())
{
out_port = st->second.port;
out_port = st->second.port;
}
else
{
@@ -829,7 +829,7 @@ LearningController::ReceiveFromSwitch (Ptr<OpenFlowSwitchNetDevice> swtch, ofpbu
x[0].port = out_port;
// Create a new flow that outputs matched packets to a learned port, OFPP_FLOOD if there's no learned port.
ofp_flow_mod* ofm = BuildFlow (key, opi->buffer_id, OFPFC_ADD, x, sizeof(x), OFP_FLOW_PERMANENT, m_expirationTime.IsZero ()?OFP_FLOW_PERMANENT:m_expirationTime.GetSeconds ());
ofp_flow_mod* ofm = BuildFlow (key, opi->buffer_id, OFPFC_ADD, x, sizeof(x), OFP_FLOW_PERMANENT, m_expirationTime.IsZero () ? OFP_FLOW_PERMANENT : m_expirationTime.GetSeconds ());
SendToSwitch (swtch, ofm, ofm->header.length);
// We can learn a specific port for the source address for future use.
@@ -853,7 +853,7 @@ LearningController::ReceiveFromSwitch (Ptr<OpenFlowSwitchNetDevice> swtch, ofpbu
src_addr.CopyTo (key.flow.dl_dst);
dst_addr.CopyTo (key.flow.dl_src);
key.flow.in_port = out_port;
ofp_flow_mod* ofm2 = BuildFlow (key, -1, OFPFC_MODIFY, x2, sizeof(x2), OFP_FLOW_PERMANENT, m_expirationTime.IsZero ()?OFP_FLOW_PERMANENT:m_expirationTime.GetSeconds ());
ofp_flow_mod* ofm2 = BuildFlow (key, -1, OFPFC_MODIFY, x2, sizeof(x2), OFP_FLOW_PERMANENT, m_expirationTime.IsZero () ? OFP_FLOW_PERMANENT : m_expirationTime.GetSeconds ());
SendToSwitch (swtch, ofm2, ofm2->header.length);
}
}

View File

@@ -110,7 +110,7 @@ void update_checksums (ofpbuf *buffer, const sw_flow_key *key, uint32_t old_word
namespace ns3 {
class OpenFlowSwitchNetDevice;
namespace ofi {
/**
@@ -146,9 +146,9 @@ struct Port
class Stats
{
public:
public:
Stats (ofp_stats_types _type, size_t body_len);
/**
* \brief Prepares to dump some kind of statistics on the connected OpenFlowSwitchNetDevice.
*
@@ -158,7 +158,7 @@ class Stats
* \return 0 if successful, otherwise a negative error code.
*/
int DoInit (const void *body, int body_len, void **state);
/**
* \brief Appends statistics for OpenFlowSwitchNetDevice to 'buffer'.
*
@@ -168,7 +168,7 @@ class Stats
* \return 1 if it should be called again later with another buffer, 0 if it is done, or a negative errno value on failure.
*/
int DoDump (Ptr<OpenFlowSwitchNetDevice> swtch, void *state, ofpbuf *buffer);
/**
* \brief Cleans any state created by the init or dump functions.
*
@@ -177,7 +177,7 @@ class Stats
* \param state State information to clear.
*/
void DoCleanup (void *state);
/**
* \brief State of the FlowStats request/reply.
*/
@@ -190,7 +190,7 @@ class Stats
ofpbuf *buffer;
};
/**
* \brief State of the PortStats request/reply.
*/
@@ -199,9 +199,9 @@ class Stats
uint32_t num_ports; ///< Number of ports in host byte order
uint32_t *ports; ///< Array of ports in network byte order
};
ofp_stats_types type;
private:
private:
int DescStatsDump (void *state, ofpbuf *buffer);
int FlowStatsInit (const void *body, int body_len, void **state);
@@ -322,10 +322,10 @@ struct EricssonAction
struct StatsDumpCallback
{
bool done; ///< Whether we are done requesting stats.
ofp_stats_request *rq; ///< Current stats request.
Stats *s; ///< Handler of the stats request.
ofp_stats_request *rq; ///< Current stats request.
Stats *s; ///< Handler of the stats request.
void *state; ///< Stats request state data.
Ptr<OpenFlowSwitchNetDevice> swtch; ///< The switch that we're requesting data from.
Ptr<OpenFlowSwitchNetDevice> swtch; ///< The switch that we're requesting data from.
};
/**
@@ -335,7 +335,7 @@ struct SwitchPacketMetadata
{
Ptr<Packet> packet; ///< The Packet itself.
ofpbuf* buffer; ///< The OpenFlow buffer as created from the Packet, with its data and headers.
uint16_t protocolNumber; ///< Protocol type of the Packet when the Packet is received
uint16_t protocolNumber; ///< Protocol type of the Packet when the Packet is received
Address src; ///< Source Address of the Packet when the Packet is received
Address dst; ///< Destination Address of the Packet when the Packet is received.
};
@@ -351,17 +351,17 @@ public:
static TypeId GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::ofi::Controller")
.SetParent<Object> ()
.AddConstructor<Controller> ()
.SetParent<Object> ()
.AddConstructor<Controller> ()
;
return tid;
}
virtual ~Controller ()
{
m_switches.clear ();
}
/**
* Adds a switch to the controller.
*
@@ -378,7 +378,7 @@ public:
virtual void ReceiveFromSwitch (Ptr<OpenFlowSwitchNetDevice> swtch, ofpbuf* buffer)
{
}
/**
* \brief Starts a callback-based, reliable, possibly multi-message reply to a request made by the controller.
*
@@ -438,7 +438,7 @@ protected:
* \return The packet type, as defined in the ofp_type struct.
*/
uint8_t GetPacketType (ofpbuf* buffer);
typedef std::set<Ptr<OpenFlowSwitchNetDevice> > Switches_t;
Switches_t m_switches; ///< The collection of switches registered to this controller.
};
@@ -465,12 +465,12 @@ class LearningController : public Controller
{
public:
static TypeId GetTypeId (void);
virtual ~LearningController ()
{
m_learnState.clear ();
}
void ReceiveFromSwitch (Ptr<OpenFlowSwitchNetDevice> swtch, ofpbuf* buffer);
protected:
@@ -478,7 +478,7 @@ protected:
{
uint32_t port; ///< Learned port.
};
Time m_expirationTime; ///< Time it takes for learned MAC state entry/created flow to expire.
Time m_expirationTime; ///< Time it takes for learned MAC state entry/created flow to expire.
typedef std::map<Mac48Address, LearnedState> LearnState_t;
LearnState_t m_learnState; ///< Learned state data.
};

View File

@@ -74,15 +74,15 @@ OpenFlowSwitchNetDevice::GetTypeId (void)
MakeTimeAccessor (&OpenFlowSwitchNetDevice::m_lookupDelay),
MakeTimeChecker ())
.AddAttribute ("Flags", // Note: The Controller can configure this value, overriding the user's setting.
"Flags to turn different functionality on/off, such as whether to inform the controller when a flow expires, or how to handle fragments.",
UintegerValue (0), // Look at the ofp_config_flags enum in openflow/include/openflow.h for options.
MakeUintegerAccessor (&OpenFlowSwitchNetDevice::m_flags),
MakeUintegerChecker<uint16_t> ())
"Flags to turn different functionality on/off, such as whether to inform the controller when a flow expires, or how to handle fragments.",
UintegerValue (0), // Look at the ofp_config_flags enum in openflow/include/openflow.h for options.
MakeUintegerAccessor (&OpenFlowSwitchNetDevice::m_flags),
MakeUintegerChecker<uint16_t> ())
.AddAttribute ("FlowTableMissSendLength", // Note: The Controller can configure this value, overriding the user's setting.
"When forwarding a packet the switch didn't match up to the controller, it can be more efficient to forward only the first x bytes.",
UintegerValue (OFP_DEFAULT_MISS_SEND_LEN), // 128 bytes
MakeUintegerAccessor (&OpenFlowSwitchNetDevice::m_missSendLen),
MakeUintegerChecker<uint16_t> ())
"When forwarding a packet the switch didn't match up to the controller, it can be more efficient to forward only the first x bytes.",
UintegerValue (OFP_DEFAULT_MISS_SEND_LEN), // 128 bytes
MakeUintegerAccessor (&OpenFlowSwitchNetDevice::m_missSendLen),
MakeUintegerChecker<uint16_t> ())
;
return tid;
}
@@ -589,7 +589,7 @@ OpenFlowSwitchNetDevice::BufferFromPacket (Ptr<Packet> packet, Address src, Addr
void
OpenFlowSwitchNetDevice::ReceiveFromDevice (Ptr<NetDevice> netdev, Ptr<const Packet> packet, uint16_t protocol,
const Address& src, const Address& dst, PacketType packetType)
const Address& src, const Address& dst, PacketType packetType)
{
NS_LOG_FUNCTION_NOARGS ();
NS_LOG_INFO ("--------------------------------------------");
@@ -645,7 +645,7 @@ OpenFlowSwitchNetDevice::ReceiveFromDevice (Ptr<NetDevice> netdev, Ptr<const Pac
break;
}
}
// Run periodic execution.
Time now = Simulator::Now();
if (now >= Seconds (m_lastExecute.GetSeconds () + 1)) // If a second or more has passed from the simulation time, execute.
@@ -665,21 +665,21 @@ OpenFlowSwitchNetDevice::ReceiveFromDevice (Ptr<NetDevice> netdev, Ptr<const Pac
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.";
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 ());
NS_LOG_INFO (str.str ());
SendFlowExpired (f, (ofp_flow_expired_reason)f->reason);
list_remove (&f->node);
flow_free (f);
}
m_lastExecute = now;
}
}
@@ -845,7 +845,7 @@ OpenFlowSwitchNetDevice::FillPortDesc (ofi::Port p, ofp_phy_port *desc)
p.netdev->GetAddress ().CopyTo (desc->hw_addr);
desc->config = htonl (p.config);
desc->state = htonl (p.state);
// TODO: This should probably be fixed eventually to specify different available features.
desc->curr = 0; // htonl(netdev_get_features(p->netdev, NETDEV_FEAT_CURRENT));
desc->supported = 0; // htonl(netdev_get_features(p->netdev, NETDEV_FEAT_SUPPORTED));
@@ -1099,7 +1099,7 @@ int
OpenFlowSwitchNetDevice::ReceiveSetConfig (const void *msg)
{
const ofp_switch_config *osc = (ofp_switch_config*)msg;
int n_flags = ntohs (osc->flags) & (OFPC_SEND_FLOW_EXP | OFPC_FRAG_MASK);
if ((n_flags & OFPC_FRAG_MASK) != OFPC_FRAG_NORMAL && (n_flags & OFPC_FRAG_MASK) != OFPC_FRAG_DROP)
{
@@ -1159,7 +1159,7 @@ int
OpenFlowSwitchNetDevice::ReceivePortMod (const void *msg)
{
ofp_port_mod* opm = (ofp_port_mod*)msg;
int port = opm->port_no; // ntohs(opm->port_no);
if (port < DP_MAX_PORTS)
{
@@ -1185,16 +1185,16 @@ OpenFlowSwitchNetDevice::ReceivePortMod (const void *msg)
if ((opm->config & htonl (OFPPC_PORT_DOWN)) && (p.config & OFPPC_PORT_DOWN) == 0)
{
p.config |= OFPPC_PORT_DOWN;
// TODO: Possibly disable the Port's Net Device via the appropriate interface.
// TODO: Possibly disable the Port's Net Device via the appropriate interface.
}
else if ((opm->config & htonl (OFPPC_PORT_DOWN)) == 0 && (p.config & OFPPC_PORT_DOWN))
{
p.config &= ~OFPPC_PORT_DOWN;
// TODO: Possibly enable the Port's Net Device via the appropriate interface.
// TODO: Possibly enable the Port's Net Device via the appropriate interface.
}
}
}
return 0;
}
@@ -1431,7 +1431,7 @@ OpenFlowSwitchNetDevice::ReceiveStatsRequest (const void *oh)
int type = ntohs (rq->type);
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)
{
return -EINVAL;
@@ -1463,7 +1463,7 @@ OpenFlowSwitchNetDevice::ReceiveStatsRequest (const void *oh)
{
NS_LOG_ERROR ("Switch needs to be registered to a controller in order to start the stats reply.");
}
return 0;
}

View File

@@ -101,7 +101,7 @@ public:
static const char * GetSoftwareDescription ();
static const char * GetSerialNumber ();
//\}
OpenFlowSwitchNetDevice ();
virtual ~OpenFlowSwitchNetDevice ();
@@ -238,7 +238,7 @@ public:
virtual bool SupportsSendFrom () const;
virtual Address GetMulticast (Ipv6Address addr) const;
//\}
protected:
virtual void DoDispose (void);
@@ -292,7 +292,7 @@ private:
* \return 0 if everything's ok, otherwise an error number.
*/
int ModFlow (const ofp_flow_mod *ofm);
/**
* \internal
*
@@ -444,7 +444,7 @@ private:
* \return 0 if everything's ok, otherwise an error number.
*/
int RunThroughVPortTable (uint32_t packet_uid, int port, uint32_t vport);
/**
* \internal
*
@@ -514,7 +514,7 @@ private:
int ReceiveVPortMod (const void *msg);
int ReceiveVPortTableFeaturesRequest (const void *msg);
//\}
/// Callbacks
NetDevice::ReceiveCallback m_rxCallback;
NetDevice::PromiscReceiveCallback m_promiscRxCallback;
@@ -536,7 +536,7 @@ private:
uint64_t m_id; ///< Unique identifier for this switch, needed for OpenFlow
Time m_lookupDelay; ///< Flow Table Lookup Delay [overhead].
Time m_lastExecute; ///< Last time the periodic execution occurred.
Time m_lastExecute; ///< Last time the periodic execution occurred.
uint16_t m_flags; ///< Flags; configurable by the controller.
uint16_t m_missSendLen; ///< Flow Table Miss Send Length; configurable by the controller.