25 #include "ns3/openflow-switch-net-device.h" 
   26 #include "ns3/openflow-interface.h" 
   38     m_chain = chain_create ();
 
   43     chain_destroy (m_chain);
 
   47   virtual void DoRun (
void);
 
   61   size_t actions_len = 0; 
 
   64   Mac48Address dl_src (
"00:00:00:00:00:00"), dl_dst (
"00:00:00:00:00:01");
 
   65   Ipv4Address nw_src (
"192.168.1.1"), nw_dst (
"192.168.1.2");
 
   66   int tp_src = 5000, tp_dst = 80;
 
   72   key.flow.in_port = htons (0);
 
   74   key.flow.dl_vlan = htons (OFP_VLAN_NONE);
 
   75   key.flow.dl_type = htons (ETH_TYPE_IP);
 
   76   key.flow.nw_proto = htons (IP_TYPE_UDP);
 
   78   key.flow.reserved = 0;
 
   79   key.flow.mpls_label1 = htonl (MPLS_INVALID_LABEL);
 
   80   key.flow.mpls_label2 = htonl (MPLS_INVALID_LABEL);
 
   83   dl_src.CopyTo (key.flow.dl_src);
 
   84   dl_dst.
CopyTo (key.flow.dl_dst);
 
   87   key.flow.nw_src = htonl (nw_src.Get ());
 
   88   key.flow.nw_dst = htonl (nw_dst.
Get ());
 
   91   key.flow.tp_src = htonl (tp_src);
 
   92   key.flow.tp_dst = htonl (tp_dst);
 
   96   ofm.header.version = OFP_VERSION;
 
   97   ofm.header.type = OFPT_FLOW_MOD;
 
   98   ofm.header.length = htons (
sizeof (ofp_flow_mod) + actions_len);
 
   99   ofm.command = htons (OFPFC_ADD);
 
  100   ofm.idle_timeout = htons (OFP_FLOW_PERMANENT);
 
  101   ofm.hard_timeout = htons (OFP_FLOW_PERMANENT);
 
  102   ofm.buffer_id = htonl (-1);
 
  103   ofm.priority = OFP_DEFAULT_PRIORITY;
 
  105   ofm.match.wildcards = key.wildcards;                                 
 
  106   ofm.match.in_port = key.flow.in_port;                                
 
  107   memcpy (ofm.match.dl_src, key.flow.dl_src, 
sizeof ofm.match.dl_src); 
 
  108   memcpy (ofm.match.dl_dst, key.flow.dl_dst, 
sizeof ofm.match.dl_dst); 
 
  109   ofm.match.dl_vlan = key.flow.dl_vlan;                                
 
  110   ofm.match.dl_type = key.flow.dl_type;                                
 
  111   ofm.match.nw_proto = key.flow.nw_proto;                              
 
  112   ofm.match.nw_src = key.flow.nw_src;                                  
 
  113   ofm.match.nw_dst = key.flow.nw_dst;                                  
 
  114   ofm.match.tp_src = key.flow.tp_src;                                  
 
  115   ofm.match.tp_dst = key.flow.tp_dst;                                  
 
  116   ofm.match.mpls_label1 = key.flow.mpls_label1;                        
 
  117   ofm.match.mpls_label2 = key.flow.mpls_label1;                        
 
  120   sw_flow *flow = flow_alloc (actions_len);
 
  123   flow_extract_match (&flow->key, &ofm.match);
 
  126   flow->priority = flow->key.wildcards ? ntohs (ofm.priority) : -1;
 
  127   flow->idle_timeout = ntohs (ofm.idle_timeout);
 
  128   flow->hard_timeout = ntohs (ofm.hard_timeout);
 
  129   flow->used = flow->created = time_now ();
 
  130   flow->sf_acts->actions_len = actions_len;
 
  131   flow->byte_count = 0;
 
  132   flow->packet_count = 0;
 
  133   memcpy (flow->sf_acts->actions, ofm.actions, actions_len);
 
  139   NS_TEST_ASSERT_MSG_NE (chain_lookup (m_chain, &key), 0, 
"Key provided doesn't match to the flow that was created from it.");
 
  142   dl_dst.
CopyTo (key.flow.dl_src);
 
  143   dl_src.CopyTo (key.flow.dl_dst);
 
  144   key.flow.nw_src = htonl (nw_dst.
Get ());
 
  145   key.flow.nw_dst = htonl (nw_src.Get ());
 
  146   key.flow.tp_src = htonl (tp_dst);
 
  147   key.flow.tp_dst = htonl (tp_src);
 
  149   NS_TEST_ASSERT_MSG_EQ (chain_lookup (m_chain, &key), 0, 
"Key provided shouldn't match the flow but it does.");
 
  152   dl_dst.
CopyTo (key.flow.dl_dst);
 
  153   dl_src.CopyTo (key.flow.dl_src);
 
  154   key.flow.nw_src = htonl (nw_src.Get ());
 
  155   key.flow.nw_dst = htonl (nw_dst.
Get ());
 
  156   key.flow.tp_src = htonl (tp_src);
 
  157   key.flow.tp_dst = htonl (tp_dst);
 
  161   ofp_action_output acts[1];
 
  162   acts[0].type = htons (OFPAT_OUTPUT);
 
  163   acts[0].len = htons (
sizeof (ofp_action_output));
 
  164   acts[0].port = output_port;
 
  166   uint16_t priority = key.wildcards ? ntohs (ofm.priority) : -1;
 
  167   NS_TEST_ASSERT_MSG_EQ (chain_modify (m_chain, &key, priority, 
false, (
const ofp_action_header*)acts, 
sizeof (acts)), 1, 
"Flow table failed to modify Flow.");
 
  172   NS_TEST_ASSERT_MSG_EQ (chain_delete (m_chain, &key, output_port, 0, 0), 1, 
"Flow table failed to delete Flow.");
 
  173   NS_TEST_ASSERT_MSG_EQ (chain_lookup (m_chain, &key), 0, 
"Key provided shouldn't match the flow but it does.");
 
virtual ~SwitchFlowTableTestCase()
#define NS_TEST_ASSERT_MSG_NE(actual, limit, msg)
Test that an actual and expected (limit) value are not equal and report and abort if not...
void CopyTo(uint8_t buffer[6]) const 
uint32_t Get(void) const 
Get the host-order 32-bit IP address. 
static SwitchTestSuite switchTestSuite
SwitchFlowTableTestCase()
virtual void DoRun(void)
Implementation to actually run this TestCase. 
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual child TestCase case to this TestCase. 
Ipv4 addresses are stored in host order in this class. 
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.