8 #include <pugixml/pugixml.hpp>
9 #include <boost/uuid/uuid.hpp>
10 #include <boost/uuid/string_generator.hpp>
12 #include <test/test_cmn_util.h>
13 #include <pkt/test/test_pkt_util.h>
24 using namespace boost::uuids;
41 tunnel_sip_ =
"0.0.0.0";
42 tunnel_dip_ =
"0.0.0.0";
46 smac_ =
"00:00:00:00:00:01";
47 dmac_ =
"00:00:00:00:00:02";
65 if (tunnel_type_ ==
"gre" || tunnel_type_ ==
"GRE")
67 if (tunnel_type_ ==
"udp" || tunnel_type_ ==
"UDP")
69 if (tunnel_type_ ==
"vxlan" || tunnel_type_ ==
"VXLAN")
82 return atoi(proto_.c_str());
86 if (trap_code_ ==
"flow")
94 if (pkt_module_ ==
"flow" || pkt_module_ ==
"FLOW")
96 if (pkt_module_ ==
"invalid" || pkt_module_ ==
"INVALID")
104 if (fwd_mode_ ==
"l2" || fwd_mode_ ==
"L2")
110 if (fwd_mode_ ==
"l3" || fwd_mode_ ==
"L3")
120 if (tunnel_type_ !=
"") {
150 if (tunnel_type_ ==
"") {
151 s <<
"Packet < " << name_ <<
"> Interface <" << intf_ <<
"> ";
153 s <<
"Packet < " << name_ <<
"> Tunnel <" << tunnel_type_ <<
" : "
154 << intf_ <<
" : " << label_ <<
" : " << tunnel_sip_ <<
" : "
155 << tunnel_dip_ <<
"> ";
157 s <<
"<" << sip_ <<
" : " << dip_ <<
" : " << proto_ <<
" : " << sport_
158 <<
" : " << dport_ <<
">" << endl;
177 pkt->AddEthHdr(
"00:00:00:00:00:01",
"00:00:00:00:00:02", 0x800);
180 string dip = tunnel_dip_;
181 if (dip ==
"0.0.0.0") {
185 uint8_t proto = IPPROTO_UDP;
189 pkt->AddIpHdr(tunnel_sip_.c_str(), dip.c_str(), proto);
192 pkt->AddMplsHdr(label_,
true);
194 pkt->AddUdpHdr(VR_MPLS_OVER_UDP_SRC_PORT, VR_MPLS_OVER_UDP_DST_PORT,
196 pkt->AddMplsHdr(label_,
true);
198 pkt->AddUdpHdr(VR_VXLAN_UDP_SRC_PORT, VR_VXLAN_UDP_DST_PORT, 0);
200 pkt->AddVxlanHdr(vxlan);
203 if (fwd_mode_ ==
"l2") {
204 pkt->AddEthHdr(dmac_.c_str(), smac_.c_str(), 0x800);
207 pkt->AddEthHdr(dmac_.c_str(), smac_.c_str(), 0x800);
210 pkt->AddIpHdr(sip_.c_str(), dip_.c_str(), proto_id_);
211 if (proto_id_ == 17) {
212 pkt->AddUdpHdr(sport_, dport_, len_);
213 }
else if (proto_id_ == 6) {
214 pkt->AddTcpHdr(sport_, dport_,
false,
false, tcp_ack_, len_);
215 }
else if (proto_id_ == 1) {
231 boost::system::error_code ec;
232 IpAddress ip = IpAddress::from_string(sip_, ec);
234 bool ingress_flow =
true;
237 ingress_flow =
false;
241 if (atoi(intf_.c_str())) {
242 intf =
static_cast<VmInterface *
>(VmPortGet(atoi(intf_.c_str())));
244 intf_id_ = intf->
id();
252 label_ = intf->
label();
256 if (fwd_mode_ !=
"l2") {
263 if (proto_id_ == 0) {
264 proto_id_ = GetIpProto();
267 uint16_t if_id = intf_id_;
283 pkt->AddEthHdr(
"00:00:00:00:00:01",
"00:00:00:00:00:02", 0x800);
284 pkt->AddAgentHdr(if_id, GetTrapCode(), hash_id_, vrf_id_, label_, vxlan_id);
286 ret = InetPacket(intf, agent, pkt);
288 ret = Inet6Packet(intf, agent, pkt);
325 cout <<
"Generate packet" << endl;
330 uint8_t *ptr(
new uint8_t[pkt.GetBuffLen()]);
331 memcpy(ptr, pkt.GetBuff(), pkt.GetBuffLen());
333 TestPkt0Interface *pkt0 =
static_cast<TestPkt0Interface *
>
335 pkt0->ProcessFlowPacket(ptr, pkt.GetBuffLen(), pkt.GetBuffLen());
343 const xml_node &node) :
399 cout <<
"Generating packet" << endl;
404 uint32_t buff_len = pkt.GetBuffLen();
405 uint32_t payload_len = pkt.GetBuffLen();
406 uint8_t *ptr(
new uint8_t[buff_len]);
407 memcpy(ptr, pkt.GetBuff(), pkt.GetBuffLen());
423 sizeof(
struct agent_hdr)));
boost::asio::ip::address IpAddress
const pugi::xml_node & node() const
TunnelType::Type GetTunnelType() const
bool ReadXml(const pugi::xml_node &node)
bool InetPacket(Interface *intf, Agent *agent, PktGen *pkt)
virtual ~AgentUtXmlPacketUtils()
PktHandler::PktModuleName GetPacketModule() const
uint8_t GetTrapCode() const
bool MakePacket(Agent *agent, PktGen *pkt)
bool Inet6Packet(Interface *intf, Agent *agent, PktGen *pkt)
uint8_t GetIpProto() const
AgentUtXmlPacketUtils pkt_
virtual std::string NodeType()
virtual void ToString(std::string *str)
AgentUtXmlPacket(const std::string &name, const pugi::xml_node &node, AgentUtXmlTestCase *test_case)
virtual ~AgentUtXmlPacket()
virtual bool ToXml(pugi::xml_node *parent)
virtual const std::string ToString()
AgentUtXmlPacketUtils pkt_
AgentUtXmlPktParseValidate(const std::string &name, const pugi::xml_node &node)
virtual ~AgentUtXmlPktParseValidate()
const pugi::xml_node & node() const
static const MacAddress & vrrp_mac()
static Agent * GetInstance()
const Interface * vhost_interface() const
const MacAddress & mac() const
uint32_t l2_label() const
const uint32_t id() const
std::string ToString() const
static MacAddress FromString(const std::string &str, boost::system::error_code *error=NULL)
PacketBufferPtr Allocate(uint32_t module, uint16_t len, uint32_t mdata)
PktModuleName ParsePacket(const AgentHdr &hdr, PktInfo *pkt_info, uint8_t *pkt)
PacketBufferManager * packet_buffer_manager() const
PktHandler * pkt_handler() const
ControlInterface * control_interface() const
VmInterface::VmiType vmi_type() const
const VnEntry * vn() const
const Ip4Address & primary_ip_addr() const
InterfaceList parent_list() const
int DecodeAgentHdr(AgentHdr *hdr, uint8_t *buff, uint32_t len)
bool GetUintAttribute(const xml_node &node, const string &name, uint16_t *value)
bool GetStringAttribute(const xml_node &node, const string &name, string *value)
boost::shared_ptr< PacketBuffer > PacketBufferPtr
static int GetVxlan(Interface *intf)