diff --git a/NEWS.rst b/NEWS.rst index e40cdb3..4b59031 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -7,6 +7,8 @@ every change, see the Git log. Latest ------ * tbd +* Major: Upgrade to kodo-python 13 +* Minor: Added an option to specify the finite field for the simulation. 1.0.0 ----- diff --git a/examples/relay_simulations.py b/examples/relay_simulations.py index 9789d01..a6cb3d4 100644 --- a/examples/relay_simulations.py +++ b/examples/relay_simulations.py @@ -10,6 +10,7 @@ def print_setup(runs, + field, symbols, symbol_size, error_source_sink, @@ -25,6 +26,7 @@ def print_setup(runs, print("[ ] Runs: {} runs".format(runs)) print("[ SETUP ] configuration.coding") print("[ ] Relay Recode: {}".format(relay_recode)) + print("[ ] Finite Field: {}".format(field)) print("[ ] Size of Symbols: {} bytes".format(symbol_size)) print("[ ] Number of Symbols: {} symbols".format(symbols)) print("[ ] Source Systematic: {}".format(source_systematic)) @@ -37,7 +39,8 @@ def print_setup(runs, print("[--------]") -def relay_simulation(symbols, +def relay_simulation(field, + symbols, symbol_size, error_source_sink, error_source_relay, @@ -67,8 +70,9 @@ def relay_simulation(symbols, | relayN | +--------+ """ - encoder_factory = kodo.FullVectorEncoderFactoryBinary(symbols, symbol_size) - decoder_factory = kodo.FullVectorDecoderFactoryBinary(symbols, symbol_size) + field = getattr(kodo.field, field) + encoder_factory = kodo.RLNCEncoderFactory(field, symbols, symbol_size) + decoder_factory = kodo.RLNCDecoderFactory(field, symbols, symbol_size) s = simulator.Simulator(encoder_factory, decoder_factory) source = s.create_source() @@ -104,11 +108,20 @@ def main(): parser = argparse.ArgumentParser( description=relay_simulation.__doc__, formatter_class=argparse.RawTextHelpFormatter) + + fields = ['binary', 'binary4', 'binary8', 'binary16'] + parser.add_argument( "--runs", help="Set number of runs.", type=int, default=100) + parser.add_argument( + '--field', + type=str, + help='The finite field to use', + choices=fields, + default='binary') parser.add_argument( "--symbols", help="Set symbols.", @@ -159,6 +172,7 @@ def main(): print_setup( runs=args.runs, + field=args.field, symbols=args.symbols, symbol_size=args.symbol_size, error_source_sink=args.error_source_sink, @@ -172,6 +186,7 @@ def main(): results = simulator.ResultSet() for run in range(args.runs): results.add(relay_simulation( + field=args.field, symbols=args.symbols, symbol_size=args.symbol_size, error_source_sink=args.error_source_sink, diff --git a/resolve.json b/resolve.json index d7f5a2d..5b29888 100644 --- a/resolve.json +++ b/resolve.json @@ -12,7 +12,7 @@ "name": "kodo-python", "resolver": "git", "method": "semver", - "major": 12, + "major": 13, "sources": [ "github.com/steinwurf/kodo-python.git" ] diff --git a/simulator/receiver.py b/simulator/receiver.py index e3f45e0..e3dd6db 100644 --- a/simulator/receiver.py +++ b/simulator/receiver.py @@ -12,6 +12,11 @@ def __init__(self, id, stats, decoder): self.decoder = decoder self.stats = stats + # Define the data_out bytearray where the symbols should be decoded + # This bytearray must not go out of scope while the encoder exists! + self.data_out = bytearray(self.decoder.block_size()) + self.decoder.set_mutable_symbols(self.data_out) + def receive(self, payload): """Receive payload.""" key = "{}_receive_from_{}".format(self.id, payload.sender.sender.id) diff --git a/simulator/source.py b/simulator/source.py index 6d7ed09..894cc3f 100644 --- a/simulator/source.py +++ b/simulator/source.py @@ -18,15 +18,11 @@ def __init__(self, id, stats, encoder): self.encoder = encoder self.stats = stats - # Create some data to encode. In this case we make a buffer - # with the same size as the encoder's block size (the max. - # amount a single encoder can encode) - # Just for fun - fill the input data with random data - data_in = os.urandom(encoder.block_size()) - - # Assign the data buffer to the encoder so that we can - # produce encoded symbols - encoder.set_const_symbols(data_in) + # Generate some random data to encode. We create a bytearray of the + # same size as the encoder's block size and assign it to the encoder. + # This bytearray must not go out of scope while the encoder exists! + self.data_in = bytearray(os.urandom(self.encoder.block_size())) + self.encoder.set_const_symbols(self.data_in) def tick(self): """Increment time.""" diff --git a/test/test_relay.py b/test/test_relay.py index 721fdb0..f720d1f 100644 --- a/test/test_relay.py +++ b/test/test_relay.py @@ -3,8 +3,10 @@ import sys sys.path.append('..') +sys.path.append('mock') import unittest +from mock import Mock import simulator.relay @@ -15,7 +17,8 @@ def test_instantiation(self): """Test instantiation.""" id = "test_id" stats = {} - decoder = "decoder_object" + decoder = Mock(name="decoder_object") + decoder.block_size = Mock(return_value=100) c = simulator.relay.Relay(id, stats, decoder) self.assertEqual(c.sender.id, id) self.assertEqual(c.receiver.id, id) diff --git a/test/test_sink.py b/test/test_sink.py index a76fe1c..51a68c7 100644 --- a/test/test_sink.py +++ b/test/test_sink.py @@ -3,8 +3,10 @@ import sys sys.path.append('..') +sys.path.append('mock') import unittest +from mock import Mock import simulator.sink @@ -15,7 +17,8 @@ def test_instantiation(self): """Test instantiation.""" id = "test_id" stats = {} - decoder = "decoder_object" + decoder = Mock(name="decoder_object") + decoder.block_size = Mock(return_value=100) c = simulator.sink.Sink(id, stats, decoder) self.assertEqual(c.receiver.id, id) self.assertEqual(c.receiver.decoder, decoder)