7 #include <pugixml/pugixml.hpp>
8 #include <boost/uuid/uuid.hpp>
9 #include <boost/uuid/string_generator.hpp>
11 #include <test/test_cmn_util.h>
12 #include <pkt/test/test_pkt_util.h>
23 using namespace boost::uuids;
24 using namespace AgentUtXmlUtils;
40 tunnel_sip_ =
"0.0.0.0";
41 tunnel_dip_ =
"0.0.0.0";
45 smac_ =
"00:00:00:00:00:01";
46 dmac_ =
"00:00:00:00:00:02";
64 if (tunnel_type_ ==
"gre" || tunnel_type_ ==
"GRE")
66 if (tunnel_type_ ==
"udp" || tunnel_type_ ==
"UDP")
68 if (tunnel_type_ ==
"vxlan" || tunnel_type_ ==
"VXLAN")
81 return atoi(proto_.c_str());
85 if (trap_code_ ==
"flow")
93 if (pkt_module_ ==
"flow" || pkt_module_ ==
"FLOW")
95 if (pkt_module_ ==
"invalid" || pkt_module_ ==
"INVALID")
103 if (fwd_mode_ ==
"l2" || fwd_mode_ ==
"L2")
109 if (fwd_mode_ ==
"l3" || fwd_mode_ ==
"L3")
119 if (tunnel_type_ !=
"") {
149 if (tunnel_type_ ==
"") {
150 s <<
"Packet < " << name_ <<
"> Interface <" << intf_ <<
"> ";
152 s <<
"Packet < " << name_ <<
"> Tunnel <" << tunnel_type_ <<
" : "
153 << intf_ <<
" : " << label_ <<
" : " << tunnel_sip_ <<
" : "
154 << tunnel_dip_ <<
"> ";
156 s <<
"<" << sip_ <<
" : " << dip_ <<
" : " << proto_ <<
" : " << sport_
157 <<
" : " << dport_ <<
">" << endl;
176 pkt->AddEthHdr(
"00:00:00:00:00:01",
"00:00:00:00:00:02", 0x800);
179 string dip = tunnel_dip_;
180 if (dip ==
"0.0.0.0") {
184 uint8_t proto = IPPROTO_UDP;
188 pkt->AddIpHdr(tunnel_sip_.c_str(), dip.c_str(), proto);
191 pkt->AddMplsHdr(label_,
true);
193 pkt->AddUdpHdr(VR_MPLS_OVER_UDP_SRC_PORT, VR_MPLS_OVER_UDP_DST_PORT,
195 pkt->AddMplsHdr(label_,
true);
197 pkt->AddUdpHdr(VR_VXLAN_UDP_SRC_PORT, VR_VXLAN_UDP_DST_PORT, 0);
199 pkt->AddVxlanHdr(vxlan);
202 if (fwd_mode_ ==
"l2") {
203 pkt->AddEthHdr(dmac_.c_str(), smac_.c_str(), 0x800);
206 pkt->AddEthHdr(dmac_.c_str(), smac_.c_str(), 0x800);
209 pkt->AddIpHdr(sip_.c_str(), dip_.c_str(), proto_id_);
210 if (proto_id_ == 17) {
211 pkt->AddUdpHdr(sport_, dport_, len_);
212 }
else if (proto_id_ == 6) {
213 pkt->AddTcpHdr(sport_, dport_,
false,
false, tcp_ack_, len_);
214 }
else if (proto_id_ == 1) {
230 boost::system::error_code ec;
231 IpAddress ip = IpAddress::from_string(sip_, ec);
233 bool ingress_flow =
true;
236 ingress_flow =
false;
240 if (atoi(intf_.c_str())) {
241 intf =
static_cast<VmInterface *
>(VmPortGet(atoi(intf_.c_str())));
243 intf_id_ = intf->
id();
251 label_ = intf->
label();
255 if (fwd_mode_ !=
"l2") {
262 if (proto_id_ == 0) {
263 proto_id_ = GetIpProto();
266 uint16_t if_id = intf_id_;
282 pkt->AddEthHdr(
"00:00:00:00:00:01",
"00:00:00:00:00:02", 0x800);
283 pkt->AddAgentHdr(if_id, GetTrapCode(), hash_id_, vrf_id_, label_, vxlan_id);
285 ret = InetPacket(intf, agent, pkt);
287 ret = Inet6Packet(intf, agent, pkt);
324 cout <<
"Generate packet" << endl;
329 uint8_t *ptr(
new uint8_t[pkt.GetBuffLen()]);
330 memcpy(ptr, pkt.GetBuff(), pkt.GetBuffLen());
332 TestPkt0Interface *pkt0 =
static_cast<TestPkt0Interface *
>
334 pkt0->ProcessFlowPacket(ptr, pkt.GetBuffLen(), pkt.GetBuffLen());
342 const xml_node &node) :
398 cout <<
"Generating packet" << endl;
403 uint32_t buff_len = pkt.GetBuffLen();
404 uint32_t payload_len = pkt.GetBuffLen();
405 uint8_t *ptr(
new uint8_t[buff_len]);
406 memcpy(ptr, pkt.GetBuff(), pkt.GetBuffLen());
422 sizeof(
struct agent_hdr)));
boost::shared_ptr< PacketBuffer > PacketBufferPtr
static Agent * GetInstance()
const uint32_t id() const
bool Inet6Packet(Interface *intf, Agent *agent, PktGen *pkt)
const Interface * vhost_interface() const
boost::asio::ip::address IpAddress
static const MacAddress & vrrp_mac()
virtual void ToString(std::string *str)
AgentUtXmlPktParseValidate(const std::string &name, const pugi::xml_node &node)
virtual std::string NodeType()
ControlInterface * control_interface() const
const MacAddress & mac() const
std::string ToString() const
virtual ~AgentUtXmlPacketUtils()
PktHandler::PktModuleName GetPacketModule() const
uint8_t GetIpProto() const
AgentUtXmlPacket(const std::string &name, const pugi::xml_node &node, AgentUtXmlTestCase *test_case)
virtual const std::string ToString()
AgentUtXmlPacketUtils pkt_
bool MakePacket(Agent *agent, PktGen *pkt)
AgentUtXmlPacketUtils pkt_
bool GetStringAttribute(const xml_node &node, const string &name, string *value)
PktHandler * pkt_handler() const
const VnEntry * vn() const
PktModuleName ParsePacket(const AgentHdr &hdr, PktInfo *pkt_info, uint8_t *pkt)
static int GetVxlan(Interface *intf)
bool InetPacket(Interface *intf, Agent *agent, PktGen *pkt)
const Ip4Address & primary_ip_addr() const
uint8_t GetTrapCode() const
PacketBufferManager * packet_buffer_manager() const
bool GetUintAttribute(const xml_node &node, const string &name, uint16_t *value)
VmInterface::VmiType vmi_type() const
bool ReadXml(const pugi::xml_node &node)
virtual ~AgentUtXmlPktParseValidate()
uint32_t l2_label() const
virtual bool ToXml(pugi::xml_node *parent)
PacketBufferPtr Allocate(uint32_t module, uint16_t len, uint32_t mdata)
const pugi::xml_node & node() const
TunnelType::Type GetTunnelType() const
static MacAddress FromString(const std::string &str, boost::system::error_code *error=NULL)
virtual ~AgentUtXmlPacket()
InterfaceList parent_list() const
const pugi::xml_node & node() const
int DecodeAgentHdr(AgentHdr *hdr, uint8_t *buff, uint32_t len)