├── README.md └── raptorq ├── __init__.py ├── raptorq.py ├── skel.py ├── table_5_6_t2.txt ├── tables.py └── utility.py /README.md: -------------------------------------------------------------------------------- 1 | An implementation of RaptorQ Rateless Erasure Codes as specified in [RFC 6330](http://tools.ietf.org/html/rfc6330). 2 | 3 | Please note that the current implementation code is really shitty. 4 | 5 | I'll fix it up later, and do it in a language that makes more sense for this. -------------------------------------------------------------------------------- /raptorq/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Meyermagic/RaptorQ-Python/749056987551312a4479e9853bcfc8e04e8d8dc6/raptorq/__init__.py -------------------------------------------------------------------------------- /raptorq/raptorq.py: -------------------------------------------------------------------------------- 1 | from __future__ import division 2 | #import array 3 | #from ctypes import * 4 | from math import ceil, floor 5 | import tables 6 | 7 | class FECPayloadID(object): 8 | """ 9 | FEC Payload ID 10 | http://tools.ietf.org/html/rfc6330#section-3.2 11 | """ 12 | def __init__(self, SBN, ESI): 13 | self.SBN = SBN 14 | self.ESI = ESI 15 | 16 | 17 | #FEC Encoding ID = 6 18 | 19 | class FEC_OTI(object): 20 | """ 21 | Common FEC Object Transmission Information (OTI) 22 | http://tools.ietf.org/html/rfc6330#section-3.3.2 23 | """ 24 | def __init__(self, transfer_length, symbol_size): 25 | self.F = transfer_length 26 | self.T = symbol_size 27 | 28 | class SS_FEC_OTI(object): 29 | """ 30 | Scheme-Specific FEC Object Transmission Information 31 | http://tools.ietf.org/html/rfc6330#section-3.3.3 32 | """ 33 | def __init__(self, source_block_count, sub_block_count, symbol_alignment): 34 | self.Z = source_block_count 35 | self.N = sub_block_count 36 | self.Al = symbol_alignment 37 | 38 | 39 | #The recommended setting for the input parameter Al is 4. 40 | #Note: Section 5.1.2 defines K'_max to be 56403. 41 | def get_TZN(F, WS, P_, Al, SS, K__max): 42 | #TODO: RFC6330, Section 4.3 says we need K'_max here, but then doesn't use it. 43 | T = P_ 44 | Kt = ceil(F/T) 45 | N_max = floor(T/(SS*Al)) 46 | def KL(n): 47 | """ 48 | KL(n) is the maximum K' value in Table 2 in Section 5.6 such 49 | that K' <= WS/(Al*(ceil(T/(Al*n)))) 50 | """ 51 | return tables.t2_le(WS/(Al*(ceil(T/(Al*n))))) 52 | Z = ceil(Kt/KL(N_max)) 53 | #N is the minimum n=1, ..., N_max such that ceil(Kt/Z) <= KL(n) 54 | cktz = ceil(Kt/Z) 55 | for n in range(1, N_max+1): 56 | #TODO: This, in constant time. 57 | if cktz <= KL(n): 58 | return T, Z, n 59 | assert False -------------------------------------------------------------------------------- /raptorq/skel.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | class RaptorQEncoder(object): 5 | def __init__(self): 6 | pass 7 | 8 | class RaptorQDecoder(object): 9 | def __init__(self): 10 | pass 11 | 12 | #d 13 | 14 | -------------------------------------------------------------------------------- /raptorq/table_5_6_t2.txt: -------------------------------------------------------------------------------- 1 | 10|254|7|10|17 2 | 12|630|7|10|19 3 | 18|682|11|10|29 4 | 20|293|11|10|31 5 | 26|80|11|10|37 6 | 30|566|11|10|41 7 | 32|860|11|10|43 8 | 36|267|11|10|47 9 | 42|822|11|10|53 10 | 46|506|13|10|59 11 | 48|589|13|10|61 12 | 49|87|13|10|61 13 | 55|520|13|10|67 14 | 60|159|13|10|71 15 | 62|235|13|10|73 16 | 69|157|13|10|79 17 | 75|502|17|10|89 18 | 84|334|17|10|97 19 | 88|583|17|10|101 20 | 91|66|17|10|103 21 | 95|352|17|10|107 22 | 97|365|17|10|109 23 | 101|562|17|10|113 24 | 114|5|19|10|127 25 | 119|603|19|10|131 26 | 125|721|19|10|137 27 | 127|28|19|10|139 28 | 138|660|19|10|149 29 | 140|829|19|10|151 30 | 149|900|23|10|163 31 | 153|930|23|10|167 32 | 160|814|23|10|173 33 | 166|661|23|10|179 34 | 168|693|23|10|181 35 | 179|780|23|10|191 36 | 181|605|23|10|193 37 | 185|551|23|10|197 38 | 187|777|23|10|199 39 | 200|491|23|10|211 40 | 213|396|23|10|223 41 | 217|764|29|10|233 42 | 225|843|29|10|241 43 | 236|646|29|10|251 44 | 242|557|29|10|257 45 | 248|608|29|10|263 46 | 257|265|29|10|271 47 | 263|505|29|10|277 48 | 269|722|29|10|283 49 | 280|263|29|10|293 50 | 295|999|29|10|307 51 | 301|874|29|10|313 52 | 305|160|29|10|317 53 | 324|575|31|10|337 54 | 337|210|31|10|349 55 | 341|513|31|10|353 56 | 347|503|31|10|359 57 | 355|558|31|10|367 58 | 362|932|31|10|373 59 | 368|404|31|10|379 60 | 372|520|37|10|389 61 | 380|846|37|10|397 62 | 385|485|37|10|401 63 | 393|728|37|10|409 64 | 405|554|37|10|421 65 | 418|471|37|10|433 66 | 428|641|37|10|443 67 | 434|732|37|10|449 68 | 447|193|37|10|461 69 | 453|934|37|10|467 70 | 466|864|37|10|479 71 | 478|790|37|10|491 72 | 486|912|37|10|499 73 | 491|617|37|10|503 74 | 497|587|37|10|509 75 | 511|800|37|10|523 76 | 526|923|41|10|541 77 | 532|998|41|10|547 78 | 542|92|41|10|557 79 | 549|497|41|10|563 80 | 557|559|41|10|571 81 | 563|667|41|10|577 82 | 573|912|41|10|587 83 | 580|262|41|10|593 84 | 588|152|41|10|601 85 | 594|526|41|10|607 86 | 600|268|41|10|613 87 | 606|212|41|10|619 88 | 619|45|41|10|631 89 | 633|898|43|10|647 90 | 640|527|43|10|653 91 | 648|558|43|10|661 92 | 666|460|47|10|683 93 | 675|5|47|10|691 94 | 685|895|47|10|701 95 | 693|996|47|10|709 96 | 703|282|47|10|719 97 | 718|513|47|10|733 98 | 728|865|47|10|743 99 | 736|870|47|10|751 100 | 747|239|47|10|761 101 | 759|452|47|10|773 102 | 778|862|53|10|797 103 | 792|852|53|10|811 104 | 802|643|53|10|821 105 | 811|543|53|10|829 106 | 821|447|53|10|839 107 | 835|321|53|10|853 108 | 845|287|53|10|863 109 | 860|12|53|10|877 110 | 870|251|53|10|887 111 | 891|30|53|10|907 112 | 903|621|53|10|919 113 | 913|555|53|10|929 114 | 926|127|53|10|941 115 | 938|400|53|10|953 116 | 950|91|59|10|971 117 | 963|916|59|10|983 118 | 977|935|59|10|997 119 | 989|691|59|10|1009 120 | 1002|299|59|10|1021 121 | 1020|282|59|10|1039 122 | 1032|824|59|10|1051 123 | 1050|536|59|11|1069 124 | 1074|596|59|11|1093 125 | 1085|28|59|11|1103 126 | 1099|947|59|11|1117 127 | 1111|162|59|11|1129 128 | 1136|536|59|11|1153 129 | 1152|1000|61|11|1171 130 | 1169|251|61|11|1187 131 | 1183|673|61|11|1201 132 | 1205|559|61|11|1223 133 | 1220|923|61|11|1237 134 | 1236|81|67|11|1259 135 | 1255|478|67|11|1277 136 | 1269|198|67|11|1291 137 | 1285|137|67|11|1307 138 | 1306|75|67|11|1327 139 | 1347|29|67|11|1367 140 | 1361|231|67|11|1381 141 | 1389|532|67|11|1409 142 | 1404|58|67|11|1423 143 | 1420|60|67|11|1439 144 | 1436|964|71|11|1459 145 | 1461|624|71|11|1483 146 | 1477|502|71|11|1499 147 | 1502|636|71|11|1523 148 | 1522|986|71|11|1543 149 | 1539|950|71|11|1559 150 | 1561|735|73|11|1583 151 | 1579|866|73|11|1601 152 | 1600|203|73|11|1621 153 | 1616|83|73|11|1637 154 | 1649|14|73|11|1669 155 | 1673|522|79|11|1699 156 | 1698|226|79|11|1723 157 | 1716|282|79|11|1741 158 | 1734|88|79|11|1759 159 | 1759|636|79|11|1783 160 | 1777|860|79|11|1801 161 | 1800|324|79|11|1823 162 | 1824|424|79|11|1847 163 | 1844|999|79|11|1867 164 | 1863|682|83|11|1889 165 | 1887|814|83|11|1913 166 | 1906|979|83|11|1931 167 | 1926|538|83|11|1951 168 | 1954|278|83|11|1979 169 | 1979|580|83|11|2003 170 | 2005|773|83|11|2029 171 | 2040|911|89|11|2069 172 | 2070|506|89|11|2099 173 | 2103|628|89|11|2131 174 | 2125|282|89|11|2153 175 | 2152|309|89|11|2179 176 | 2195|858|89|11|2221 177 | 2217|442|89|11|2243 178 | 2247|654|89|11|2273 179 | 2278|82|97|11|2311 180 | 2315|428|97|11|2347 181 | 2339|442|97|11|2371 182 | 2367|283|97|11|2399 183 | 2392|538|97|11|2423 184 | 2416|189|97|11|2447 185 | 2447|438|97|11|2477 186 | 2473|912|97|11|2503 187 | 2502|1|97|11|2531 188 | 2528|167|97|11|2557 189 | 2565|272|97|11|2593 190 | 2601|209|101|11|2633 191 | 2640|927|101|11|2671 192 | 2668|386|101|11|2699 193 | 2701|653|101|11|2731 194 | 2737|669|101|11|2767 195 | 2772|431|101|11|2801 196 | 2802|793|103|11|2833 197 | 2831|588|103|11|2861 198 | 2875|777|107|11|2909 199 | 2906|939|107|11|2939 200 | 2938|864|107|11|2971 201 | 2979|627|107|11|3011 202 | 3015|265|109|11|3049 203 | 3056|976|109|11|3089 204 | 3101|988|113|11|3137 205 | 3151|507|113|11|3187 206 | 3186|640|113|11|3221 207 | 3224|15|113|11|3259 208 | 3265|667|113|11|3299 209 | 3299|24|127|11|3347 210 | 3344|877|127|11|3391 211 | 3387|240|127|11|3433 212 | 3423|720|127|11|3469 213 | 3466|93|127|11|3511 214 | 3502|919|127|11|3547 215 | 3539|635|127|11|3583 216 | 3579|174|127|11|3623 217 | 3616|647|127|11|3659 218 | 3658|820|127|11|3701 219 | 3697|56|127|11|3739 220 | 3751|485|127|11|3793 221 | 3792|210|127|11|3833 222 | 3840|124|127|11|3881 223 | 3883|546|127|11|3923 224 | 3924|954|131|11|3967 225 | 3970|262|131|11|4013 226 | 4015|927|131|11|4057 227 | 4069|957|131|11|4111 228 | 4112|726|137|11|4159 229 | 4165|583|137|11|4211 230 | 4207|782|137|11|4253 231 | 4252|37|137|11|4297 232 | 4318|758|137|11|4363 233 | 4365|777|137|11|4409 234 | 4418|104|139|11|4463 235 | 4468|476|139|11|4513 236 | 4513|113|149|11|4567 237 | 4567|313|149|11|4621 238 | 4626|102|149|11|4679 239 | 4681|501|149|11|4733 240 | 4731|332|149|11|4783 241 | 4780|786|149|11|4831 242 | 4838|99|149|11|4889 243 | 4901|658|149|11|4951 244 | 4954|794|149|11|5003 245 | 5008|37|151|11|5059 246 | 5063|471|151|11|5113 247 | 5116|94|157|11|5171 248 | 5172|873|157|11|5227 249 | 5225|918|157|11|5279 250 | 5279|945|157|11|5333 251 | 5334|211|157|11|5387 252 | 5391|341|157|11|5443 253 | 5449|11|163|11|5507 254 | 5506|578|163|11|5563 255 | 5566|494|163|11|5623 256 | 5637|694|163|11|5693 257 | 5694|252|163|11|5749 258 | 5763|451|167|11|5821 259 | 5823|83|167|11|5881 260 | 5896|689|167|11|5953 261 | 5975|488|173|11|6037 262 | 6039|214|173|11|6101 263 | 6102|17|173|11|6163 264 | 6169|469|173|11|6229 265 | 6233|263|179|11|6299 266 | 6296|309|179|11|6361 267 | 6363|984|179|11|6427 268 | 6427|123|179|11|6491 269 | 6518|360|179|11|6581 270 | 6589|863|181|11|6653 271 | 6655|122|181|11|6719 272 | 6730|522|191|11|6803 273 | 6799|539|191|11|6871 274 | 6878|181|191|11|6949 275 | 6956|64|191|11|7027 276 | 7033|387|191|11|7103 277 | 7108|967|191|11|7177 278 | 7185|843|191|11|7253 279 | 7281|999|193|11|7351 280 | 7360|76|197|11|7433 281 | 7445|142|197|11|7517 282 | 7520|599|197|11|7591 283 | 7596|576|199|11|7669 284 | 7675|176|211|11|7759 285 | 7770|392|211|11|7853 286 | 7855|332|211|11|7937 287 | 7935|291|211|11|8017 288 | 8030|913|211|11|8111 289 | 8111|608|211|11|8191 290 | 8194|212|211|11|8273 291 | 8290|696|211|11|8369 292 | 8377|931|223|11|8467 293 | 8474|326|223|11|8563 294 | 8559|228|223|11|8647 295 | 8654|706|223|11|8741 296 | 8744|144|223|11|8831 297 | 8837|83|223|11|8923 298 | 8928|743|223|11|9013 299 | 9019|187|223|11|9103 300 | 9111|654|227|11|9199 301 | 9206|359|227|11|9293 302 | 9303|493|229|11|9391 303 | 9400|369|233|11|9491 304 | 9497|981|233|11|9587 305 | 9601|276|239|11|9697 306 | 9708|647|239|11|9803 307 | 9813|389|239|11|9907 308 | 9916|80|239|11|10009 309 | 10017|396|241|11|10111 310 | 10120|580|251|11|10223 311 | 10241|873|251|11|10343 312 | 10351|15|251|11|10453 313 | 10458|976|251|11|10559 314 | 10567|584|251|11|10667 315 | 10676|267|257|11|10781 316 | 10787|876|257|11|10891 317 | 10899|642|257|12|11003 318 | 11015|794|257|12|11119 319 | 11130|78|263|12|11239 320 | 11245|736|263|12|11353 321 | 11358|882|269|12|11471 322 | 11475|251|269|12|11587 323 | 11590|434|269|12|11701 324 | 11711|204|269|12|11821 325 | 11829|256|271|12|11941 326 | 11956|106|277|12|12073 327 | 12087|375|277|12|12203 328 | 12208|148|277|12|12323 329 | 12333|496|281|12|12451 330 | 12460|88|281|12|12577 331 | 12593|826|293|12|12721 332 | 12726|71|293|12|12853 333 | 12857|925|293|12|12983 334 | 13002|760|293|12|13127 335 | 13143|130|293|12|13267 336 | 13284|641|307|12|13421 337 | 13417|400|307|12|13553 338 | 13558|480|307|12|13693 339 | 13695|76|307|12|13829 340 | 13833|665|307|12|13967 341 | 13974|910|307|12|14107 342 | 14115|467|311|12|14251 343 | 14272|964|311|12|14407 344 | 14415|625|313|12|14551 345 | 14560|362|317|12|14699 346 | 14713|759|317|12|14851 347 | 14862|728|331|12|15013 348 | 15011|343|331|12|15161 349 | 15170|113|331|12|15319 350 | 15325|137|331|12|15473 351 | 15496|308|331|12|15643 352 | 15651|800|337|12|15803 353 | 15808|177|337|12|15959 354 | 15977|961|337|12|16127 355 | 16161|958|347|12|16319 356 | 16336|72|347|12|16493 357 | 16505|732|347|12|16661 358 | 16674|145|349|12|16831 359 | 16851|577|353|12|17011 360 | 17024|305|353|12|17183 361 | 17195|50|359|12|17359 362 | 17376|351|359|12|17539 363 | 17559|175|367|12|17729 364 | 17742|727|367|12|17911 365 | 17929|902|367|12|18097 366 | 18116|409|373|12|18289 367 | 18309|776|373|12|18481 368 | 18503|586|379|12|18679 369 | 18694|451|379|12|18869 370 | 18909|287|383|12|19087 371 | 19126|246|389|12|19309 372 | 19325|222|389|12|19507 373 | 19539|563|397|12|19727 374 | 19740|839|397|12|19927 375 | 19939|897|401|12|20129 376 | 20152|409|401|12|20341 377 | 20355|618|409|12|20551 378 | 20564|439|409|12|20759 379 | 20778|95|419|13|20983 380 | 20988|448|419|13|21191 381 | 21199|133|419|13|21401 382 | 21412|938|419|13|21613 383 | 21629|423|431|13|21841 384 | 21852|90|431|13|22063 385 | 22073|640|431|13|22283 386 | 22301|922|433|13|22511 387 | 22536|250|439|13|22751 388 | 22779|367|439|13|22993 389 | 23010|447|443|13|23227 390 | 23252|559|449|13|23473 391 | 23491|121|457|13|23719 392 | 23730|623|457|13|23957 393 | 23971|450|457|13|24197 394 | 24215|253|461|13|24443 395 | 24476|106|467|13|24709 396 | 24721|863|467|13|24953 397 | 24976|148|479|13|25219 398 | 25230|427|479|13|25471 399 | 25493|138|479|13|25733 400 | 25756|794|487|13|26003 401 | 26022|247|487|13|26267 402 | 26291|562|491|13|26539 403 | 26566|53|499|13|26821 404 | 26838|135|499|13|27091 405 | 27111|21|503|13|27367 406 | 27392|201|509|13|27653 407 | 27682|169|521|13|27953 408 | 27959|70|521|13|28229 409 | 28248|386|521|13|28517 410 | 28548|226|523|13|28817 411 | 28845|3|541|13|29131 412 | 29138|769|541|13|29423 413 | 29434|590|541|13|29717 414 | 29731|672|541|13|30013 415 | 30037|713|547|13|30323 416 | 30346|967|547|13|30631 417 | 30654|368|557|14|30949 418 | 30974|348|557|14|31267 419 | 31285|119|563|14|31583 420 | 31605|503|569|14|31907 421 | 31948|181|571|14|32251 422 | 32272|394|577|14|32579 423 | 32601|189|587|14|32917 424 | 32932|210|587|14|33247 425 | 33282|62|593|14|33601 426 | 33623|273|593|14|33941 427 | 33961|554|599|14|34283 428 | 34302|936|607|14|34631 429 | 34654|483|607|14|34981 430 | 35031|397|613|14|35363 431 | 35395|241|619|14|35731 432 | 35750|500|631|14|36097 433 | 36112|12|631|14|36457 434 | 36479|958|641|14|36833 435 | 36849|524|641|14|37201 436 | 37227|8|643|14|37579 437 | 37606|100|653|14|37967 438 | 37992|339|653|14|38351 439 | 38385|804|659|14|38749 440 | 38787|510|673|14|39163 441 | 39176|18|673|14|39551 442 | 39576|412|677|14|39953 443 | 39980|394|683|14|40361 444 | 40398|830|691|15|40787 445 | 40816|535|701|15|41213 446 | 41226|199|701|15|41621 447 | 41641|27|709|15|42043 448 | 42067|298|709|15|42467 449 | 42490|368|719|15|42899 450 | 42916|755|727|15|43331 451 | 43388|379|727|15|43801 452 | 43840|73|733|15|44257 453 | 44279|387|739|15|44701 454 | 44729|457|751|15|45161 455 | 45183|761|751|15|45613 456 | 45638|855|757|15|46073 457 | 46104|370|769|15|46549 458 | 46574|261|769|15|47017 459 | 47047|299|787|15|47507 460 | 47523|920|787|15|47981 461 | 48007|269|787|15|48463 462 | 48489|862|797|15|48953 463 | 48976|349|809|15|49451 464 | 49470|103|809|15|49943 465 | 49978|115|821|15|50461 466 | 50511|93|821|16|50993 467 | 51017|982|827|16|51503 468 | 51530|432|839|16|52027 469 | 52062|340|853|16|52571 470 | 52586|173|853|16|53093 471 | 53114|421|857|16|53623 472 | 53650|330|863|16|54163 473 | 54188|624|877|16|54713 474 | 54735|233|877|16|55259 475 | 55289|362|883|16|55817 476 | 55843|963|907|16|56393 477 | 56403|471|907|16|56951 -------------------------------------------------------------------------------- /raptorq/tables.py: -------------------------------------------------------------------------------- 1 | from __future__ import with_statement 2 | import csv 3 | import bisect 4 | 5 | 6 | #Section 5.6, Table 2 7 | # K' -> (J(K'), S(K'), H(K'), W(K')) 8 | def load_56t2(): 9 | table_data = dict() 10 | with open('table_5_6_t2.txt', 'rb') as f: 11 | reader = csv.reader(f, delimiter='|') 12 | for row in reader: 13 | table_data[int(row[0])] = (int(row[1]), int(row[2]), int(row[3]), int(row[4])) 14 | return table_data 15 | 16 | table_2 = load_56t2() 17 | sorted_keys = sorted(table_2.keys()) 18 | 19 | def t2_le(k): 20 | i = bisect.bisect_right(sorted_keys, k) 21 | return sorted_keys[i-1] 22 | 23 | def J(K_): 24 | return table_2[K_][0] 25 | 26 | def S(K_): 27 | return table_2[K_][1] 28 | 29 | def H(K_): 30 | return table_2[K_][2] 31 | 32 | def W(K_): 33 | return table_2[K_][3] 34 | -------------------------------------------------------------------------------- /raptorq/utility.py: -------------------------------------------------------------------------------- 1 | #from collections import OrderedDict 2 | #import bitarray 3 | # 4 | # 5 | #class BitStruct(object): 6 | # """ 7 | # A Python Class for storing arbitrary-sized (in number of bits) fields in a bit array. 8 | # """ 9 | # def __init__(self, fields, values): 10 | # """ 11 | # Fields is a list of 2-tuples, [("field name", number of bits), ...] 12 | # """ 13 | # fields = OrderedDict(fields) 14 | # values = OrderedDict(values) 15 | # def __getitem__(self, item): 16 | # return values[item] --------------------------------------------------------------------------------