Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maintaining a Nat within a fixed range

Tags:

idris

I'd like to have a Nat that remains within a fixed range. I would like functions incr and decr that fail if they are going to push the number outside the range. This seems like it might be a good use case for Fin, but I'm not really sure how to make it work. The type signatures might look something like this:

- Returns the next value in the ordered finite set.
- Returns Nothing if the input element is the last element in the set. 
incr : Fin n -> Maybe (Fin n)

- Returns the previous value in the ordered finite set.
- Returns Nothing if the input element is the first element in the set.
decr : Fin n -> Maybe (Fin n)

The Nat will be used to index into a Vect n. How can I implement incr and decr? Is Fin even the right choice for this?

like image 498
mushroom Avatar asked Mar 14 '15 17:03

mushroom


People also ask

What is Nat for IP address conservation?

This module also provides information about the benefits of configuring NAT for IP address conservation. NAT enables private IP internetworks that use nonregistered IP addresses to connect to the Internet. NAT operates on a device, usually connecting two networks.

Can Nat policies be rearranged within the policy list?

NAT policies can be rearranged within the policy list. NAT policies are applied to network traffic after a security policy. The central SNAT table allows you to create, edit, delete, and clone central SNAT entries.

How does the Nat table work?

When the device receives the packet with the inside global IP address, it performs a NAT table lookup by using a protocol, the inside global address and port, and the outside address and port as keys. It translates the address to the inside local address 10.1.1.1 and forwards the packet to host 10.1.1.1.

When does Nat return the same inside global IP address?

In Cisco IOS Release 15.1 (3)T and later releases, when you configure the traceroute command, NAT returns the same inside global IP address for all inside local IP addresses. The following figure illustrates a device that is translating a source address inside a network to a source address outside the network.


1 Answers

I guess the easiest way is to use some standard Fin↔Nat conversion functions from Data.Fin:

incr, decr : {n : Nat} -> Fin n -> Maybe (Fin n)
incr {n=n} f = natToFin (succ $ finToNat f) n

decr {n=n} f = case finToNat f of
    Z => Nothing
    S k => natToFin k n
like image 172
Yuuri Avatar answered Oct 22 '22 08:10

Yuuri