Skip to content

Commit

Permalink
Merge "Sctp flow handling changes for agent . Unit Test ." into R2.20
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed Nov 5, 2015
2 parents 096a96c + bb0e0ad commit 5b983b0
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/vnsw/agent/pkt/pkt_handler.cc
Expand Up @@ -352,6 +352,16 @@ int PktHandler::ParseIpPacket(PktInfo *pkt_info, PktType::Type &pkt_type,
break;
}

case IPPROTO_SCTP : {
pkt_info->transp.sctp = (sctphdr *) (pkt + len);
len += sizeof(sctphdr);
pkt_info->data = (pkt + len);
pkt_info->dport = ntohs(pkt_info->transp.sctp->th_dport);
pkt_info->sport = ntohs(pkt_info->transp.sctp->th_sport);
pkt_type = PktType::SCTP;
break;
}

case IPPROTO_ICMP: {
pkt_info->transp.icmp = (struct icmp *) (pkt + len);
pkt_type = PktType::ICMP;
Expand Down
10 changes: 9 additions & 1 deletion src/vnsw/agent/pkt/pkt_handler.h
Expand Up @@ -87,10 +87,17 @@ struct PktType {
ICMP,
ICMPV6,
NON_IP,
MESSAGE
MESSAGE,
SCTP
};
};

struct sctphdr {
u_int16_t th_sport;
u_int16_t th_dport;
u_int32_t vtag;
};

struct AgentHdr {
// Packet commands between agent and vrouter. The values must be in-sync
// with vrouter/include/vr_defs.h
Expand Down Expand Up @@ -200,6 +207,7 @@ struct PktInfo {
struct udphdr *udp;
struct icmp *icmp;
struct icmp6_hdr *icmp6;
struct sctphdr *sctp;
} transp;

PktInfo(Agent *agent, uint32_t buff_len, uint32_t module, uint32_t mdata);
Expand Down
15 changes: 14 additions & 1 deletion src/vnsw/agent/pkt/test/test_pkt_parse.cc
Expand Up @@ -312,6 +312,11 @@ static bool ValidateIpPktInfo(PktInfo *pkt_info, const char *sip,
if (pkt_info->type != PktType::ICMP) {
ret = false;
}
} else if (proto == IPPROTO_SCTP) {
EXPECT_EQ(pkt_info->type, PktType::SCTP);
if (pkt_info->type != PktType::SCTP) {
ret = false;
}
} else {
EXPECT_EQ(pkt_info->type, PktType::IP);
if (pkt_info->type != PktType::IP) {
Expand Down Expand Up @@ -426,10 +431,18 @@ TEST_F(PktParseTest, IP_On_Vnet_1) {
1, 2));

pkt->Reset();
MakeIpPacket(pkt.get(), vnet1->id(), "1.1.1.1", "1.1.1.2", 1, 1, -1, -1, true);
MakeSctpPacket(pkt.get(), vnet1->id(), "1.1.1.1", "1.1.1.2", 1, 2, 3, -1);
PktInfo pkt_info4(Agent::GetInstance(), 100, 0, 0);
TestPkt(&pkt_info4, pkt.get());
client->WaitForIdle();
EXPECT_TRUE(ValidateIpPktInfo(&pkt_info4, "1.1.1.1", "1.1.1.2", IPPROTO_SCTP,
1, 2));

pkt->Reset();
MakeIpPacket(pkt.get(), vnet1->id(), "1.1.1.1", "1.1.1.2", 1, 1, -1, -1, true);
PktInfo pkt_info5(Agent::GetInstance(), 100, PktHandler::FLOW, 0);
TestPkt(&pkt_info5, pkt.get());
client->WaitForIdle();
EXPECT_TRUE(ValidateIpPktInfo(&pkt_info1, "1.1.1.1", "1.1.1.2", 1, 0, 0));
EXPECT_EQ(Agent::GetInstance()->stats()->pkt_fragments_dropped(), 1);

Expand Down
10 changes: 10 additions & 0 deletions src/vnsw/agent/pkt/test/test_pkt_util.cc
Expand Up @@ -89,6 +89,16 @@ void TxUdpPacket(int ifindex, const char *sip, const char *dip,
delete pkt;
}

void MakeSctpPacket(PktGen *pkt, int ifindex, const char *sip,
const char *dip, uint16_t sport, uint16_t dport,
int hash_id, uint32_t vrf_id) {
pkt->AddEthHdr("00:00:00:00:00:01", "00:00:00:00:00:02", 0x800);
pkt->AddAgentHdr(ifindex, AgentHdr::TRAP_FLOW_MISS, hash_id, vrf_id);
pkt->AddEthHdr("00:00:5E:00:01:00", "00:00:00:00:00:01", 0x800);
pkt->AddIpHdr(sip, dip, IPPROTO_SCTP);
pkt->AddSctpHdr(sport, dport, 64);
}

void MakeTcpPacket(PktGen *pkt, int ifindex, const char *sip,
const char *dip, uint16_t sport, uint16_t dport, bool ack,
int hash_id, uint32_t vrf_id) {
Expand Down
5 changes: 5 additions & 0 deletions src/vnsw/agent/pkt/test/test_pkt_util.h
Expand Up @@ -32,6 +32,11 @@ extern void TxUdpPacket(int ifindex, const char *sip, const char *dip,
extern void MakeTcpPacket(PktGen *pkt, int ifindex, const char *sip,
const char *dip, uint16_t sport, uint16_t dport,
bool ack, int hash_id, uint32_t vrf_id);

extern void MakeSctpPacket(PktGen *pkt, int ifindex, const char *sip,
const char *dip, uint16_t sport, uint16_t dport,
int hash_id, uint32_t vrf_id);

extern void TxTcpPacket(int ifindex, const char *sip, const char *dip,
uint16_t sport, uint16_t dport, bool ack, int hash_id = 1,
uint32_t vrf_id = -1);
Expand Down
7 changes: 7 additions & 0 deletions src/vnsw/agent/test/pkt_gen.h
Expand Up @@ -338,6 +338,13 @@ class PktGen {
len += sizeof(tcphdr) + plen;
};

void AddSctpHdr(uint16_t sport, uint16_t dport, int plen) {
struct sctphdr *sctp = (struct sctphdr *)(buff + len);
sctp -> th_dport = htons(dport);
sctp -> th_sport = htons(sport);
len += sizeof(sctphdr) + plen;
};

void AddIcmpHdr() {
struct icmp *icmp = (struct icmp *)(buff + len);
icmp->icmp_type = 0;
Expand Down

0 comments on commit 5b983b0

Please sign in to comment.