Hw3

advertisement
2011-03-30
OS 2011 – Assignment #3
Due date: 14.04.2011
TA in charge: Alperovich Sasha (sashaal@gmail.com)
Background:
Circular buffer:
A circular buffer data structure is a common method to share memory areas in a memory constrained
systems among multiple tasks, such as in the producer – consumer case.
More about circular buffers - http://en.wikipedia.org/wiki/Circular_buffer
TLV:
Many of the communication protocols we use are based on a type – length – value approach which is a
method to send packets of variable length carrying different types of data, and the reader is able to
interpret the packet correctly based on the header (type + length fields).
More about TLV - http://en.wikipedia.org/wiki/Type-length-value
Assignment:
Your assignment is to implement a Windows utility that receives data through memory mapped circular
buffer, applies some computation to the data and outputs it to a file.
The utility will simulate a simple back-end decoder that receives key and additional parameters through
command line and for each data piece it receives through the mapped memory it will decode it and
output to a file.






Utility name = Project name = ReaderDecoder
o Execution will be as follows: ReaderDecoder C:\keyfile.txt C:\outputFile.txt
You will be supplied a .h file holding the DEFINES used next
The circular buffer will hold TLV structures, consisting of
o TYPE – DWORD - writing entity number or EXIT_CODE to signal the reader to exit
o Length – DWORD – length of the value field (excluding the type and length) in bytes
o Value – data of Length bytes holding the content
MAX_CONTENT_LENGTH will represent the longest possible content
You may assume that the buffer boundary will never cut the type and the length fields (you have
to deal with the value thought)
Key – this file will hold a single line ANSI hexadecimal string that will be used to decode the TLV
content
o Result = bitwise XOR (^) between the content and the key
 In case the content is longer than the key, the key should be treated as circular,
and used more than once from its beginning (restart)
o For each content (packet) the key is restarted
1
2011-03-30









o You may assume the content length is even
Output – The decoder should output the writing entity number followed by a colon and the
decoded data to the output file as ANSI, each value in a new line.
o Use "%d : %s\n" for output formatting
Mapping –
o You should create a page file mapped memory, with parameters according to the .h file
supplied and map the file into your process with read access.
o As the memory is going to be accessed rapidly, it is reasonable to map the entire area
into the process memory.
 You may assume the SHARED_MEMORY_SIZE constant fits the region into a 32bit process address space
Synchronization
o As the writes pace (and writers count) is unknown, synchronization technique of a
semaphore will be applied to notify the reader that there is a data packet ready for
processing.
o You should create a semaphore with parameters according to the .h file supplied.
o Each time a producer (external entity – you should not implement it), finishes putting a
data packet into the circular buffer it will add 1 to the semaphore count.
o You may assume nothing regarding the producers count, yet it is not up to you to handle
the synchronization among them – if the semaphore count is N it means that N packets
are ready for your processing.
o You may assume that the writers will not override data before it's processed (it is yet
again not up to you to implement)
You shouldn’t print anything else to the console or other destinations in the NON DEBUG
(RELEASE) version of the tool, and exit immediately upon completion
o Completion = receiving a packet that carries EXIT_CODE as its' type
You may assume you have required permissions to access the files
o You may assume that the key file exists and carries a legal content
o You should override the output file in case it exists.
You may use c-library functions to deal with output, files, memory allocation etc, but the
memory mapping and the synchronization must be performed through system calls.
You are more than welcome to modify the supplied .h file to provide you more functionality, but
keep the constants intact – the same constants are being used by the writers.
In case you missed before – you implement the reader only – the course staff will implement the
writers to check your code.
Submission – according to the guidelines at the course site.
Open question – no need to implement
In this assignment you implemented a single reader multiple writers scenario (the writers had to
take care of their synchronization). In case the input data arrives at high pace and the reader becomes a
bottle neck one need to provide a multiple readers scheme. What is the problem with the current
solution? How would you overcome it (you may introduce some minor modifications to the writer as
well if required).
2
Download