Srinivas Pinisetty

Yliès Falcone
email: ylies.falcone@ujf-grenoble.fr

Thierry Jéron

Hervé Marchand

Antoine Rollet
email: antoine.rollet@labri.fr

Omer Nguena Timo

Runtime Enforcement of Timed Properties

Runtime enforcement is a powerful technique to ensure that a running system respects some desired properties. Using an enforcement monitor, an (untrustworthy) input execution (in the form of a sequence of events) is modified into an output sequence that complies to a property. Runtime enforcement has been extensively studied over the last decade in the context of untimed properties. This paper introduces runtime enforcement of timed properties. We revisit the foundations of runtime enforcement when time between events matters. We show how runtime enforcers can be synthesized for any safety or co-safety timed property. Proposed runtime enforcers are time retardant: to produce an output sequence, additional delays are introduced between the events of the input sequence to correct it. Runtime enforcers have been prototyped and our simulation experiments validate their effectiveness.

Introduction

Runtime verification [START_REF] Thati | Monitoring algorithms for metric temporal logic specifications[END_REF][START_REF] Chen | Parametric trace slicing and monitoring[END_REF][START_REF] Nickovic | From MTL to deterministic timed automata[END_REF][START_REF] Bauer | Runtime verification for LTL and TLTL[END_REF][START_REF] Basin | Algorithms for monitoring real-time properties[END_REF][START_REF] Barringer | Quantified Event Automata: Towards Expressive and Efficient Runtime Monitors[END_REF] (resp. enforcement [START_REF] Schneider | Enforceable security policies[END_REF][START_REF] Ligatti | Run-time enforcement of nonsafety policies[END_REF][START_REF] Falcone | You should better enforce than verify[END_REF]) refers to the theories, techniques, and tools aiming at checking (resp. ensuring) the conformance of the executions of systems under scrutiny w.r.t. some desired property. The first step of those monitoring approaches consists in instrumenting the underlying system so as to partially observe the events or the parts of its global state that may influence the property under scrutiny. A central concept is the verification or enforcement monitor that is generally synthesized from the property expressed in a high-level formalism. Then, the monitor can operate either online by receiving events in a lock-step manner with the execution of the system or offline by reading a log of system events. When the monitor is only dedicated to verification, it is a decision procedure emitting verdicts stating the correctness of the (partial) observed trace generated from the system execution.

Three categories of runtime verification frameworks can be distinguished according to the formalism used to express the input property. In propositional approaches, properties refer to events taken from a finite set of propositional names. For instance, a propositional specification may rule the ordering of function calls in a program. Monitoring such kind of specifications has received a lot of attention. Parametric approaches have received a growing interest in the last five years. Here, events are augmented with formal parameters, instantiated at runtime. In timed approaches, the observed time between events may influence the truth-value of the property. It turns out that monitoring of (continuous) time specifications is a much harder problem. Intuitively, when monitoring a timed specification, the problem that arises is that the overhead induced by the monitor (i.e., the time spent executing monitor's code) influences the truth-value of the monitored specification. Consequently, not much information can be gained from the verdicts produced by the monitor. Few attempts have been made on monitoring systems w.r.t. timed properties (see Sec. 8 for related work). Two lines of work can be distinguished: synthesis of automata-based decision procedures for timed formalisms (e.g., [START_REF] Thati | Monitoring algorithms for metric temporal logic specifications[END_REF][START_REF] Nickovic | From MTL to deterministic timed automata[END_REF][START_REF] Bauer | Runtime verification for LTL and TLTL[END_REF][START_REF] Basin | Algorithms for monitoring real-time properties[END_REF]), and, tools for runtime verification of timed properties [START_REF] Nickovic | AMT: A property-based monitoring tool for analog systems[END_REF][START_REF] Colombo | LARVA -safer monitoring of real-time java programs (tool paper)[END_REF].

In runtime enforcement, an enforcement monitor (EM) is used to transform some (possibly) incorrect execution sequence into a correct sequence w.r.t. the property of interest. In the propositional case, the transformation performed by an EM should be sound and transparent. Soundness means that the resulting sequence obeys the property. Transparency means that, if the input sequence already conforms to the property, the monitor has to modify it in a minimal way. According to how a monitor is allowed to modify the input sequence (i.e., the primitives afforded to the monitor), several models of enforcement monitors have been proposed [START_REF] Schneider | Enforceable security policies[END_REF][START_REF] Ligatti | Run-time enforcement of nonsafety policies[END_REF][START_REF] Falcone | You should better enforce than verify[END_REF]. In a nutshell, an EM can definitely block the input sequence (as done by security automata), suppress an event from the input sequence (as done by suppression automata), insert an event to the input sequence (as done by insertion automata), or perform any of these primitives (as is the case with edit-automata). Moreover, according to how transparency is effectively formalized, several definitions of runtime enforcement have been proposed (see [START_REF] Falcone | You should better enforce than verify[END_REF] for an overview).

In this paper we focus on online enforcement of timed properties. To the best of our knowledge, no approach was proposed to enforce timed properties. Motivations for extending runtime enforcement to timed properties abound. First, timed properties are a more precise tool to specify desired behaviors of systems since they allow to explicitly state how time should elapse between two events. Moreover, several applications of runtime enforcement of timed properties can be considered. For instance, in the context of security monitoring, enforcement monitors can be used as firewalls to prevent denial of service attacks by ensuring a minimal delay between input events (carrying some request for a protected server). On a network, enforcement monitors can be used to synchronize streams of events together, or, ensuring that a stream of events conforms to the pre-conditions of some service.

Contributions. We propose a context where, under some reasonable assumptions, runtime enforcement of timed properties is possible. For this purpose, we adapt soundness and transparency to a timed context. Runtime enforcement monitors are built from safety and co-safety properties expressed by timed automata. In contrast with previous runtime enforcement approaches, we afford only the primitives of being able to delay the input events to our enforcer. By possibly increasing delays between events of the input sequence, the output timed sequence conforms to the property. Delays are modified by monitors using an internal memory where (sequence of) events are stored and released after appropriate delays. Experiments have been performed on prototype monitors to show their effectiveness and the feasibility of our approach.

Paper organization. Section 2 introduces preliminaries and notation. Section 3 introduces the notion of enforcement for timed properties. Sections 4 and 5 describe how one can enforce safety and co-safety properties, respectively. Our prototype implementations of monitors and experiments are in Sec. 6 and Sec. 7, respectively. Section 8 discusses related work. Finally, conclusions and open perspectives are drawn in Sec. 9.

Preliminaries and Notation

Untimed notions. An alphabet is a finite set of elements. A (finite) word over an alphabet A is a finite sequence of elements of A. The length of a word w is noted |w|. The empty word over A is denoted by A or when clear from context.The set of all (resp. nonempty) words over A is denoted by A * (resp. A + ). A language over A is a subset L ⊆ A * . The concatenation of two words w and w is noted w • w . For an interval [j, k] in N, by i∈[j,k] (a i ) we denote the concatenation a j •a j+1 • • • a k . A word w is a prefix of a word w, noted w w, whenever there exists a word w such that w = w • w . For a word w and 1 ≤ i ≤ |w|, the i-th letter (resp. prefix of length i, suffix starting at

position i) of w is noted w(i) (resp. w [•••i] , w [i••• ] ) -with the convention w [•••0] def = .
pref(w) denotes the set of prefixes of w and by extension, pref(L) def = {pref(w) | w ∈ L} the prefix of L. L is said to be prefix-closed whenever pref(L) = L and extensionclosed whenever L = L • A * . Given a tuple of symbols e = (e 1 , . . . , e n ), Π i (e) is the projection of e on its i th element (Π i (e) def = e i ).

Timed languages. Let R ≥0 denote the set of non negative real numbers, and Σ a finite alphabet of actions. A pair (δ, a) ∈ (R ≥0 × Σ) is called an event. We note del(δ, a) = δ and act(δ, a) = a the projections of events on delays and actions, respectively. A timed word over Σ is a finite sequence of events ranging over

(R ≥0 × Σ) * . For σ = (δ 1 , a 1 )•(δ 2 , a 2 ) • • • (δ n , a n ), δ i (2 ≤ i ≤ n) is
the delay between a i-1 and a i and δ 1 the time elapsed before the first action. Note that the alphabet is infinite in this case. Nevertheless, previous notions and notations defined above (related to length, concatenation, prefix, etc) naturally extend to timed words. The sum of delays of a timed word σ is noted time(σ). Given t ∈ R ≥0 , and a timed word σ ∈ (R ≥0 ×Σ) * , we define the observation of σ at time t as the timed word obs(σ, t) def = max{σ | σ σ ∧ time(σ ) ≤ t}, i.e., the longest prefix of σ with a sum of delays less than t. The untimed projection of

σ is Π Σ (σ) def = a 1 • a 2 • • • a n in Σ * (i.
e., delays are ignored). A timed language is any subset L ⊆ (R ≥0 × Σ) * . We define the following order on timed words:

σ delays σ (noted σ d σ) if Π Σ (σ ) Π Σ (σ) and ∀i ≤ |σ |, del(σ(i)) ≤ del(σ (i)).
Timed Automata. Let X = {X 1 , . . . , X k } be a finite set of clocks. A clock valuation for X is a function ν from X to R X ≥0 where R X ≥0 denotes the valuations of X. For ν ∈ R X ≥0 and δ ∈ R ≥0 , ν + δ is the valuation assigning ν(X i ) + δ to each clock X i of X. Given a set of clocks X ⊆ X, ν[X ← 0] is the clock valuation ν where all clocks in X are assigned to 0. G(X) denotes the set of clock constraints defined as boolean combinations of simple constraints of the form X i c with X i ∈ X, c ∈ N and ∈ {<, ≤, =, ≥, >}. Given g ∈ G(X) and ν ∈ R X ≥0 , we write ν |= g when g(ν) ≡ true.

Definition 1 (Timed automaton). A timed automaton (TA) is a tuple

A = L, l 0 , X, Σ, ∆, G , s.t. L is a finite set of locations with l 0 ∈ L the initial location, X is a finite set of clocks, Σ is a finite set of events, ∆ ⊆ L × G(X) × Σ × 2 X × L is the transition relation, and G ⊆ L is a set of accepting locations.
The semantics of a TA is a timed transition system

[[A]] = Q, q 0 , Γ, →, F G where Q = L × R X
≥0 is the (infinite) set of states, q 0 = (l 0 , ν 0 ) is the initial state where ν 0

F G = G × R X ≥0
is the set of of accepting states, Γ = R ≥0 × Σ is the set of transition labels, i.e., pairs composed of a delay and an action. The transition relation

→⊆ Q × Γ × Q is a set of transitions of the form (l, ν) (δ,a) ---→(l , ν ) with ν = (ν + δ)[Y ← 0] whenever there exists (l, g, a, Y, l ) ∈ ∆ s.t. ν + δ |= g for δ ≥ 0.
In the following, we consider a timed automaton A = L, l 0 , X, Σ, ∆, G with its semantics [[A]]. A is deterministic whenever for any (l, g 1 , a, Y 1 , l 1 ) and (l, g 2 , a, Y 2 , l 2 ) in ∆, g 1 ∧ g 2 is false. A is complete whenever for any location l ∈ L and every event a ∈ Σ, the disjunction of the guards of the transitions leaving l and labeled by a is true.

In the remainder of this paper, we shall consider only deterministic timed automata.

A run ρ from q ∈ Q is a sequence of moves in [[A]] of the form: ρ = q 0 (δ1,a1) ----→ q 1 • • • q n-1 (δn,an)
-----→ q n . The set of runs from q 0 ∈ Q is denoted Run(A) and Run F G (A) denotes the subset of runs accepted by A, i.e., ending in F G . The trace of a run ρ is the timed word (δ 1 , a 1 ) • (δ 2 , a 2 ) • • • (δ n , a n ). We note L(A) the set of traces of Run(A). We extend this notation to L F G (A) in a natural way. Timed Properties A timed property is defined by a timed language ϕ ⊆ (R ≥0 × Σ) * . Given a timed word σ ∈ (R ≥0 × Σ) * , we say that σ satisfies ϕ (noted σ |= ϕ) if σ ∈ ϕ. In the sequel, we shall be interested in safety and co-safety timed properties. Informally, safety (resp. co-safety) properties state that "nothing bad should ever happen" (resp. "something good should happen within a finite amount of time"). Safety (resp. co-safety) properties can be characterized by prefix-closed (resp. extension-closed) languages. We consider only the sets of safety and co-safety properties that can be represented by timed automata (Definition 1).

Definition 2 (Safety and Co-safety TA). A complete and deterministic TA L, l 0 , X, Σ, ∆, G , where G ⊆ L is the set of accepting locations, is said to be:

-a safety TA if l, g, a, Y, l ∈ ∆, l ∈ L \ G ∧ l ∈ G; -a co-safety TA if l, g, a, Y, l ∈ ∆, l ∈ G ∧ l ∈ L \ G.
It is easy to check that safety and co-safety TAs define safety and co-safety properties. Example 1 (Safety and co-safety TA). Fig. 1a and 1b present two properties formalized with safety and co-safety TA. Accepting locations are represented by squares. The safety TA formalizes the property ϕ 1 defined over Σ 1 = {a, r}: "There should be a delay of at least 5 time units between any two user requests (r)". The co-safety TA formalizes the property ϕ 2 defined over Σ 2 = {r, g, a}: "The user can perform an action a only after a successful authentication, i.e., after sending a request r and receiving a grant g. After an r, g should occur between 10 and 15 time units".

Enforcement Monitoring in a Timed Context

Roughly speaking, both in the timed and untimed settings, the purpose of an enforcement monitor (EM) is to read some (possibly incorrect) input sequence σ produced by a running system (input to the enforcer), and to transform it into an output sequence o that is correct w.r.t. a property ϕ, here modeled by a TA. From an abstract point of view, an enforcement monitor realizes an enforcement function E that transforms timed words into timed words according to global time.

Definition 3. For a given property ϕ, an enforcement function is a function E from (R ≥0 × Σ) * × R ≥0 to (R ≥0 × Σ) * . Enforcement function ϕ σ, t E(σ, t) |= ϕ Fig. 2: Enforcement function E
An enforcement function E transforms some timed word σ given as input and possibly incorrect w.r.t. the desired property (see Fig. 2). The resulting output E(σ, t) at time t is a timed word with same actions, but possibly increased delays between actions so that it satisfies the property. Similar to the untimed setting, additional constraints on E(σ, t), namely soundness and transparency, are required on actions. However, in the timed setting, those constraints also depend on both delays between events and the class of the enforced property, as we shall discuss later.

An enforcement function E is realized by an enforcement monitor EM . This monitor is equipped with a memory and a set of enforcement operations used to store and dump some timed events to and from the memory, respectively. The memory of an EM is basically a queue containing a timed word, the received actions with increased delays that have not been released yet. In addition, the EM also keeps track of the state of the TA modeling the property, satisfaction of the property using a Boolean variable, and some variables indicating the clock values used to count time between input and output events.

The specific operations of the EM are the Store operation which stores in memory the received action together with a possibly modified delay; the Dump operation which releases the first action from the memory; and the optional Halt operation which stops the enforcer, i.e., blocks the input sequence and stops producing outputs. Off operation which turns off the enforcer. The Off and Halt operations can be added for optimization. The Off can be used when we observe that the property will be satisfied for any future input events. The Halt operation is useful if the property cannot be satisfied anymore.

In the following sections, we will present enforcement monitors for both safety and co-safety properties and analyze constraints on the associated enforcement functions.

Enforcement of Safety Properties

In this section we focus on the enforcement of a safety property ϕ specified by a safety automaton A = L, l 0 , X, Σ, ∆, G and its associated semantics

[[A]] = Q, q 0 , Γ, →, F G .
Without loss of generality, we assume that the set of locations L \ G is reduced to a singleton {Bad}. Given ϕ, and a timed word σ, an enforcement function E for ϕ should satisfy the following soundness, transparency and optimality conditions. Definition 4 (Soundness, transparency and optimality).

Let E : (R ≥0 × Σ) * × R ≥0 → (R ≥0 × Σ) * be an enforcement function for a safety property ϕ. E is: -sound if ∀σ ∈ (R ≥0 × Σ) * , ∀t ∈ R ≥0 , E(σ, t) |= ϕ; -transparent if ∀σ ∈ (R ≥0 ×Σ) * , ∀t ∈ R ≥0 , E(σ, t) d obs(σ, t)∧time(E(σ, t)) ≤ t.
If E is both sound and transparent, we say that it is optimal if, for any input σ ∈ (R ≥0 × Σ) * , at any time t ∈ R ≥0 , the following constraints hold:

(Op1) ω , ω |= ϕ ∧ ω d obs(σ, t) ∧ |ω | > |E(σ, t)| (Op2) ∀i ∈ [1, |E(σ, t)|], δ ∈ R ≥0 , del(obs(σ, t)(i)) ≤ δ ≤ del(E(σ, t)(i)) ∧E(σ, t) [•••i-1] • (δ , act(E(σ, t)(i)))
|= ϕ Soundness means that, at any time t, the produced timed word should satisfy the property ϕ. Transparency means that, at any time instant t, the output E(σ, t) delays the input obs(σ, t): the enforcement function should not modify the order of events, should not reduce the delays between consecutive events, and should not produce outputs faster than inputs. Optimality means that the enforcement function should provide the output as soon as possible. The optimality condition (Op1) extends the requirement on the output sequences of the enforcement function in the untimed case (cf. [START_REF] Falcone | You should better enforce than verify[END_REF]): at any time instant t, the output sequence E(σ, t) should be the longest correct timed word delaying the input sequence obs(σ, t). Here, taking physical time into account, (Op2) requires that the input and output sequences are as close as possible w.r.t. physical observation, i.e., every prefix of E(σ, t) has the shortest possible last delay.

We now design an enforcement monitor whose semantics effectively realizes the enforcement function as described Definition 4.

Definition 5 (Enforcement Monitor for safety). An enforcement monitor for ϕ is a transition system EM = C, C 0 , Γ EM , → s.t.:

-C = (R ≥0 × Σ) * × R ≥0 × R ≥0 × B × Q is the set of configurations; -the initial configuration is C 0 = , 0, 0, tt, q 0 ∈ C; -Γ EM = (R ≥0 ×Σ)∪{ } ×Op× (R ≥0 ×Σ)∪{ } is the input-operation-output
alphabet, where Op = {store(•), dump(•), del(•)}; -→⊆ C × Γ EM × C is the transition relation defined as the smallest relation obtained by the following rules applied in the following order:

• store: σ s , δ, d, tt, q (δ,a)/store(δ ,a)/ → σ s • (δ , a), 0, d, (δ = ∞), q with: * δ = update s (q, a, δ), where update s5 is the function defined as:

Q × Σ × R ≥0 → R ≥0 (q, a, δ) →    ∞ if ∀δ ∈ R ≥0 , ∀q 1 ∈ Q, (δ ≥ δ ∧ q (δ ,a) → q 1 ) ⇒ q 1 ∈ F G min{δ ∈ R ≥0 | ∃q 1 ∈ F G , q (δ ,a) → q 1 ∧ δ ≥ δ} * q is defined as q (δ ,a)
→ q if δ < ∞ and q = q otherwise;

• dump: (δ, a) • σ s , s, δ, b, q /dump(δ,a)/(δ,a) → σ s , s, 0, b, q if δ = ∞;
• delay: σ s , s, d, b, q

/del(δ)/ → σ s , s + δ, d + δ, b, q .
A configuration σ s , s, d, b, q of the EM consists of the current stored sequence (i.e., the memory content) σ s , two clock values s and d indicating respectively the time elapsed since the last store and dump operations, a Boolean b indicating whether the underlying enforced property is satisfied or not on the output sequence, and q the current state of [[A]] reached after processing the sequence already released followed by the timed word in memory. Regarding its alphabet, in the input (resp. output) sequence, the EM either lets time elapse and no event is read or released, or reads and stores (resp. dumps and releases) a symbol event after some delays. Semantics rules can be understood as follows:

-The store rule is executed upon the reception of an event (δ, a). The timed event (δ , a) is appended to the memory content, where δ is the minimal delay that has to be waited so that the property remains satisfied -if such a delay exists. The value of s is then reinitialized to 0. If a delay can be found through the update s function, q is updated to the state that will be reached by appending the timed event (δ , a) to the output sequence concatenated with the contents of the memory, and b remains tt and becomes ff otherwise. -The dump rule is executed when the value of d is equal to the delay of the first timed event in the memory. The value of d is then reinitialized to 0. The first event in memory is suppressed (and released from the enforcer). Other elements of the configuration remain unchanged. -The delay rule adds the time elapsed δ to the current values of s and d when no store nor dump operation is possible.

Remark 1. The model of enforcement monitor presented in Definition 5 can be easily extended by relaxing two hypothesis: in the store rule, we check whether there is a delay greater than δ allowing the output sequence to stay in the accepting states of the property (δ = ∞). Of course, this condition can be adapted to a given time bound in R ≥0 . More complex conditions are also possible according to some desired quality of service.

Similarly, processing input and output actions is assumed to be done in zero time. Some delay (either fixed or depending on additional parameters) can be considered for this action by modifying the store rule.

We define the language of runs of an enforcement monitor EM :

L(EM ) ⊆ (Γ EM ) * = (R ≥0 × Σ) ∪ { } × Op × (R ≥0 × Σ) ∪ { } *
It is worth noticing that enforcement monitors are deterministic. Hence, given σ ∈ (R ≥0 × Σ) * and t ∈ R ≥0 , let w ∈ L(EM ) be the unique maximal sequence such that

Π i∈[1,|w|] (Π 1 (w(i))) = obs(σ, t),
where Π is the projection that erases from words in ((R ≥0 × Σ) ∪ { }) * . Now, we define the enforcement function E associated to EM as

∀σ ∈ (R ≥0 × Σ) * , ∀t ∈ R ≥0 , E(σ, t) = Π i∈[1,|w|] (Π 3 (w(i))) (1)
Proposition 1. Given an enforcement monitor EM for a safety property ϕ and E defined as in Eq. ( 1), E verifies the soundness, transparency and optimality conditions of Definition 4.

/( , 0, 0, tt, < l 0 , 0 >)/(1, a)

• (3, r) • (1, r) /( , 1, 1, tt, < l 0 , 1 >)/(1, a) • (3, r) • (1, r)
del( 1)

/((1, a), 0, 1, tt, < l 0 , 1 >)/(3, r) • (1, r) store (1, a)/( , 0, 0, tt, < l 0 , 1 >)/(3, r) • (1, r) dump (1, a)/( , 3, 3, tt, < l 0 , 4 >)/(3, r) • (1, r) del (3)
(1, a)/((3, r), 0, 3, tt, < l 1 , 0 >)/(1, r)

store t = 0 t = 1 t = 1 t = 1 t = 4 t = 4
(1, a) • (3, r)/( , 0, 0, tt, < l 1 , 0 >)/(1, r) Fig. 3: Enforcer configuration evolution Example 2. Let us illustrate how these rules are applied to enforce ϕ 1 (represented by the TA in Fig. 1a with Σ 1 = {a, r}). Let us consider the input timed word σ = (1, a) • (3, r) • (1, r). Figure 3 shows how successive rules are applied and the evolution of the configurations of the EM . The variable t describes global time. The input is represented on the right-hand (resp. left-hand) side of the configuration.

(1, a) • (3, r)/( , 1, 1, tt, < l 1 , 1 >)/(1, r)

Enforcement of Co-safety Properties

Let us now focus on the enforcement of co-safety properties. We assume a co-safety property ϕ specified by a co-safety timed automaton A = L, l 0 , X, Σ, ∆, G and its associated semantics [[A]] = Q, q 0 , Γ, →, F G . An enforcer function E for a co-safety property ϕ should satisfy new soundness, transparency and optimality conditions.

Before defining those constraints, the notion of a sequence delaying another has to be modified in the context of co-safety properties. Let σ, σ ∈ (R ≥0 ×Σ) * be two timed sequences, we note

σ c σ for Π Σ (σ ) = Π Σ (σ) ∧ ∀i ≤ |σ |, del(σ (i)) ≥ del(σ(i)).
This order between timed words shall be used in the transparency and optimality conditions below to constrain the sequences produced by an enforcer. We define γ(σ)

(R ≥0 × Σ) * × R ≥0 → (R ≥0 × Σ) * for a co-safety property ϕ is -sound if ∀σ ∈ (R ≥0 × Σ) * , ∀t ∈ R ≥0 , E(σ, t) = ⇒ (∃t ≥ t, E(σ, t ) |= ϕ). -transparent if ∀σ ∈ (R ≥0 × Σ) * , ∀t ∈ R ≥0 , E(σ, t) = ⇒ (∃t ≥ t, E(σ, t ) c obs(σ, t)).
If E is sound and transparent, it is optimal if for any input σ ∈ (R ≥0 × Σ) * , at any time t ∈ R ≥0 , the following constraints hold:

(Op1) γ obs(σ, t) = ∅ ∧ ∀t < t, γ(obs(σ, t ) = ∅) ⇒ ∃t ≥ t, |E(σ, t )| = |obs(σ, t)| ∧ t = t + time(E(σ, t )) ; (Op2) E(σ, t) = ⇒ (1) ∧ (2), where let E(σ, t) [•••n] be the smallest prefix of E(σ, t) s.t. E(σ, t) [•••n] |= ϕ in (1) (δ 1 , . . . , δ n ), n i=1 δ i ≤ n i=1 del(E(σ, t)(i)) ∧ i∈[1,n] (δ i , act((σ(i)))) |= ϕ ∧ ∀i ∈ [1, n], del(σ(i)) ≤ δ i (2) E(σ, t) |= ϕ ⇒ E(σ, t) = E(σ, t) [•••n] • obs(σ, t) [n+1•••|E(σ,t)|]
Soundness means that if a timed word is released by the enforcement function, in the future, the output timed word of the enforcement function should satisfy the property ϕ. 6 Transparency means that the enforcement function should not change the order of events, and the delay between any two consecutive events cannot be reduced.

Optimality means that the output is produced as soon as possible: Op1 means that if t is the first time instant at which there is a timed word that delays obs(σ, t) and satisfies ϕ, then, in the future at time t = t + time(E(σ, t )), the enforcement monitor should have output exactly all the observed events until time t. Op2-1 means that if E(σ, t) = is released by the enforcement function, for the smallest prefix E(σ, t) [•••n] that satisfies ϕ, the total amount of time spent to trigger E(σ, t) [•••n] should be minimal.Op2-2 means that the delay between the remaining actions obs(σ, t) [n+1••• ] (i.e., when the property is satisfied) should not be changed. Similarly to safety properties, we expect the enforcement function to minimally alter the initial sequence: after correcting an incorrect prefix, the remainder of the sequence should be the same for events and delays between them.

Before presenting the definition of enforcement monitor, we introduce update c as a function from (R ≥0 × Σ)

+ → R + ≥0 × B such that for σ ∈ (R ≥0 × Σ) + update c (σ) def =      (δ 1 , . . . , δ |σ| ), tt s.t. |σ| i=1 δ i = min{γ t (σ)}, if γ(σ) = ∅ (del(σ(1)), . . . , del(σ(|σ|))), ff , otherwise
Definition 7 (Enforcement Monitor for co-safety properties). An enforcement monitor EM for ϕ is a transition system C, C 0 , Γ, → s.t.:

-C = (R ≥0 × Σ) * × R ≥0 × R ≥0 × B is the set of configurations and the initial configuration is C 0 = ε, 0, 0, ff ∈ C; -Γ EM = (R ≥0 × Σ) × Op × (R ≥0 × Σ) is the "input-operation-output" alphabet,
where Op = {store-ϕ(•), store-ϕ init (•), store-ϕ(•), dump(•), delay(•)}; -→⊆ C × Γ EM × C is the transition relation defined as the smallest relation obtained by the following rules applied with the priority order below:

1. store-ϕ: σ s , δ, d, ff

(δ,a)/store-ϕ(δ,a)/ → σ s • (δ, a), 0, d, ff if Π 2 update c (σ s • (δ, a)) = ff 2. store-ϕ init : σ s , δ, d, ff (δ,a)/store-ϕinit(δ ,a)/ → σ s , 0, 0, tt if Π 2 update c (σ s • (δ, a)) = tt with • δ = Π 1 update c (σ s • (δ, a)) • σ s = i∈[1,|σs|] (Π i (δ ), act(σ s (i))) • (δ |σs|+1 , a)
3. store-ϕ: σ s , δ, d, tt Fig. 4: Enforcer configuration evolution The EM either lets time elapse when no event is read or released as output, or reads and stores (resp. dumps and outputs) an event after some delay. Semantic rules can be understood as follows: -Upon reception of an event (δ, a), one of the three store rules is executed. The rule store-ϕ is executed if b ff and the property still remains unsatisfied after this new event (i.e., when the update c function returns ff). If the update c function returns tt (indicating that the ϕ can now be satisfied), then the rule store-ϕ init is executed. When executing this rule, d is reset to 0, indicating that the enforcer can start outputting events. The rule store-ϕ is executed if the Boolean in the current configuration is tt, which indicates that the property is already satisfied by the inputs received earlier. So, in this case, it is not necessary to invoke the update c function, and the event (δ, a) is appended to the memory. -The dump rule is similar to the one of the enforcement of safety properties except that we wait that the Boolean indicating property satisfaction becomes tt. -The delay rule adds the time elapsed to the current clock values s and d. Note that, in this case, time measured in output starts elapsing upon property satisfaction by the memory content (contrarily to the safety case, where it starts with the enforcer).

As was the case in the previous section, from EM , we can define an enforcement function E as in Eq. ( 1), such that the following proposition holds: Proposition 2. Given an enforcement monitor EM for a co-safety property and E defined as in Eq (1), E is sound, transparent and optimal as per Definition 6. Example 3. Let us illustrate how these rules are applied to enforce ϕ 2 (Fig. 1b), with Σ 2 = {r, g, a}. Let us consider the input timed word σ = (1, r) • (8, g) • (5, a). Figure 4 shows how semantic rules are applied, and the evolution of the configurations of the EM . The input is shown on the right of the configuration, and the output is presented on the left. The variable t describes global time. The resulting output is E(σ) = (1, r) • (10, g) • (5, a), which satisfies the property ϕ presented in Fig. 1b.

Implementation

Enforcement Monitor

Store Process Dump Process

Memory σ, t E(σ, t) Fig. 5: Realizing an EM Let us now provide the algorithms showing how enforcement monitors can be implemented. As shown in Fig. 5, the implementation of an enforcement monitor (EM) consists of two processes running concurrently (Store and Dump) and a memory. The Store process models the store rules. The memory contains the timed words σ s . The Dump process reads events stored in the memory and releases them as output after the required amount of time. To define the enforcement monitors, the following algorithms assume a TA A = L, l 0 , X, Σ, ∆, G . We now describe these processes for safety properties.

Algorithm 1 DumpProcess safety d ← 0 while tt do await (|σs| ≥ 1) (δ, a) ← dequeue (σs) wait (δ -d) dump (a) d ← 0 end while Algorithm 2 StoreProcess safety (l, X) ← (l0, [X ← 0]) while tt do (δ, a) ← await event if (post(l, X, a, δ) / ∈ G) then δ ← update(l, X, a, δ) if δ = ∞ then terminate StoreProcess end if else δ ← δ end if (l, X) ← post(l, a, X, δ ) enqueue (δ ,
-The DumpProcess safety algorithm (see Algorithm 1) is an infinite loop that scrutinizes the memory and proceeds as follows: Initially, d is set to 0. If the memory is empty (|σ s | = 0), it waits until a new element (δ, a) is stored in memory, otherwise it proceeds with the first element in memory. Meanwhile, d keeps track of the time elapsed since the last dump operation. The DumpProcess safety waits for (δ -d) time units before releasing the action a and resets d. -The StoreProcess safety algorithm (see Algorithm 2) is an infinite loop that scrutinizes the system for input events. It proceeds as follows. Let (l, X) be the state of the property automaton, where l represents the location and X is the current clock values initialized to (l 0 , 0). The function post takes a state of the property automaton (l, X), an event (δ, a), and computes the state reached by the property automaton.

The update function computes a new delay δ such that the property automaton will reach an accepting state in an optimal way by triggering (δ , a). We now describe these processes for co-safety properties. -The DumpProcess co-safety algorithm for co-safety properties (see Algorithm 3) resembles the one of the safety case. The only difference is that the infinite loop starts only after receiving the startDump notification from the StoreProcess co-safety . -In the StoreProcess co-safety algorithm (see Algorithm 4), goalReached is a Boolean, used to indicate if the goal location is visited by the input events which were already processed. It is initialized to ff. The update c function takes all events stored in the enforcer memory, and returns new delays and if the goal location is reachable. startDump is a notification message sent to the DumpProcess co-safety , to indicate that it can start dumping the events stored in the memory. Note that the update c can be easily implemented using the optimal path routine of UPPAAL.

Evaluation

Enforcement monitors for safety and co-safety properties, based on the algorithms presented in the previous section, have been implemented in prototype tool of 500 LOC using Python. The tool also uses UPPAAL [START_REF] Larsen | UPPAAL in a nutshell[END_REF] as a library to implement the update function and the pyuppaal library to parse UPPAAL models written in XML.

We present some performance evaluation on a simulated system where the input timed trace is generated. As described in Sec. 6, enforcement monitors for safety and co-safety properties are implemented by two concurrent processes. The TA representing the property is a UPPAAL model, and is an input to the enforcement monitor. The UPPAAL model also contains another automaton representing the sequence of events received by the enforcement monitor. The update function of the StoreProcess uses UPPAAL. Experiments were conducted on an Intel Core i7-2720QM at 2.20GHz CPU, and 4 GB RAM running on Ubuntu 12.04 LTS. Note that the implementation is a prototype, and there is still scope for improving the performance.

Results of the performance analysis of our running example properties are presented in Tables 1a and1b. The values are presented in seconds. Average values are computed over multiple runs. The length of the input trace is denoted by |tr|. The entry t tr represents the time taken by the system simulator process to generate the trace. The entry t update (resp. t Post) indicates the time taken for one call to the update (resp. post) function when the last event of the input trace is received. The entry t EM presents the total time from the start of the simulation until the last event is dumped by the enforcer. The throughput shows how many events can be processed by the enforcer (|tr|/t EM).

We observe that the throughput decreases with the length of the input trace. This unexpected behavior stems from the external invocation of UPPAAL to realize post and update functions. Indeed, after each event, the length of the automaton representing the trace grows, and, as indicated in Table 1a, the time taken by update and post functions also increases, unnecessarily starting the computation from the initial location each time an event is received. Future implementations will avoid this by realizing the post and update functions online from the current state. Performance and throughput shall 1b, the time taken by the update function increases with the number of events. This behavior is expected for co-safety properties, as we check for an optimal output from the initial state after each event. Please note that in case of a co-safety property, once the property is satisfied (a good location is reached), it is not necessary to invoke the update function. From that point onwards, the increase in total time t EM per event will be very less (since we just add the received event to the output queue), and t update will be zero for the events received later on.

Related Work

This work is by no means the first to address monitoring of timed properties. Matteucci inspires from partial-model checking techniques to synthesize controller operations to enforce safety and information-flow properties using process-algebra [START_REF] Matteucci | Automated synthesis of enforcing mechanisms for security properties in a timed setting[END_REF]. Monitors are close to Schneider's security automata [START_REF] Schneider | Enforceable security policies[END_REF]. The approach targets discrete-time properties and systems are modelled as timed processes expressed in CCS. Compared to our approach, the description of enforcement mechanisms remains abstract, directly restricts the monitored system, and no description of monitor implementation is proposed.

Other research efforts aim to mainly runtime verify timed properties and we shall categorize them into i) rather theoretical efforts aiming at synthesizing monitors, and ii) tools for runtime monitoring of timed properties.

Synthesis of timed automata from timed logical formalisms Bauer et al. propose an approach to runtime verify timed-bounded properties expressed in a variant of Timed Linear Temporal Logic [START_REF] Bauer | Runtime verification for LTL and TLTL[END_REF]. Contrarily to TLTL, the considered logic, TLTL 3 , processes finite timed words and the truth-values of this logic are suitable for monitoring. After reading some timed word u, the monitor synthesized for a TLTL 3 formula ϕ state the verdict (resp. ⊥) when there is no infinite timed continuation w such that u • w satisfy (resp. does not satisfy) ϕ. Another variant of LTL in a timed context is the metric temporal logic (MTL), a dense extension of LTL. Nickovic et al. [START_REF] Maler | From MITL to timed automata[END_REF][START_REF] Nickovic | From MTL to deterministic timed automata[END_REF] proposed a translation of MTL to timed automata. The translation is defined under the bounded variability assumption stating that, in a finite interval, a bounded number of events can arrive to the monitor. Still for MTL, Thati et al. propose an online monitoring algorithm by rewriting of the monitored formula and study its complexity [START_REF] Thati | Monitoring algorithms for metric temporal logic specifications[END_REF]. Later, Basin et al.

propose an improvement of this approach having a better complexity but considering only the past fragment of MTL [START_REF] Basin | Algorithms for monitoring real-time properties[END_REF].

Runtime enforcement of timed properties as presented in this paper is compatible with the previously described approaches. These approaches synthesize automata-based decision procedures for logical formalisms. Decision procedures synthesized for safety and co-safety properties could be used as input to our framework.

Tools for runtime monitoring of timed properties The Analog Monitoring Tool [START_REF] Nickovic | AMT: A property-based monitoring tool for analog systems[END_REF] is a tool for monitoring specifications over continuous signals. The input logic of AMT is STL/PSL where continuous signals are abstracted into propositions and operations are defined over signals. Input signal traces can be monitored in an offline or incremental fashion (i.e., online monitoring with periodic trace accumulation).

LARVA [START_REF] Colombo | Dynamic event-based runtime monitoring of realtime and contextual properties[END_REF][START_REF] Colombo | LARVA -safer monitoring of real-time java programs (tool paper)[END_REF] takes as input properties expressed in several notations, e.g., Lustre, duration calculus. Properties are translated to DATE (Dynamic Automata with Timers and Events) which basically resemble timed automata with stop watches but also feature resets, pauses, and can be composed into networks. Transitions are augmented with code that modify the internal system state. DATE target only safety properties. In addition, LARVA is able to compute an upper-bound on the overhead induced on the target system. The authors also identify a subset of duration calculus, called counter-examples traces, where properties are insensitive to monitoring [START_REF] Colombo | Safe runtime verification of real-time properties[END_REF].

Our monitors not only differ by their objectives but also by how they are interfaced with the system. We propose a less restrictive framework where monitors asynchronously read the outputs of the target system. We do not assume our monitors to be able to modify the internal state of the target program. The objective of our monitors is rather to correct the timed sequence of output events before this sequence is released to the environment (i.e., outside the system augmented with a monitor).

Conclusion and Future Work

This paper introduces runtime enforcement for timed properties and provides a complete framework. We consider safety and co-safety properties described by timed automata. We propose adapted notions of enforcement monitors with the possibility to delay some input actions in order to satisfy the required property. For this purpose, the enforcement monitor can store some actions during a certain time period. We propose a set of enforcement rules ensuring that outputs not only satisfy the required property (if possible), but also with the "best" delay according to the current situation. We describe how to realize the enforcement monitor using concurrent processes, how it has been prototyped and experimented. This paper introduced the first steps to runtime enforcement of (continuous) timed properties. However, several research questions remain open. As this approach targets explicitly safety and co-safety properties, it seems desirable to investigate whether more expressive properties can be enforced, and if so, pro-pose enforcement mechanisms for them. We expect to extend our approach to Boolean combinations of timed safety and co-safety properties, and more general properties. The question requires further investigation since the update function would have to be adapted. A precise characterization of enforceable timed properties would thus be possible, as was the case in the untimed setting [START_REF] Bauer | Runtime verification for LTL and TLTL[END_REF][START_REF] Falcone | What can you verify and enforce at runtime?[END_REF]. Also related to expressiveness is the question of how the set of timed enforceable properties is impacted when the underlying memory is limited and/or the primitives operations endowed to the monitor are modified. A more practical research perspective is to study the implementability of the approach proposed in this paper, e.g., using robustness of timed automata.

  A co-safety TA for ϕ2

Fig. 1 :

 1 Fig. 1: Example of Timed Properties is the valuation that maps every clock to 0,F G = G × R X ≥0is the set of of accepting states, Γ = R ≥0 × Σ is the set of transition labels, i.e., pairs composed of a delay and an action. The transition relation →⊆ Q × Γ × Q is a set of transitions of the form

del( 1 )( 1 ,

 11 a) • (3, r)/((5, r), 0, 1, tt, < l 1 , 0 >)/ store (1, a) • (3, r)/((5, r), 4, 5, tt, < l 1 , 4 >)/ del(4) (1, a) • (3, r) • (5, r)/( , 4, 0, tt, < l 1 , 4 >)/

  def = {σ c σ | σ |= ϕ}, the set of sequences delaying σ and satisfying the property ϕ and γ t (σ) def = {time(σ ) | σ ∈ γ(σ)} the set of sums of delays of these sequences. Definition 6 (Soundness, transparency, optimality). An enforcement function E :

( 10 ( 1 ,

 101 δ,a)/store-ϕ(δ,a)/ → σ s • (δ, a), 0, d, tt 4. dump: (δ, a) • σ s , s, δ, tt /dump(δ,a)/(δ,a) → σ s , s, 0, tt 5. delay: σ s , s, d, b /delay(δ)/ → σ s , s + δ, d + δ, b . /( , 0, 0, ff)/(1, r) • (8, g) • (5, a) /( , 1, 1, ff)/(1, r) • (8, g) • (5, a) delay(1) /((1, r), 0, 1, ff)/(8, g) • (5, a) store-¬ ϕ /((1, r), 8, 9, ff)/(8, g) • (5, a) delay(8) /((1, r) • (10, g), 0, 0, tt)/(5, a) store-ϕ init /((1, r) • (10, g), 1, 1, tt)/(5, a) delay(1) (1, r)/((10, g), 1, 0, tt)/(5, a) r)/((10, g), 5, 4, tt)/(5, a) (1, r)/((10, g) • (5, a), 0, 4, tt)/ store-ϕ (1, r)/((10, g) • (5, a), 6, 10, tt)/ delay(6) (1, r) • (10, g)/((5, a), 6, 0, tt)/ dump (1, r) • (10, g)/((5, a), 11, 5, tt)/ delay(5) (1, r) • (10, g) • (5, a)/( , 11, 0, tt)

a) end while Algorithm 3 Algorithm 4

 34 DumpProcess co-safety await startDump d ← 0 while tt do await (|σs| ≥ 1) (δ, a) ← dequeue (σs) wait (δ -d) dump (a) d ← 0 end while StoreProcess co-safety goalReached ← ff while tt do (δ, a) ← await (event) enqueue(δ, a) if goalReached = ff then (newDelays, R) ← update c (σs) if R = tt then modify delays goalReached ← tt notify (startDump) end if end if end while

Table 1 :

 1 Performance analysis of enforcement monitors the trace length. Further experiments have been carried out on different examples similarly demonstrating feasibility and scalability.For co-safety properties, regarding the total time t EM, note that the most expensive operation update is called upon each event. Moreover, examining the column t update in Table

	(a) For ϕ1				(b) For ϕ2
	|tr| t update t post	t tr	t EM throughput	|tr| t update t tr t EM
	100 0.0433 0.0383 0.00483 2.648	37	100 0.063 0.0026 1.28
	200 0.08196 0.07158 0.0087 9.135	21.89	200	0.17 0.0065	8
	300 0.121 0.1065 0.0118 19.42	15.46	300	0.33 0.0081	25
	400 0.1696 0.1525 0.0133 34.314	11.65	400	0.54 0.0115	58
	500 0.2148 0.1891 0.0142 53.110	9.41	500	0.79 0.0131 109
	600 0.2668 0.2334 0.0166 77.428	7.75	600	1.11 0.0157 186
	700 0.3164 0.2789 0.0178 107.61	6.50	700	1.50 0.0186 297
	800 0.3669 0.3289 0.0198 143.53	5.57	800	1.96 0.0209 462
	900 0.4256 0.3810 0.0237 181.06	4.97	900	2.40 0.0234 623
	1000 0.4878 0.4352 0.0259 229.12	4.36	1000	2.84 0.0341 852
	be independent from

The updates function computes the minimal delay δ ≥ δ, such that the safety-property automaton still remains in an accepting state after processing the action a.

As usual in runtime enforcement, either it is assumed that the empty sequence does belong to the property or the soundness constraint does not take into account.