Skip to content

Commit

Permalink
[pylibs] Added case study on fast (1-hour) key rotation; fixes in dep…
Browse files Browse the repository at this point in the history
…recated_prefix case study.
  • Loading branch information
EskoDijk committed Jan 17, 2024
1 parent de67889 commit 8feadeb
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 3 deletions.
5 changes: 2 additions & 3 deletions pylibs/case_studies/deprecated_prefix.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
import logging

# Case study on routing when a prefix becomes deprecated. Requires loading current.pcap
# into Wireshark to see the results.

import time

import logging
from otns.cli import OTNS
from otns.cli.errors import OTNSExitedError

Expand Down
82 changes: 82 additions & 0 deletions pylibs/case_studies/fast_key_rotation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/usr/bin/env python3
# Copyright (c) 2024, The OTNS Authors.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of the copyright holder nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

# Case study on fast key rotation (low Rotation Time field in Security Policy)

import logging
from otns.cli import OTNS
from otns.cli.errors import OTNSExitedError

def test_ping(ns):
# test ping
ns.ping(1,2,datasize=48) # Parent preps ping to SED - waits in buffer
ns.ping(2,1,datasize=32) # SED sends ping to Parent - this also triggers getting buffered ping from parent.
ns.go(2)
ns.pings()

def main():
ns = OTNS()
ns.logconfig(logging.DEBUG)
ns.loglevel = 'debug'
ns.web()

# Router/Leader
ns.add("router", x=300, y=200)
ns.go(9)

# make a copy of Active Dataset into the dataset buffer. Change security policy only.
ns.node_cmd(1, "dataset init active")
ns.node_cmd(1, "dataset securitypolicy 1")

# set pending dataset parameters.
ns.node_cmd(1, "dataset delay 200")
ns.node_cmd(1,"dataset pendingtimestamp 1696177379")

# commit as the Pending Dataset. Delay timer starts counting down from then on.
ns.node_cmd(1, "dataset commit pending")

# wait until Pending Dataset has become active.
ns.go(1)

# add a SED
ns.add("sed", x=300, y=300)
ns.go(10)

for i in range(10):
#ns.node_cmd(1, "keysequence guardtime 0") # use this to force Router to accept new +1 tKSC value
test_ping(ns)
ns.go(3600) # pass time period for next key rotation

#ns.interactive_cli() # enable this in case interactive CLI status checking is needed at the end.
ns.web_display()

if __name__ == '__main__':
try:
main()
except OTNSExitedError as ex:
if ex.exit_code != 0:
raise

0 comments on commit 8feadeb

Please sign in to comment.