From patchwork Sat Oct 10 04:15:23 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Pfaff X-Patchwork-Id: 528522 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (li376-54.members.linode.com [96.126.127.54]) by ozlabs.org (Postfix) with ESMTP id 715D8140E3D for ; Sat, 10 Oct 2015 15:16:06 +1100 (AEDT) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id 5335210AE7; Fri, 9 Oct 2015 21:15:55 -0700 (PDT) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx3v1.cudamail.com (mx3.cudamail.com [64.34.241.5]) by archives.nicira.com (Postfix) with ESMTPS id 0CA6F10ADD for ; Fri, 9 Oct 2015 21:15:54 -0700 (PDT) Received: from bar3.cudamail.com (bar1 [192.168.15.1]) by mx3v1.cudamail.com (Postfix) with ESMTP id 89E2A619817 for ; Fri, 9 Oct 2015 22:15:53 -0600 (MDT) X-ASG-Debug-ID: 1444450553-03dd7b7d40115660001-byXFYA Received: from mx3-pf2.cudamail.com ([192.168.14.1]) by bar3.cudamail.com with ESMTP id 8DSiaKcAfh0bbvVw (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 09 Oct 2015 22:15:53 -0600 (MDT) X-Barracuda-Envelope-From: blp@nicira.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.14.1 Received: from unknown (HELO mail-pa0-f53.google.com) (209.85.220.53) by mx3-pf2.cudamail.com with ESMTPS (RC4-SHA encrypted); 10 Oct 2015 04:15:52 -0000 Received-SPF: unknown (mx3-pf2.cudamail.com: Multiple SPF records returned) X-Barracuda-RBL-Trusted-Forwarder: 209.85.220.53 Received: by pacex6 with SMTP id ex6so104164895pac.0 for ; Fri, 09 Oct 2015 21:15:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=BnPwem8flifaCHVaJ89ZbMTFWcWcCbvR7rKaCa0eJxo=; b=PUN32wGkWCfwwgPbuclZIgQxRW5sJzM3c/OX23ie3ORYeqrhITArnophDzVINT5PAE UMitM+RhIR82k1dQaoRY5oADxeBlZuuCOcqSqjg6EuWGvVIiRCTzK5zj5/xp0s/m5Wci MYju3LhY7TeQ2HRuiLngpYZZKCniyCoLbL+tEzbLq7mOq9EQWOH3GZSq+cNeFuFANwTD xiAPFA2dOh+4NKn2+ih6Ki5ViA78mVZasGYwCCFGojwIgZzqTjFoPW86TdxuQ1xQ23O4 zX77jgRKoJ4CwVQiCUivGAUzO9zV6bPjVJVqyzK+1BQLtv5QIRMoeySe+fB6B1jp9mHp cehw== X-Gm-Message-State: ALoCoQlY2aiD9BqhjfeP/uLzgRDX7cfpA1ASUKE8Is53JTMA04OKfJLPAMOJmTKjh5wi7JCnguTM X-Received: by 10.66.230.169 with SMTP id sz9mr19781568pac.136.1444450552356; Fri, 09 Oct 2015 21:15:52 -0700 (PDT) Received: from sigabrt.gateway.sonic.net (173-228-112-112.dsl.dynamic.fusionbroadband.com. [173.228.112.112]) by smtp.gmail.com with ESMTPSA id bk8sm5386937pad.18.2015.10.09.21.15.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 09 Oct 2015 21:15:51 -0700 (PDT) X-CudaMail-Envelope-Sender: blp@nicira.com X-Barracuda-Apparent-Source-IP: 173.228.112.112 From: Ben Pfaff To: dev@openvswitch.org X-CudaMail-Whitelist-To: dev@openvswitch.org X-CudaMail-MID: CM-V2-1008076601 X-CudaMail-DTE: 100915 X-CudaMail-Originating-IP: 209.85.220.53 Date: Fri, 9 Oct 2015 21:15:23 -0700 X-ASG-Orig-Subj: [##CM-V2-1008076601##][PATCH 02/23] ovn: Implement logical action to decrement IPv4 TTL. Message-Id: <1444450544-11845-3-git-send-email-blp@nicira.com> X-Mailer: git-send-email 2.1.3 In-Reply-To: <1444450544-11845-1-git-send-email-blp@nicira.com> References: <1444450544-11845-1-git-send-email-blp@nicira.com> X-Barracuda-Connect: UNKNOWN[192.168.14.1] X-Barracuda-Start-Time: 1444450553 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-ASG-Whitelist: Header =?UTF-8?B?eFwtY3VkYW1haWxcLXdoaXRlbGlzdFwtdG8=?= X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 Cc: Ben Pfaff Subject: [ovs-dev] [PATCH 02/23] ovn: Implement logical action to decrement IPv4 TTL. X-BeenThere: dev@openvswitch.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dev-bounces@openvswitch.org Sender: "dev" This is necessary for IPv4 routing. Signed-off-by: Ben Pfaff Acked-by: Justin Pettit --- ovn/lib/actions.c | 9 +++++++++ ovn/lib/lex.c | 13 +++++++++++++ ovn/lib/lex.h | 1 + tests/ovn.at | 6 +++++- 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/ovn/lib/actions.c b/ovn/lib/actions.c index 2bc495c..0874174 100644 --- a/ovn/lib/actions.c +++ b/ovn/lib/actions.c @@ -205,6 +205,15 @@ parse_actions(struct action_context *ctx) parse_next_action(ctx); } else if (lexer_match_id(ctx->lexer, "output")) { emit_resubmit(ctx, ctx->output_table); + } else if (lexer_match_id(ctx->lexer, "ip4.ttl")) { + if (lexer_match(ctx->lexer, LEX_T_DECREMENT)) { + struct expr *e = expr_parse_string("ip4", ctx->symtab, + &ctx->error); + ctx->prereqs = expr_combine(EXPR_T_AND, ctx->prereqs, e); + ofpact_put_DEC_TTL(ctx->ofpacts); + } else { + action_syntax_error(ctx, "expecting `--'"); + } } else { action_syntax_error(ctx, "expecting action"); } diff --git a/ovn/lib/lex.c b/ovn/lib/lex.c index 308d216..cc8eb28 100644 --- a/ovn/lib/lex.c +++ b/ovn/lib/lex.c @@ -241,6 +241,9 @@ lex_token_format(const struct lex_token *token, struct ds *s) case LEX_T_EXCHANGE: ds_put_cstr(s, "<->"); break; + case LEX_T_DECREMENT: + ds_put_cstr(s, "--"); + break; default: OVS_NOT_REACHED(); } @@ -640,6 +643,16 @@ next: token->type = LEX_T_SEMICOLON; break; + case '-': + p++; + if (*p == '-') { + token->type = LEX_T_DECREMENT; + p++; + } else { + lex_error(token, "`-' is only valid as part of `--'."); + } + break; + case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case ':': diff --git a/ovn/lib/lex.h b/ovn/lib/lex.h index 7ad6f55..3c2bb6a 100644 --- a/ovn/lib/lex.h +++ b/ovn/lib/lex.h @@ -59,6 +59,7 @@ enum lex_type { LEX_T_SEMICOLON, /* ; */ LEX_T_EQUALS, /* = */ LEX_T_EXCHANGE, /* <-> */ + LEX_T_DECREMENT, /* -- */ }; /* Subtype for LEX_T_INTEGER and LEX_T_MASKED_INTEGER tokens. diff --git a/tests/ovn.at b/tests/ovn.at index 330f723..095b0d9 100644 --- a/tests/ovn.at +++ b/tests/ovn.at @@ -82,9 +82,10 @@ fe:x => error("Invalid numeric constant.") 00:01:02:03:04:x => error("Invalid numeric constant.") # Test that operators are tokenized as expected, even without white space. -(){}[[]]==!=<<=>>=!&&||..,;=<-> => ( ) { } [[ ]] == != < <= > >= ! && || .. , ; = <-> +(){}[[]]==!=<<=>>=!&&||..,;=<->-- => ( ) { } [[ ]] == != < <= > >= ! && || .. , ; = <-> -- & => error("`&' is only valid as part of `&&'.") | => error("`|' is only valid as part of `||'.") +- => error("`-' is only valid as part of `--'.") ^ => error("Invalid character `^' in input.") ]) @@ -455,6 +456,8 @@ reg0 <-> reg1; => actions=push:OXM_OF_PKT_REG0[0..31],push:OXM_OF_PKT_REG0[32..6 vlan.pcp <-> reg0[0..2]; => actions=push:OXM_OF_PKT_REG0[32..34],push:NXM_OF_VLAN_TCI[13..15],pop:OXM_OF_PKT_REG0[32..34],pop:NXM_OF_VLAN_TCI[13..15], prereqs=vlan.tci[12] reg0[10] <-> vlan.pcp[1]; => actions=push:NXM_OF_VLAN_TCI[14],push:OXM_OF_PKT_REG0[42],pop:NXM_OF_VLAN_TCI[14],pop:OXM_OF_PKT_REG0[42], prereqs=vlan.tci[12] outport <-> inport; => actions=push:NXM_NX_REG6[],push:NXM_NX_REG7[],pop:NXM_NX_REG6[],pop:NXM_NX_REG7[], prereqs=1 +ip4.ttl--; => actions=dec_ttl, prereqs=ip4 + # Contradictionary prerequisites (allowed but not useful): ip4.src = ip6.src[0..31]; => actions=move:NXM_NX_IPV6_SRC[0..31]->NXM_OF_IP_SRC[], prereqs=eth.type == 0x800 && eth.type == 0x86dd ip4.src <-> ip6.src[0..31]; => actions=push:NXM_NX_IPV6_SRC[0..31],push:NXM_OF_IP_SRC[],pop:NXM_NX_IPV6_SRC[0..31],pop:NXM_OF_IP_SRC[], prereqs=eth.type == 0x800 && eth.type == 0x86dd @@ -498,6 +501,7 @@ inport <-> reg0; => Can't exchange string field (inport) with integer field (reg inport <-> big_string; => String fields inport and big_string are incompatible for exchange. ip.proto <-> reg0[0..7]; => Field ip.proto is not modifiable. reg0[0..7] <-> ip.proto; => Field ip.proto is not modifiable. +ip4.ttl => Syntax error at end of input expecting `--'. ]]) sed 's/ =>.*//' test-cases.txt > input.txt sed 's/.* => //' test-cases.txt > expout