From 75edc57072ef26c9920574f4ba57246d5749efc8 Mon Sep 17 00:00:00 2001 From: Mikio Hara Date: Fri, 11 Dec 2009 15:21:54 -0800 Subject: [PATCH] IPv4 DSCP match: Add IPv4 ToS/DSCP description capability to dpctl --- lib/ofp-print.c | 8 ++++---- utilities/dpctl.8.in | 5 +++++ utilities/dpctl.c | 7 ++++--- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/ofp-print.c b/lib/ofp-print.c index a859723..c8198c9 100644 --- a/lib/ofp-print.c +++ b/lib/ofp-print.c @@ -303,7 +303,7 @@ ofp_print_action(struct ds *string, const struct ofp_action_header *ah, return -1; } } - + switch (type) { case OFPAT_OUTPUT: { struct ofp_action_output *oa = (struct ofp_action_output *)ah; @@ -350,7 +350,7 @@ ofp_print_action(struct ds *string, const struct ofp_action_header *ah, case OFPAT_SET_DL_SRC: { struct ofp_action_dl_addr *da = (struct ofp_action_dl_addr *)ah; - ds_put_format(string, "mod_dl_src:"ETH_ADDR_FMT, + ds_put_format(string, "mod_dl_src:"ETH_ADDR_FMT, ETH_ADDR_ARGS(da->dl_addr)); break; } @@ -376,7 +376,7 @@ ofp_print_action(struct ds *string, const struct ofp_action_header *ah, case OFPAT_SET_NW_TOS: { struct ofp_action_nw_tos *nt = (struct ofp_action_nw_tos *)ah; - ds_put_format(string, "mod_ip_tos:%d", nt->nw_tos); + ds_put_format(string, "mod_nw_tos:0x%"PRIx8, nt->nw_tos); break; } @@ -715,7 +715,7 @@ ofp_match_to_string(const struct ofp_match *om, int verbosity) print_ip_netmask(&f, "nw_dst=", om->nw_dst, (w & OFPFW_NW_DST_MASK) >> OFPFW_NW_DST_SHIFT, verbosity); print_wild(&f, "nw_tos=", w & OFPFW_NW_TOS, verbosity, - "%u", om->nw_tos); + "0x%02x", om->nw_tos); if (!skip_proto) { print_wild(&f, "nw_proto=", w & OFPFW_NW_PROTO, verbosity, "%u", om->nw_proto); diff --git a/utilities/dpctl.8.in b/utilities/dpctl.8.in index 36d5294..909faa8 100644 --- a/utilities/dpctl.8.in +++ b/utilities/dpctl.8.in @@ -301,6 +301,11 @@ Matches IP protocol type \fIproto\fR, which should be specified as a decimal number between 0 and 255, inclusive, e.g. 6 to match TCP packets. +.IP \fBnw_tos=\fItos/dscp\fR +Matches ToS/DSCP (only 6-bits, not modify reserved 2-bits for future +use) field of IPv4 header \fItos/dscp\fR, which should be specified as +a decimal number between 0 and 255, inclusive. + .IP \fBtp_src=\fIport\fR Matches UDP or TCP source port \fIport\fR, which should be specified as a decimal number between 0 and 65535, inclusive, e.g. 80 to match diff --git a/utilities/dpctl.c b/utilities/dpctl.c index 4694b5e..0406d9b 100644 --- a/utilities/dpctl.c +++ b/utilities/dpctl.c @@ -951,21 +951,22 @@ struct field { }; static bool -parse_field(const char *name, const struct field **f_out) +parse_field(const char *name, const struct field **f_out) { #define F_OFS(MEMBER) offsetof(struct ofp_match, MEMBER) - static const struct field fields[] = { + static const struct field fields[] = { { "in_port", OFPFW_IN_PORT, F_U16, F_OFS(in_port), 0 }, { "dl_vlan", OFPFW_DL_VLAN, F_U16, F_OFS(dl_vlan), 0 }, { "dl_vlan_pcp", OFPFW_DL_VLAN_PCP, F_U8, F_OFS(dl_vlan_pcp), 0 }, { "dl_src", OFPFW_DL_SRC, F_MAC, F_OFS(dl_src), 0 }, { "dl_dst", OFPFW_DL_DST, F_MAC, F_OFS(dl_dst), 0 }, { "dl_type", OFPFW_DL_TYPE, F_U16, F_OFS(dl_type), 0 }, + { "nw_tos", OFPFW_NW_TOS, F_U8, F_OFS(nw_tos), 0 }, + { "nw_proto", OFPFW_NW_PROTO, F_U8, F_OFS(nw_proto), 0 }, { "nw_src", OFPFW_NW_SRC_MASK, F_IP, F_OFS(nw_src), OFPFW_NW_SRC_SHIFT }, { "nw_dst", OFPFW_NW_DST_MASK, F_IP, F_OFS(nw_dst), OFPFW_NW_DST_SHIFT }, - { "nw_proto", OFPFW_NW_PROTO, F_U8, F_OFS(nw_proto), 0 }, { "tp_src", OFPFW_TP_SRC, F_U16, F_OFS(tp_src), 0 }, { "tp_dst", OFPFW_TP_DST, F_U16, F_OFS(tp_dst), 0 }, { "icmp_type", OFPFW_ICMP_TYPE, F_U16, F_OFS(icmp_type), 0 },