1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445
|
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author : Richard GAYRAUD - 04 Nov 2003
* Marc LAMBERTON
* Olivier JACQUES
* From Hewlett Packard Company.
* F. Tarek Rogers
* Peter Higginson
* Vincent Luba
*/
#define GLOBALS_FULL_DEFINITION
#include "sipp.hpp"
#ifdef _USE_OPENSSL
SSL_CTX *sip_trp_ssl_ctx = NULL; /* For SSL cserver context */
SSL_CTX *sip_trp_ssl_ctx_client = NULL; /* For SSL cserver context */
SSL_CTX *twinSipp_sip_trp_ssl_ctx_client = NULL; /* For SSL cserver context */
#define CALL_BACK_USER_DATA "ksgr"
/*
** passwd_call_back_routine implementation
**
*/
int
passwd_call_back_routine(char *buf , int size , int flag, void *passwd)
{
strncpy(buf, (char *)(passwd), size);
buf[size - 1] = '\0';
return(strlen(buf));
}
#endif
/***************** System Portability Features *****************/
unsigned int getmilliseconds()
{
struct timeval LS_system_time;
unsigned long long int VI_milli;
static unsigned long long int VI_milli_base = 0;
gettimeofday(&LS_system_time, NULL);
VI_milli = ((unsigned long long) LS_system_time.tv_sec)
* 1000LL + (LS_system_time.tv_usec / 1000LL);
if (!VI_milli_base) VI_milli_base = VI_milli - 1;
VI_milli = VI_milli - VI_milli_base;
return (unsigned int) VI_milli;
}
#ifdef _USE_OPENSSL
int send_nowait_tls(SSL *ssl, const void *msg, int len, int flags)
{
int initial_fd_flags;
int rc;
int fd;
int fd_flags;
if ( (fd = SSL_get_fd(ssl)) == -1 ) {
return (-1);
}
fd_flags = fcntl(fd, F_GETFL , NULL);
initial_fd_flags = fd_flags;
fd_flags |= O_NONBLOCK;
fcntl(fd, F_SETFL , fd_flags);
rc = SSL_write(ssl,msg,len);
if ( rc <= 0 ) {
return(rc);
}
fcntl(fd, F_SETFL , initial_fd_flags);
return rc;
}
#endif
int send_nowait(int s, const void *msg, int len, int flags)
{
#ifdef MSG_DONTWAIT
return send(s, msg, len, flags | MSG_DONTWAIT);
#else
int fd_flags = fcntl(s, F_GETFL , NULL);
int initial_fd_flags;
int rc;
initial_fd_flags = fd_flags;
// fd_flags &= ~O_ACCMODE; // Remove the access mode from the value
fd_flags |= O_NONBLOCK;
fcntl(s, F_SETFL , fd_flags);
rc = send(s, msg, len, flags);
fcntl(s, F_SETFL , initial_fd_flags);
return rc;
#endif
}
char * get_inet_address(struct sockaddr_storage * addr)
{
static char * ip_addr = NULL;
int res;
if (!ip_addr) {
ip_addr = (char *)malloc(1024*sizeof(char));
}
if (getnameinfo(_RCAST(struct sockaddr *, addr),
sizeof(struct sockaddr),
ip_addr,
1024,
NULL,
0,
NI_NUMERICHOST) != 0) {
strcpy(ip_addr, "addr not supported");
}
return ip_addr;
}
void get_host_and_port(char * addr, char * host, int * port)
{
/* Separate the port number (if any) from the host name.
* Thing is, the separator is a colon (':'). The colon may also exist
* in the host portion if the host is specified as an IPv6 address (see
* RFC 2732). If that's the case, then we need to skip past the IPv6
* address, which should be contained within square brackets ('[',']').
*/
char *p;
p = strchr( addr, '[' ); /* Look for '['. */
if( p != NULL ) { /* If found, look for ']'. */
p = strchr( p, ']' );
}
if( p == NULL ) { /* If '['..']' not found, */
p = addr; /* scan the whole string. */
} else { /* If '['..']' found, */
char *p1; /* extract the remote_host */
char *p2;
p1 = strchr( addr, '[' );
p2 = strchr( addr, ']' );
*p2 = '\0';
strcpy(host, p1 + 1);
}
/* Starting at <p>, which is either the start of the host substring
* or the end of the IPv6 address, find the last colon character.
*/
p = strchr( p, ':' );
if( NULL != p ) {
*p = '\0';
*port = atol(p + 1);
} else {
*port = 0;
}
}
char * strcasestr2(char *s, char *find) {
char c, sc;
size_t len;
if ((c = *find++) != 0) {
c = tolower((unsigned char)c);
len = strlen(find);
do {
do {
if ((sc = *s++) == 0)
return (NULL);
} while ((char)tolower((unsigned char)sc) != c);
} while (strncasecmp(s, find, len) != 0);
s--;
}
return ((char *)s);
}
/******************** Recv Poll Processing *********************/
int pollnfds;
struct pollfd pollfiles[SIPP_MAXFDS];
call * pollcalls[SIPP_MAXFDS];
#ifdef _USE_OPENSSL
SSL * ssl_list[SIPP_MAXFDS];
#endif
/***************** Check of the message received ***************/
bool sipMsgCheck (char *P_msg, int P_msgSize
#ifdef __3PCC__
,int P_pollSetIdx
#endif
) {
const char C_sipHeader[] = "SIP/2.0" ;
#ifdef __3PCC__
if (pollfiles[P_pollSetIdx].fd == twinSippSocket) {
return true ;
} else {
#endif // __3PCC__
if (strstr(P_msg, C_sipHeader) != NULL) {
return true ;
}
return false ;
#ifdef __3PCC__
}
#endif // __3PCC__
}
void pollset_reset()
{
pollnfds = 0;
memset((void *)pollfiles,0,SIPP_MAXFDS*sizeof(struct pollfd));
pollfiles[pollnfds].fd = main_socket;
pollfiles[pollnfds].events = POLLIN | POLLERR;
pollfiles[pollnfds].revents = 0;
pollcalls[pollnfds] = NULL;
pollnfds++;
if(tcp_multiplex) {
/* Adds the TCP multiplex in the file descriptor array */
pollfiles[pollnfds].fd = tcp_multiplex;
pollfiles[pollnfds].events = POLLIN | POLLERR;
pollfiles[pollnfds].revents = 0;
pollcalls[pollnfds] = NULL;
pollnfds++;
}
#ifdef __3PCC__
if(twinSippSocket) {
/* Adds the twinSippSocket */
pollfiles[pollnfds].fd = twinSippSocket;
pollfiles[pollnfds].events = POLLIN | POLLERR;
pollfiles[pollnfds].revents = 0;
pollcalls[pollnfds] = NULL;
pollnfds++;
}
if(localTwinSippSocket) {
/* Adds the twinSippSocket */
pollfiles[pollnfds].fd = localTwinSippSocket;
pollfiles[pollnfds].events = POLLIN | POLLERR;
pollfiles[pollnfds].revents = 0;
pollcalls[pollnfds] = NULL;
pollnfds++;
}
#endif
}
int pollset_add(call * p_call, int sock)
{
// WARNING_P2("Adding socket %d at idx = %d", sock, pollnfds);
pollfiles[pollnfds].fd = sock;
pollfiles[pollnfds].events = POLLIN | POLLERR;
pollfiles[pollnfds].revents = 0;
pollcalls[pollnfds] = p_call;
pollnfds++;
return pollnfds - 1;
}
void pollset_remove(int idx)
{
if(idx >= pollnfds) {
ERROR("Pollset error");
}
/* Adds call sockets in the array */
if(pollnfds) {
// WARNING_P2("Removing socket %d at idx = %d", pollfiles[idx].fd, idx);
pollnfds--;
pollfiles[idx] = pollfiles[pollnfds];
pollcalls[idx] = pollcalls[pollnfds];
if((pollcalls[idx]) && (pollcalls[idx] -> pollset_index)) {
pollcalls[idx] -> pollset_index = idx;
}
} else {
ERROR("Pollset underflow");
}
}
/************** Statistics display & User control *************/
void print_stats_in_file(FILE * f, int last)
{
int index;
static char temp_str[256];
int divisor;
#define SIPP_ENDL "\r\n"
/* Optional timestamp line for files only */
if(f != stdout) {
time_t tim;
time(&tim);
fprintf(f, " Timestamp: %s" SIPP_ENDL, ctime(&tim));
}
/* Header line with global parameters */
sprintf(temp_str, "%3.1f(%d ms)/%5.3fs", rate, duration, rate_period_s);
if( toolMode == MODE_SERVER) {
fprintf
(f,
" Port Total-time Total-calls Transport"
SIPP_ENDL
" %-5d %6d.%02d s %8d %s"
SIPP_ENDL SIPP_ENDL,
local_port,
clock_tick / 1000, (clock_tick % 1000) / 10,
total_calls,
TRANSPORT_TO_STRING(transport));
} else {
fprintf
(f,
" Call-rate(length) Port Total-time Total-calls Remote-host"
SIPP_ENDL
"%19s %-5d %6d.%02d s %8d %s:%d(%s)"
SIPP_ENDL SIPP_ENDL,
temp_str,
local_port,
clock_tick / 1000, (clock_tick % 1000) / 10,
total_calls,
remote_ip,
remote_port,
TRANSPORT_TO_STRING(transport));
}
/* 1st line */
if(total_calls < stop_after) {
sprintf(temp_str, "%d new calls during %d.%03d s period ",
total_calls - last_report_calls,
(clock_tick-last_report_time) / 1000,
((clock_tick-last_report_time) % 1000));
} else {
sprintf(temp_str, "Call limit reached (-m %d), %d.%03d s period ",
stop_after,
(clock_tick-last_report_time) / 1000,
((clock_tick-last_report_time) % 1000));
}
divisor = scheduling_loops; if(!divisor) { divisor = 1; }
fprintf(f," %-38s %d ms scheduler resolution"
SIPP_ENDL,
temp_str,
(clock_tick-last_report_time) / divisor);
/* 2nd line */
if( toolMode == MODE_SERVER) {
sprintf(temp_str, "%d concurrent calls", open_calls);
} else {
sprintf(temp_str,
"%d concurrent calls (limit %d)",
open_calls,
open_calls_allowed);
}
fprintf(f," %-38s Peak was %d calls, after %d s" SIPP_ENDL,
temp_str,
open_calls_peak,
open_calls_peak_time);
/* 3rd line (optional) */
if( toolMode != MODE_SERVER) {
sprintf(temp_str,"%d out-of-call msg (discarded)",
nb_out_of_the_blue);
fprintf(f," %-37s", temp_str);
}
if(compression) {
fprintf(f," Comp resync: %d sent, %d recv" ,
resynch_send, resynch_recv);
}
if(compression || (toolMode != MODE_SERVER)) {
fprintf(f,SIPP_ENDL);
}
/* 4th line , sockets and optional errors */
sprintf(temp_str,"%d open sockets",
pollnfds);
fprintf(f," %-38s", temp_str);
if(nb_net_recv_errors || nb_net_send_errors || nb_net_cong) {
fprintf(f," %d/%d/%d %s errors (send/recv/cong)" SIPP_ENDL,
nb_net_send_errors,
nb_net_recv_errors,
nb_net_cong,
TRANSPORT_TO_STRING(transport));
} else {
fprintf(f,SIPP_ENDL);
}
/* 5th line, RTP echo statistics */
if (media_socket > 0) {
sprintf(temp_str, "%d Total echo RTP pckts",
rtp_pckts);
// AComment: Fix for random coredump when using RTP echo
if (clock_tick-last_report_time) {
fprintf(f," %-38s %d.%03d last period RTP rate (kB/s)" SIPP_ENDL,
temp_str,
(rtp_bytes)/(clock_tick-last_report_time),
(rtp_bytes)%(clock_tick-last_report_time));
}
rtp_bytes = 0;
}
/* Scenario counters */
fprintf(f,SIPP_ENDL);
if(!lose_packets) {
fprintf(f," "
"Messages Retrans Timeout Unexpected-Msg"
SIPP_ENDL);
} else {
fprintf(f," "
"Messages Retrans Timeout Unexp. Lost"
SIPP_ENDL);
}
for(index = 0;
index < scenario_len;
index ++) {
if(scenario[index] -> send_scheme) {
char *dest, *src;
int len;
dest = temp_str;
src = scenario[index] -> send_scheme;
if( strncmp(src, "SIP/2.0", 7) == 0) {
src += 8;
}
while((*src) && (*src != ' ') && (*src != '\t') && (*src != '\n')) {
*dest++ = *src ++;
}
*dest = 0;
if(toolMode == MODE_SERVER) {
fprintf(f," <---------- %-10s %-8s",
temp_str,
scenario[index] -> start_rtd ?
"B-RTD" :
scenario[index] -> stop_rtd ? "E-RTD" : "");
} else {
fprintf(f," %10s ----------> %-8s",
temp_str,
scenario[index] -> start_rtd ?
"B-RTD" :
scenario[index] -> stop_rtd ? "E-RTD" : "");
}
if(scenario[index] -> retrans_delay) {
fprintf(f,"%-9d %-9d %-9d" ,
scenario[index] -> nb_sent,
scenario[index] -> nb_sent_retrans,
scenario[index] -> nb_timeout);
} else {
fprintf(f,"%-9d %-9d " ,
scenario[index] -> nb_sent,
scenario[index] -> nb_sent_retrans);
}
} else if(scenario[index] -> recv_response) {
if(toolMode == MODE_SERVER) {
fprintf(f," ----------> %-10d %-8s",
scenario[index] -> recv_response,
scenario[index] -> start_rtd ?
"B-RTD" :
scenario[index] -> stop_rtd ? "E-RTD" : "");
} else {
fprintf(f," %10d <---------- %-8s",
scenario[index] -> recv_response,
scenario[index] -> start_rtd ?
"B-RTD" :
scenario[index] -> stop_rtd ? "E-RTD" : "");
}
if(toolMode == MODE_SERVER) {
fprintf(f,"%-9d %-9d %-9d" ,
scenario[index] -> nb_recv,
scenario[index] -> nb_recv_retrans,
scenario[index] -> nb_unexp);
} else {
fprintf(f,"%-9d %-9d %-9d" ,
scenario[index] -> nb_recv,
scenario[index] -> nb_recv_retrans,
scenario[index] -> nb_unexp);
}
} else if (scenario[index] -> pause) {
int pause;
if(scenario[index] -> pause < 0) {
pause = duration;
} else {
pause = scenario[index] -> pause;
}
if(toolMode == MODE_SERVER) {
fprintf(f," [%6d ms]", pause);
} else {
fprintf(f," [%6d ms]", pause);
}
} else if(scenario[index] -> recv_request) {
if(toolMode == MODE_SERVER) {
fprintf(f," ----------> %-10s %-8s",
scenario[index] -> recv_request,
scenario[index] -> start_rtd ?
"B-RTD" :
scenario[index] -> stop_rtd ? "E-RTD" : "");
} else {
fprintf(f," %10s <---------- %-8s",
scenario[index] -> recv_request,
scenario[index] -> start_rtd ?
"B-RTD" :
scenario[index] -> stop_rtd ? "E-RTD" : "");
}
fprintf(f,"%-9d %-9d %-9d" ,
scenario[index] -> nb_recv,
scenario[index] -> nb_recv_retrans,
scenario[index] -> nb_unexp);
}
#ifdef __3PCC__
else if(scenario[index] -> M_type == MSG_TYPE_RECVCMD) {
fprintf(f," [ Received Command ] ");
fprintf(f,"%-9d %-9s %-9s" ,
scenario[index] -> M_nbCmdRecv,
"",
"");
} else if(scenario[index] -> M_type == MSG_TYPE_SENDCMD) {
fprintf(f," [ Sent Command ] ");
fprintf(f,"%-9d %-9s %-9s" ,
scenario[index] -> M_nbCmdSent,
"",
"");
}
#endif
else {
ERROR("Not Implemented\n");
}
if(lose_packets && (scenario[index] -> nb_lost)) {
fprintf(f," %-9d" SIPP_ENDL,
scenario[index] -> nb_lost);
} else {
fprintf(f,SIPP_ENDL);
}
if(scenario[index] -> crlf) {
fprintf(f,SIPP_ENDL);
}
}
}
void print_header_line(FILE *f, int last)
{
switch(currentScreenToDisplay)
{
case DISPLAY_STAT_SCREEN :
fprintf(f,"----------------------------- Statistics Screen ------- [1-4]: Change Screen --" SIPP_ENDL);
break;
case DISPLAY_REPARTITION_SCREEN :
fprintf(f,"---------------------------- Repartition Screen ------- [1-4]: Change Screen --" SIPP_ENDL);
break;
case DISPLAY_VARIABLE_SCREEN :
fprintf(f,"----------------------------- Variables Screen -------- [1-4]: Change Screen --" SIPP_ENDL);
break;
case DISPLAY_SCENARIO_SCREEN :
default:
fprintf(f,"------------------------------ Scenario Screen -------- [1-4]: Change Screen --" SIPP_ENDL);
break;
}
}
void print_bottom_line(FILE *f, int last)
{
if(last) {
fprintf(f,"------------------------------ Test Terminated --------------------------------" SIPP_ENDL);
} else if(quitting) {
fprintf(f,"------- Waiting for active calls to end. Press [Ctrl-c] to force exit. --------" SIPP_ENDL );
} else if(paused) {
fprintf(f,"----------------- Traffic Paused - Press [p] again to resume ------------------" SIPP_ENDL );
} else if(cpu_max) {
fprintf(f,"-------------------------------- CPU CONGESTED ---------------------------------" SIPP_ENDL);
} else {
switch(toolMode)
{
case MODE_SERVER :
fprintf(f,"------------------------------ Sipp Server Mode -------------------------------" SIPP_ENDL);
break;
#ifdef __3PCC__
case MODE_3PCC_CONTROLLER_B :
fprintf(f,"----------------------- 3PCC Mode - Controller B side -------------------------" SIPP_ENDL);
break;
case MODE_3PCC_A_PASSIVE :
fprintf(f,"------------------ 3PCC Mode - Controller A side (passive) --------------------" SIPP_ENDL);
break;
case MODE_3PCC_CONTROLLER_A :
fprintf(f,"----------------------- 3PCC Mode - Controller A side -------------------------" SIPP_ENDL);
break;
#endif
case MODE_CLIENT :
default:
fprintf(f,"------ [+|-|*|/]: Adjust rate ---- [q]: Soft exit ---- [p]: Pause traffic -----" SIPP_ENDL);
break;
}
}
fprintf(f,SIPP_ENDL);
fflush(stdout);
}
void print_variable_list()
{
CActions * actions;
CAction * action;
CVariable * variable;
int i;
bool found;
printf("Action defined Per Message :" SIPP_ENDL);
found = false;
for(i=0; i<scenario_len; i++)
{
actions = scenario[i]->M_actions;
if(actions != NULL)
{
switch(scenario[i]->M_type)
{
case MSG_TYPE_RECV:
printf("=> Message[%d] (Receive Message) - "
"[%d] action(s) defined :" SIPP_ENDL,
i,
actions->getUsedAction());
break;
#ifdef __3PCC__
case MSG_TYPE_RECVCMD:
printf("=> Message[%d] (Receive Command Message) - "
"[%d] action(s) defined :" SIPP_ENDL,
i,
actions->getUsedAction());
break;
#endif
default:
printf("=> Message[%d] - [%d] action(s) defined :" SIPP_ENDL,
i,
actions->getUsedAction());
break;
}
for(int j=0; j<actions->getUsedAction(); j++)
{
action = actions->getAction(j);
if(action != NULL)
{
printf(" --> action[%d] = ", j);
action->afficheInfo();
printf(SIPP_ENDL);
found = true;
}
}
}
}
if(!found) printf("=> No action found on any messages"SIPP_ENDL);
printf(SIPP_ENDL);
printf("Setted Variable List:" SIPP_ENDL);
found = false;
for(i=0; i<SCEN_VARIABLE_SIZE; i++)
{
variable = scenVariableTable[i];
if(variable != NULL)
{
printf("=> Variable[%d] : setted regExp[%s]" SIPP_ENDL,
i,
variable->getRegularExpression());
found = true;
}
}
if(!found) printf("=> No variable found for this scenario"SIPP_ENDL);
}
/* Function to dump all available screens in a file */
void print_screens(void)
{
int oldScreen = currentScreenToDisplay;
currentScreenToDisplay = DISPLAY_SCENARIO_SCREEN;
print_header_line( screenf, 0);
print_stats_in_file( screenf, 0);
print_bottom_line( screenf, 0);
currentScreenToDisplay = DISPLAY_STAT_SCREEN;
print_header_line( screenf, 0);
CStat::instance()->displayStat(screenf);
print_bottom_line( screenf, 0);
currentScreenToDisplay = DISPLAY_REPARTITION_SCREEN;
print_header_line( screenf, 0);
CStat::instance()->displayRepartition(screenf);
print_bottom_line( screenf, 0);
currentScreenToDisplay = oldScreen;
}
void print_statistics(int last)
{
static int first = 1;
if(backgroundMode == false) {
if(!last) {
screen_clear();
}
if(first) {
first = 0;
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
}
print_header_line(stdout,last);
switch(currentScreenToDisplay) {
case DISPLAY_STAT_SCREEN :
CStat::instance()->displayStat(stdout);
break;
case DISPLAY_REPARTITION_SCREEN :
CStat::instance()->displayRepartition(stdout);
break;
case DISPLAY_VARIABLE_SCREEN :
print_variable_list();
break;
case DISPLAY_SCENARIO_SCREEN :
default:
print_stats_in_file(stdout, last);
break;
}
print_bottom_line(stdout,last);
if(last) { fprintf(stdout,"\n"); }
}
}
void set_rate(double new_rate)
{
double L_temp ;
if(toolMode == MODE_SERVER) {
rate = 0;
open_calls_allowed = 0;
}
rate = new_rate;
if(rate < 0) {
rate = 0;
}
last_rate_change_time = clock_tick;
calls_since_last_rate_change = 0;
if(!open_calls_user_setting) {
int call_duration_min = scenario_duration;
if(duration > call_duration_min) call_duration_min = duration;
if(call_duration_min < 1000) call_duration_min = 1000;
L_temp = (3 * rate * call_duration_min) / rate_period_s / 1000 ;
open_calls_allowed = (unsigned int) L_temp ;
}
}
void sipp_sigusr1(int /* not used */)
{
/* Smooth exit: do not place any new calls and exit */
quitting = 1;
}
void sipp_sigusr2(int /* not used */)
{
if (!signalDump) {
signalDump = true ;
}
}
/* User interface thread */
void keyb_thread (void * param)
{
int c;
while(!feof(stdin)){
c = screen_readkey();
switch (c) {
case '1':
currentScreenToDisplay = DISPLAY_SCENARIO_SCREEN;
print_statistics(0);
break;
case '2':
currentScreenToDisplay = DISPLAY_STAT_SCREEN;
print_statistics(0);
break;
case '3':
currentScreenToDisplay = DISPLAY_REPARTITION_SCREEN;
print_statistics(0);
break;
case '4':
currentScreenToDisplay = DISPLAY_VARIABLE_SCREEN;
print_statistics(0);
break;
case '+':
set_rate(rate + 1);
print_statistics(0);
break;
case '-':
set_rate(rate - 1);
print_statistics(0);
break;
case '*':
set_rate(rate + 10);
print_statistics(0);
break;
case '/':
set_rate(rate - 10);
print_statistics(0);
break;
case 'p':
if(paused) {
paused = 0;
set_rate(rate);
} else {
paused = 1;
}
print_statistics(0);
break;
case 'q':
quitting = 1;
print_statistics(0);
return;
}
}
}
/*************************** Mini SIP parser ***************************/
char * get_peer_tag(char *msg)
{
char * to_hdr;
char * ptr;
char * end_ptr;
static char tag[MAX_HEADER_LEN];
int tag_i = 0;
to_hdr = strstr(msg, "To:");
if(!to_hdr) to_hdr = strstr(msg, "to:");
if(!to_hdr) to_hdr = strstr(msg, "TO:");
if(!to_hdr) {
ERROR("No valid To: header in reply");
}
end_ptr = strchr(to_hdr,'\n');
ptr = strchr(to_hdr, '>');
if (!ptr) {
return NULL;
}
ptr = strchr(to_hdr, ';');
if(!ptr) {
return NULL;
}
to_hdr = ptr;
ptr = strstr(to_hdr, "tag");
if(!ptr) { ptr = strstr(to_hdr, "TAG"); }
if(!ptr) { ptr = strstr(to_hdr, "Tag"); }
if(!ptr) {
return NULL;
}
if (ptr>end_ptr) {
return NULL ;
}
ptr = strchr(ptr, '=');
if(!ptr) {
ERROR("Invalid tag param in To: header");
}
ptr ++;
while((*ptr) &&
(*ptr != ' ') &&
(*ptr != ';') &&
(*ptr != '\t') &&
(*ptr != '\t') &&
(*ptr != '\r') &&
(*ptr != '\n') &&
(*ptr)) {
tag[tag_i++] = *(ptr++);
}
tag[tag_i] = 0;
return tag;
}
char * get_call_id(char *msg)
{
static char call_id[MAX_HEADER_LEN];
char * ptr1, * ptr2, backup;
ptr1 = strstr(msg, "Call-ID:");
if(!ptr1) { ptr1 = strstr(msg, "Call-Id:"); }
if(!ptr1) { ptr1 = strstr(msg, "Call-id:"); }
if(!ptr1) { ptr1 = strstr(msg, "call-Id:"); }
if(!ptr1) { ptr1 = strstr(msg, "call-id:"); }
if(!ptr1) { ptr1 = strstr(msg, "CALL-ID:"); }
if(!ptr1) { ERROR_P1("(1) No valid Call-ID: header in reply '%s'", msg); }
ptr1 += 8;
while((*ptr1 == ' ') || (*ptr1 == '\t')) { ptr1++; }
if(!(*ptr1)) { ERROR("(2) No valid Call-ID: header in reply"); }
ptr2 = ptr1;
while((*ptr2) &&
(*ptr2 != ' ') &&
(*ptr2 != '\t') &&
(*ptr2 != '\r') &&
(*ptr2 != '\n')) {
ptr2 ++;
}
if(!*ptr2) { ERROR("(3) No valid Call-ID: header in reply"); }
backup = *ptr2;
*ptr2 = 0;
strcpy(call_id, ptr1);
*ptr2 = backup;
return (char *) call_id;
}
unsigned long get_reply_code(char *msg)
{
while((*msg != ' ') && (*msg != '\t')) msg ++;
while((*msg == ' ') || (*msg == '\t')) msg ++;
return atol(msg);
}
/*************************** I/O functions ***************************/
#ifdef _USE_OPENSSL
int recv_all_tls(SSL *ssl, char *buffer, int size, int trace_id)
{
int recv_size = 0;
char * start_buffer = buffer;
int to_be_recvd = size;
int part_size ;
recv_size = SSL_read(ssl,buffer, size);
if(recv_size <= 0) {
if(recv_size != 0) {
nb_net_recv_errors++;
WARNING_P3("TLS %d Recv error : size = %d,Dummy : %d ",
trace_id, recv_size, trace_id);
} else {
/* This is normal for a server to have its client close
* the connection */
if(toolMode != MODE_SERVER) {
WARNING_P3("TLS %d Recv error : size = %d, dummy : %d "
"remote host closed connection",
trace_id, recv_size,trace_id);
nb_net_recv_errors++;
}
}
}
return recv_size;
}
#endif
int recv_all_tcp(int sock, char *buffer, int size, int trace_id)
{
int recv_size = 0;
char * start_buffer = buffer;
int to_be_recvd = size;
int part_size ;
do {
part_size = recv(sock, start_buffer, to_be_recvd, 0);
if(part_size > 0) {
to_be_recvd -= part_size;
start_buffer += part_size;
recv_size += part_size;
} else {
recv_size = part_size;
}
} while((part_size > 0) && to_be_recvd);
if(recv_size <= 0) {
if(recv_size != 0) {
nb_net_recv_errors++;
WARNING_P3("TCP %d Recv error : size = %d, sock = %d",
trace_id, recv_size, sock);
WARNING_NO("TCP Recv error");
// ERROR_NO("TCP recv error");
} else {
#ifdef __3PCC__
if (toolMode == MODE_3PCC_CONTROLLER_B) {
/* In 3PCC controller B mode, twin socket is closed at peer closing.
* This is a normal case: 3PCC controller B should end now */
ERROR("3PCC controller A has ended -> exiting");
} else
#endif
/* This is normal for a server to have its client close
* the connection */
if(toolMode != MODE_SERVER) {
WARNING_P3("TCP %d Recv error : size = %d, sock = %d, "
"remote host closed connection",
trace_id, recv_size, sock);
#ifdef __3PCC__
if(sock == twinSippSocket || sock == localTwinSippSocket) {
int L_poll_idx = 0 ;
quitting = 1;
for((L_poll_idx) = 0;
(L_poll_idx) < pollnfds;
(L_poll_idx)++) {
if(pollfiles[L_poll_idx].fd == twinSippSocket) {
pollset_remove(L_poll_idx);
}
if(pollfiles[L_poll_idx].fd == localTwinSippSocket) {
pollset_remove(L_poll_idx);
}
}
if(twinSippSocket) {
shutdown(twinSippSocket, SHUT_RDWR);
close(twinSippSocket);
twinSippSocket = 0 ;
}
if(localTwinSippSocket) {
shutdown(localTwinSippSocket, SHUT_RDWR);
close(localTwinSippSocket);
localTwinSippSocket = 0 ;
}
}
#endif
nb_net_recv_errors++;
}
}
}
return recv_size;
}
#ifdef _USE_OPENSSL
int recv_tls_message(SSL * ssl,
char *buffer,
int buffer_size,
E_Alter_YesNo alter_msg)
{
int len = 0;
int recv_size;
char * ctl_hdr;
int content_length;
len = recv_size = recv_all_tls(ssl, buffer, buffer_size, 1);
if(recv_size <= 0) {
return recv_size;
}
if(len >= buffer_size) {
ERROR("TLS msg too big");
}
buffer[len] = 0;
return len;
}
#endif
int recv_tcp_message(int sock,
char *buffer,
int buffer_size,
E_Alter_YesNo alter_msg,
E_Alter_YesNo isControlMsg = E_ALTER_NO)
{
int len = 0;
int recv_size;
char * ctl_hdr;
int content_length;
// Try to read SIP Header Message only
// or CMD Message
while(1) {
// Read one char on tcp socket
recv_size = recv_all_tcp(sock, &(buffer[len]), 1, 1);
// Check read problem return
if(recv_size <= 0) {
return recv_size;
}
len++;
// Search the end Message condition
if (isControlMsg == E_ALTER_NO) {
// In case of SIP Message \r\n follow by
// \r\n is header end
if((buffer[len-1] == '\n') &&
(buffer[len-2] == '\r') &&
(buffer[len-3] == '\n') &&
(buffer[len-4] == '\r')) {
/* CRLF CRLF Detected */
buffer[len] = 0;
break;
}
}
else
{
// In case of CMD Message
// escape char is the end of message
if((alter_msg==E_ALTER_NO) &&
(buffer[len-1] == 27)) {
/* End delimitor detected, stop receiving */
buffer[len-1] = 0;
return (len - 1);
}
}
}
if(len >= buffer_size) {
ERROR("TCP msg too big");
}
// Now search the content length of the body
// part of SIP or CMD Message
ctl_hdr = strstr(buffer, "Content-Length:");
if(!ctl_hdr) ctl_hdr = strstr(buffer, "Content-length:");
if(!ctl_hdr) ctl_hdr = strstr(buffer, "content-Length:");
if(!ctl_hdr) ctl_hdr = strstr(buffer, "content-length:");
if(!ctl_hdr) ctl_hdr = strstr(buffer, "CONTENT-LENGTH:");
// Content Length was found
// Read its value
if((ctl_hdr) && (alter_msg==E_ALTER_YES)) {
ctl_hdr += 15;
content_length = atoi(ctl_hdr);
} else {
content_length = 0;
}
// If a body exist read it
if(content_length) {
/* Ensure remaining content will fit in remaining buffer size */
if(content_length > (buffer_size - len)) {
ERROR("TCP msg too big");
}
// Read Body part
do {
recv_size = recv_all_tcp(sock, &(buffer[len]), content_length, 2);
if(recv_size <= 0) {
return recv_size;
}
len += recv_size;
content_length -= recv_size;
} while(content_length);
}
// Add the final '\0'
buffer[len] = 0;
return len;
}
int decompress_if_needed(int sock, char *buff, int len, void **st)
{
if(compression && len) {
struct timeval currentTime;
GET_TIME (¤tTime);
TRACE_MSG((s,
"----------------------------------------------- %s\n"
"Compressed message received, header :\n"
"0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x "
"0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
CStat::instance()->formatTime(¤tTime),
buff[0] , buff[1] , buff[2] , buff[3],
buff[4] , buff[5] , buff[6] , buff[7],
buff[8] , buff[9] , buff[10], buff[11],
buff[12], buff[13], buff[14], buff[15]));
int rc = comp_uncompress(st,
buff,
(unsigned int *)&len);
switch(rc) {
case COMP_OK:
TRACE_MSG((s,"Compressed message decompressed properly.\n"));
break;
case COMP_REPLY:
TRACE_MSG((s,
"Compressed message KO, sending a reply (resynch).\n"));
sendto(sock,
buff,
len,
0,
(sockaddr *)(void *)&remote_sockaddr,
SOCK_ADDR_SIZE(&remote_sockaddr));
resynch_send++;
return 0;
case COMP_DISCARD:
TRACE_MSG((s, "Compressed message discarded by pluggin.\n"));
resynch_recv++;
return 0;
default:
case COMP_KO:
ERROR("Compression pluggin error");
return 0;
}
}
return len;
}
void sipp_customize_socket(int s)
{
unsigned int buffsize = 65535;
/* Allows fast TCP reuse of the socket */
#ifdef _USE_OPENSSL
if (transport == T_TCP || transport == T_TLS ) {
#else
if (transport == T_TCP) {
#endif
int sock_opt = 1;
if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void *)&sock_opt,
sizeof (sock_opt)) == -1) {
ERROR_NO("setsockopt(SO_REUSEADDR) failed");
}
#ifndef SOL_TCP
#define SOL_TCP 6
#endif
if (setsockopt (s, SOL_TCP, TCP_NODELAY, (void *)&sock_opt,
sizeof (sock_opt)) == -1) {
{
ERROR_NO("setsockopt(TCP_NODELAY) failed");
}
}
{
struct linger linger;
linger.l_onoff = 1;
linger.l_linger = 1;
if (setsockopt (s, SOL_SOCKET, SO_LINGER,
&linger, sizeof (linger)) < 0) {
ERROR_NO("Unable to set SO_LINGER option");
}
}
}
/* Increase buffer sizes for this sockets */
if(setsockopt(s,
SOL_SOCKET,
SO_SNDBUF,
&buffsize,
sizeof(buffsize))) {
ERROR_NO("Unable to set socket sndbuf");
}
buffsize = 65535;
if(setsockopt(s,
SOL_SOCKET,
SO_RCVBUF,
&buffsize,
sizeof(buffsize))) {
ERROR_NO("Unable to set socket rcvbuf");
}
}
#ifdef _USE_OPENSSL
int send_message_tls(SSL *ssl, void ** comp_state, char * msg)
{
int rc;
rc = send_nowait_tls(ssl, msg, strlen(msg), 0);
if(rc == 0) {
nb_net_send_errors++;
ERROR_NO("Unable to send TLS message");
return -2;
}
return rc;
}
#endif
int send_message(int s, void ** comp_state, char * msg)
{
struct sockaddr_storage *L_dest = &remote_sockaddr;
if(transport == T_TCP) {
int rc;
rc = send_nowait(s,
msg,
strlen(msg),
0);
#ifdef EAGAIN
if(errno == EAGAIN) {
nb_net_cong++;
return -1;
}
#endif
if(errno == EWOULDBLOCK) {
nb_net_cong++;
return -1;
}
if(errno == EPIPE) {
nb_net_send_errors++;
ERROR("Broken pipe on TCP connection, remote peer "
"probably closed the socket");
}
if(rc <= 0) {
nb_net_send_errors++;
ERROR_NO("Unable to send TCP message");
return -2;
}
} else { /* UDP */
unsigned int len = strlen(msg);
if(compression) {
static char comp_msg[SIPP_MAX_MSG_SIZE];
strcpy(comp_msg, msg);
if(comp_compress(comp_state,
comp_msg,
&len) != COMP_OK) {
ERROR("Compression pluggin error");
}
msg = (char *)comp_msg;
TRACE_MSG((s, "---\nCompressed message len: %d\n",
len));
}
// different remote sending address from received
if (use_remote_sending_addr) {
L_dest = &remote_sending_sockaddr ;
}
if(sendto(s,
msg,
len,
0,
(struct sockaddr *)(void *)L_dest,
SOCK_ADDR_SIZE(L_dest)) == -1) {
nb_net_send_errors++;
ERROR_NO("Unable to send UDP message");
return -2;
}
}
return 0;
}
/****************************** Network Interface *******************/
int recv_message(char * buffer, int buffer_size, int * poll_idx)
{
int size = 0;
#ifdef _USE_OPENSSL
BIO *bio;
SSL *ssl;
#endif
int err;
for((*poll_idx) = 0;
(*poll_idx) < pollnfds;
(*poll_idx)++) {
if(pollfiles[(*poll_idx)].revents) {
call * recv_call = pollcalls[(*poll_idx)];
int s = pollfiles[(*poll_idx)].fd;
int ss = s;
pollfiles[(*poll_idx)].revents = 0;
#ifdef __3PCC__
if(s == localTwinSippSocket)
{
sipp_socklen_t len = sizeof(twinSipp_sockaddr);
twinSippSocket = accept(s,
(sockaddr *)(void *)&twinSipp_sockaddr,
&len);
pollset_add(0, twinSippSocket);
return(-2);
}
else if (s == twinSippSocket)
{
size = recv_tcp_message(s,
buffer,
buffer_size,
E_ALTER_NO,
E_ALTER_YES);
if(size >= 0) {
buffer[size] = 0;
}
else
buffer[0] = 0;
return size;
}
else
{
#endif
#ifdef _USE_OPENSSL
if(transport == T_TCP || transport == T_TLS ) {
#else
if(transport == T_TCP ) {
#endif
if(s == main_socket) {
/* New incoming connection */
sipp_socklen_t len = SOCK_ADDR_SIZE(&remote_sockaddr);
int new_sock = accept(s,
(sockaddr *)(void *)&remote_sockaddr,
&len);
#ifdef _USE_OPENSSL
if (transport == T_TLS) {
if ( (bio = BIO_new_socket(new_sock,BIO_NOCLOSE)) == NULL) {
ERROR("Unable to create the BIO- New TLS connection - recv_message\n");
}
/* Create a SSL object */
if (!(ssl = SSL_new(sip_trp_ssl_ctx))){
ERROR("Unable to create new SSL context recv_message: Fail SSL_new\n");
}
SSL_set_bio(ssl,bio,bio);
if ( (err = SSL_accept(ssl)) < 0 ) {
ERROR("SSL_accept Fails - recv_message()\n");
}
ssl_list[new_sock] = ssl;
}
#endif
pollset_add(0, new_sock);
return -2;
}
#ifdef _USE_OPENSSL
if ( transport == T_TLS ) {
int ss = s;
ssl = ssl_list[s];
size = recv_tls_message(ssl,
buffer,
buffer_size,
E_ALTER_YES);
} else {
#endif
size = recv_tcp_message(s,
buffer,
buffer_size,
E_ALTER_YES);
#ifdef _USE_OPENSSL
}
#endif
if(size <= 0) { /* Remote side closed TCP connection */
nb_net_recv_errors++;
/* Preventive cleaning */
if(size < 0) {
WARNING_P2("TCP/TLS recv error on socket %d, index = %d",
s, *poll_idx);
ERROR_NO("TCP/TLS recv_error");
}
if(recv_call) {
recv_call -> call_socket = 0;
if(recv_call -> pollset_index) {
recv_call -> pollset_index = 0;
}
}
pollset_remove((*poll_idx));
shutdown(s, SHUT_RDWR);
close(s);
return 0;
}
} else { /* T_UDP */
if(toolMode == MODE_SERVER) {
sipp_socklen_t len = SOCK_ADDR_SIZE(&remote_sockaddr);
size = recvfrom(s,
buffer,
buffer_size,
0,
(sockaddr *)(void *)&remote_sockaddr,
&len);
} else {
size = recvfrom(s,
buffer,
buffer_size,
0, NULL, NULL);
}
if(size < 0) {
WARNING_P3("Unexpected UDP recv error, idx = %d, "
"socket = %d, recv_call = 0x%08x",
(*poll_idx), s, recv_call);
ERROR_NO("Unexpected UDP recv error");
#if 0
nb_net_recv_errors++;
pollset_remove((*poll_idx));
shutdown(s, SHUT_RDWR);
close(s);
#endif
return 0;
}
if (size > 0) {
size = decompress_if_needed(s,
buffer,
size,
((recv_call) ?
(&(recv_call -> comp_state)) :
&monosocket_comp_state));
}
} /* else ... T_UDP */
break;
#ifdef __3PCC__
}
#endif
} /* if(pollfiles[(*poll_idx)].revents) */
} /* for((*poll_idx)) */
buffer[size] = 0;
struct timeval currentTime;
GET_TIME (¤tTime);
TRACE_MSG((s, "----------------------------------------------- %s\n"
"%s message received [%d] bytes :\n\n%s\n",
CStat::instance()->formatTime(¤tTime),
TRANSPORT_TO_STRING(transport), size,
buffer));
return size;
}
void pollset_process(bool ipv6)
{
int rs; /* Number of times to execute recv().
For TCP with 1 socket per call:
no. of events returned by poll
For UDP and TCP with 1 global socket:
recv_count is a flag that stays up as
long as there's data to read */
int loops = MAX_RECV_LOOPS;
while((loops-- > 0) && /* Ensure some minimal statistics display sometime */
(rs = poll(pollfiles, pollnfds, 1)) > 0) {
if((rs < 0) && (errno == EINTR)) {
return;
}
if(rs < 0) {
ERROR_NO("poll() error");
}
while(rs > 0) {
char msg[SIPP_MAX_MSG_SIZE];
int msg_size;
char * call_id;
call * call_ptr;
int pollset_index = 0;
memset(msg,0,sizeof(msg));
msg_size = recv_message(msg,
SIPP_MAX_MSG_SIZE,
&pollset_index);
if(msg_size > 0) {
if (sipMsgCheck(msg,
msg_size
#ifdef __3PCC__
,pollset_index
#endif // __3PCC__
) == true) {
call_id = get_call_id(msg);
call_ptr = get_call(call_id);
if(!call_ptr)
{
if(toolMode == MODE_SERVER)
{
// Adding a new INCOMING call !
CStat::instance()->computeStat
(CStat::E_CREATE_INCOMING_CALL);
call_ptr = add_call(call_id, ipv6);
if((pollset_index) &&
(pollfiles[pollset_index].fd != main_socket) &&
(pollfiles[pollset_index].fd != tcp_multiplex) ) {
call_ptr -> call_socket = pollfiles[pollset_index].fd;
}
}
#ifdef __3PCC__
else if(toolMode == MODE_3PCC_CONTROLLER_B || toolMode == MODE_3PCC_A_PASSIVE)
{
// Adding a new OUTGOING call !
CStat::instance()->computeStat
(CStat::E_CREATE_OUTGOING_CALL);
call_ptr = add_call(call_id, ipv6);
if((pollset_index) &&
(pollfiles[pollset_index].fd != main_socket) &&
(pollfiles[pollset_index].fd != tcp_multiplex) &&
(pollfiles[pollset_index].fd != localTwinSippSocket) &&
(pollfiles[pollset_index].fd != twinSippSocket)) {
call_ptr -> call_socket = pollfiles[pollset_index].fd;
}
}
#endif
else // mode != from SERVER and 3PCC Controller B
{
nb_out_of_the_blue++;
CStat::instance()->computeStat
(CStat::E_OUT_OF_CALL_MSGS);
// This is a message that is not relating to any call
}
}
if(call_ptr)
{
#ifdef __3PCC__
if( (pollfiles[pollset_index].fd == localTwinSippSocket) ||
(pollfiles[pollset_index].fd == twinSippSocket))
{
if(!call_ptr -> process_twinSippCom(msg))
{
return;
}
}
else
#endif
{
if(!call_ptr -> process_incomming(msg))
{
/* Needs to rebuild the pollset (socket removed,
* call deleted, etc... Cause pollcalls is now
* invalid and will alway lead poll() to return
* an error.*/
return;
}
}
}
} else { // sipMsgCheck == false
// unrecognized message => discard it
WARNING("non SIP message discarded");
}
if (pollnfds > 0) /* refer to note at the beginning of this function */
rs--;
} // end if msg >=0
else
rs--;
}
}
cpu_max = loops <= 0;
}
/* Send loop & trafic generation*/
void traffic_thread(bool ipv6)
{
unsigned int calls_to_open = 0;
unsigned int new_time;
unsigned int last_time;
int timer_resolution = DEFAULT_TIMER_RESOLUTION;
bool firstPass;
/* create the file */
char L_file_name [200];
sprintf (L_file_name, "%s_%d_screen.log", scenario_file, getpid());
firstPass = true;
last_time = getmilliseconds();
/* Prepare pollset with basic sockets */
pollset_reset();
while(1) {
scheduling_loops ++;
/* update local time, except if resetted*/
new_time = getmilliseconds();
clock_tick += (new_time - last_time);
last_time = new_time;
if (signalDump) {
/* Screen dumping in a file */
if (screenf) {
print_screens();
} else {
/* If the -trace_screen option has not been set, */
/* create the file at this occasion */
screenf = fopen(L_file_name, "a");
if (!screenf) {
WARNING_P1("Unable to create '%s'", L_file_name);
}
print_screens();
fclose(screenf);
screenf = 0;
}
signalDump = false ;
}
if ((!quitting) && (!paused)) {
calls_to_open =
(unsigned int) (((clock_tick - last_rate_change_time) * rate/rate_period_s) / 1000)
- calls_since_last_rate_change;
if( (toolMode == MODE_CLIENT)
#ifdef __3PCC__
|| (toolMode == MODE_3PCC_CONTROLLER_A)
#endif
)
{
while((calls_to_open--) &&
(open_calls < open_calls_allowed) &&
(total_calls < stop_after))
{
// adding a new OUTGOING CALL
CStat::instance()->computeStat(CStat::E_CREATE_OUTGOING_CALL);
call * call_ptr = add_call(ipv6);
call_ptr -> run();
}
if(open_calls >= open_calls_allowed) {
set_rate(rate);
}
}
// Quit after asked number of calls is reached
if(total_calls >= stop_after) {
quitting = 1;
}
} else if (quitting) {
/* Quitting and no more openned calls, close all */
if(!open_calls) {
// Dump the latest statistics if necessary
if(dumpInFile) {
CStat::instance()->dumpData();
}
/* Screen dumping in a file if asked */
if(screenf) {
print_screens();
}
screen_exit(EXIT_TEST_RES_UNKNOWN);
}
}
if(compression) {
timer_resolution = 50;
}
/* Schedule all pending calls and process their timers */
if((clock_tick - last_timer_cycle) > timer_resolution) {
call_map * calls = get_calls();
call_map::iterator iter;
/* Workaround hpux problem with iterators. Deleting the
* current object when iterating breaks the iterator and
* leads to iterate again on the destroyed (deleted)
* object. Thus, we have to wait ont step befere actual
* deletion of the object*/
call * last = NULL;
for(iter = calls->begin(); iter != calls->end(); iter++) {
if(last) { last -> run(); }
last = iter -> second;
}
if(last) { last -> run(); }
last_timer_cycle = clock_tick;
}
/* Receive incomming messages */
pollset_process(ipv6);
if(firstPass)
{
// dumping (to create file on disk) and showing
// screen at the beginning even if the report
// period is not reach
firstPass = false;
print_statistics(0);
/* Dumping once to create the file on disk */
if(dumpInFile)
{
CStat::instance()->dumpData();
}
}
if((clock_tick - last_report_time) >= report_freq)
{
print_statistics(0);
CStat::instance()->computeStat(CStat::E_RESET_PD_COUNTERS);
last_report_time = clock_tick;
last_report_calls = total_calls;
rtd_sum = 0;
rtd_nb = 0;
call_duration_sum = 0;
call_duration_nb = 0;
scheduling_loops = 0;
}
// FIXME - Should we recompute time ? print stat take
// a lot of time, so the clock_time is no more
// the current time !
if(dumpInFile) {
if((clock_tick - last_dump_time) >= report_freq_dumpLog) {
CStat::instance()->dumpData();
CStat::instance()->computeStat(CStat::E_RESET_PL_COUNTERS);
last_dump_time = clock_tick;
}
}
}
}
/*************** RTP ECHO THREAD ***********************/
void rtp_echo_thread (void * param)
{
char msg[2048];
size_t nr, ns;
sipp_socklen_t len;
int rc;
sigset_t mask;
sigfillset(&mask); /* Mask all allowed signals */
rc = pthread_sigmask(SIG_BLOCK, &mask, NULL);
for (;;) {
len = sizeof(remote_rtp_addr);
nr = recvfrom(media_socket,
msg,
sizeof(msg), 0,
(sockaddr *)(void *) &remote_rtp_addr,
&len);
if (((long)nr) < 0) {
WARNING_P2("%s %i",
"Error on RTP echo reception - stopping echo - errno=",
errno);
return;
}
ns = sendto(media_socket, msg, nr,
0, (sockaddr *)(void *) &remote_rtp_addr,
len);
if (ns != nr) {
WARNING_P2("%s %i",
"Error on RTP echo transmission - stopping echo - errno=",
errno);
return;
}
rtp_pckts++;
rtp_bytes += ns;
}
}
/* Help screen */
void help()
{
printf
("\n"
"Usage:\n"
"\n"
" sipp remote_host[:remote_port] [options]\n"
"\n"
" Available options:\n"
"\n"
" -v : Display version and copyright information.\n"
"\n"
" -bg : Launch the tool in background mode.\n"
"\n"
" -p local_port : Set the local port number. Default is a\n"
" random free port chosen by the system.\n"
"\n"
" -i local_ip : Set the local IP address for 'Contact:',\n"
" 'Via:', and 'From:' headers. Default is\n"
" primary host IP address.\n"
"\n"
" -inf file_name : Inject values from an external CSV file during calls\n"
" into the scenarios.\n"
" First line of this file say whether the data is \n"
" to be read in sequence (SEQUENTIAL) or random \n"
" (RANDOM) order.\n"
" Each line corresponds to one call and has one or \n"
" more ';' delimited data fields. Those fields can be \n"
" referred as [field0], [field1], ... in the xml \n"
" scenario file.\n"
"\n"
" -d duration : Controls the length (in milliseconds) of\n"
" calls. More precisely, this controls\n"
" the duration of 'pause' instructions in\n"
" the scenario, if they do not have a\n"
" 'milliseconds' section. Default value is 0.\n"
"\n"
" -r rate (cps) : Set the call rate (in calls per seconds).\n"
" This value can be changed during test by\n"
" pressing '+','_','*' or '/'. Default is 10.\n"
" pressing '+' key to increase call rate by 1,\n"
" pressing '-' key to decrease call rate by 1,\n"
" pressing '*' key to increase call rate by 10,\n"
" pressing '/' key to decrease call rate by 10.\n"
" If the -rp option is used, the call rate is\n"
" calculated with the period in ms given \n"
" by the user.\n"
"\n"
" -rp period (ms) : Specify the rate period in milliseconds for the call\n"
" rate.\n"
" Default is 1 second.\n"
" This allows you to have n calls every m milliseconds \n"
" (by using -r n -rp m).\n"
" Example: -r 7 -rp 2000 ==> 7 calls every 2 seconds.\n"
"\n"
" -sf filename : Loads an alternate xml scenario file.\n"
" To learn more about XML scenario syntax,\n"
" use the -sd option to dump embedded \n"
" scenarios. They contain all the necessary\n"
" help.\n"
"\n"
" -sn name : Use a default scenario (embedded in\n"
" the sipp executable). If this option is omitted,\n"
" the Standard SipStone UAC scenario is loaded.\n"
" Available values in this version:\n"
"\n"
" 'uac' : Standard SipStone UAC (default).\n"
" 'uas' : Simple UAS responder.\n"
" 'regexp' : Standard SipStone UAC - with\n"
" regexp and variables.\n"
" 'branchc' : Branching and conditional\n"
" branching in scenarios - client.\n"
" 'branchs' : Branching and conditional\n"
" branching in scenarios - server.\n"
#ifdef __3PCC__
"\n"
" Default 3pcc scanerios (see -3pcc option):\n"
"\n"
" '3pcc-C-A' : Controller A side (must be started\n"
" after all other 3pcc scenarios)\n"
" '3pcc-C-B' : Controller B side.\n"
" '3pcc-A' : A side.\n"
" '3pcc-B' : B side.\n"
#endif
"\n"
" -sd name : Dumps a default scenario (embeded in\n"
" the sipp executable)\n"
"\n"
#ifdef _USE_OPENSSL
" -t [u1|un|t1|tn|l1|ln] : Set the transport mode:\n"
#else
" -t [u1|un|t1|tn] : Set the transport mode:\n"
#endif
"\n"
" u1: UDP with one socket (default),\n"
" un: UDP with one socket per call,\n"
" t1: TCP with one socket,\n"
" tn: TCP with one socket per call,\n"
#ifdef _USE_OPENSSL
" l1: TLS with one socket,\n"
" ln: TLS with one socket per call.\n"
#endif
"\n");
if(!strlen(comp_error)) {
printf
(" It appears that you installed the\n"
" " COMP_PLUGGIN " plugin. 2 additionnal\n"
" transport modes are available:\n"
"\n"
" c1: u1 + compression,\n"
" cn: un + compression.\n"
"\n");
}
printf
(" -trace_msg : Displays sent and received SIP messages in\n"
" <scenario file name>_<ppid>_messages.log\n"
"\n"
" -trace_screen : Dump statistic screens in the \n"
" <scenario_name>_<ppid>_screens.log file when\n"
" quitting SIPp. Useful to get a final status report\n"
" in background mode (-bg option).\n"
"\n"
" -trace_timeout : Displays call ids for calls with timeouts in\n"
" <scenario file name>_<ppid>_timeout.log\n"
"\n"
" -trace_stat : Dumps all statistics in <scenario_name>_<ppid>.csv\n"
" file. Use the '-h stat' option for a detailed\n"
" description of the statistics file content.\n"
"\n"
" -stf file_name : Set the file name to use to dump statistics\n"
"\n"
" -trace_err : Trace all unexpected messages in\n"
" <scenario file name>_<ppid>_errors.log.\n"
"\n"
" -trace_logs : Allow tracing of <log> actions in\n"
" <scenario file name>_<ppid>_logs.log.\n"
"\n"
" -s service_name : Set the username part of the resquest URI.\n"
" Default is 'service'.\n"
"\n"
#ifdef _USE_OPENSSL
" -ap password : Set the password for authentication challenges.\n"
" Default is 'password'\n"
"\n"
#endif
" -f frequency : Set the statistics report frequency on screen\n"
" (in seconds). Default is 1.\n"
"\n"
" -fd frequency : Set the statistics dump log report frequency\n"
" (in seconds). Default is 60.\n"
"\n"
" -l calls_limit : Set the maximum number of simultaneous\n"
" calls. Once this limit is reached, traffic\n"
" is decreased until the number of open calls\n"
" goes down. Default:\n"
"\n"
" (3 * call_duration (s) * rate).\n"
"\n"
" -m calls : Stop the test and exit when 'calls' calls are\n"
" processed.\n"
"\n"
" -mp local_port : Set the local RTP echo port number. Default\n"
" is none. RTP/UDP packets received on that\n"
" port are echoed to their sender.\n"
"\n"
" -mi local_rtp_ip : Set the local IP address for RTP echo.\n"
"\n"
#ifdef __3PCC__
" -3pcc ip:port : Launch the tool in 3pcc mode (\"Third Party\n"
" call control\"). The passed ip address\n"
" is depending on the 3PCC role.\n"
" - When the first twin command is 'sendCmd' then\n"
" this is the address of the remote twin socket.\n"
" Example: 3PCC-C-A scenario.\n"
" - When the first twin command is 'recvCmd' then\n"
" this is the address of the local twin socket.\n"
" Example: 3PCC-C-B scenario.\n"
"\n"
#endif
" -nr : Disable retransmission in UDP mode.\n"
"\n"
" -nd : No Default. Disable all default behavior of SIPp\n"
" which are the following:\n"
" - On UDP retransmission timeout, abort the call by\n"
" sending a BYE or a CANCEL\n"
" - On unexpected BYE send a 200 OK and close the call\n"
" - On unexpected CANCEL send a 200 OK and close the call\n"
" - On unexpected PING send a 200 OK and continue the call\n"
" - On any other unexpected message, abort the call by\n"
" sending a BYE or a CANCEL\n"
"\n"
" -rsa host:port : Set the remote sending address to host:port.\n"
" for sending the messages.\n"
"\n"
"Signal handling:\n"
"\n"
" SIPp can be controlled using posix signals. The following signals\n"
" are handled:\n"
" USR1: Similar to press 'q' keyboard key. It triggers a soft exit\n"
" of SIPp. No more new calls are placed and all ongoing calls\n"
" are finished before SIPp exits.\n"
" Example: kill -SIGUSR1 732\n"
" USR2: Triggers a dump of all statistics screens in\n"
" <scenario_name>_<ppid>_screens.log file. Especially useful \n"
" in background mode to know what the current status is.\n"
" Example: kill -SIGUSR2 732\n"
"\n"
"Exit code:\n"
"\n"
" Upon exit (on fatal error or when the number of asked calls (-m\n"
" option) is reached, sipp exits with one of the following exit\n"
" code:\n"
" 0: All calls were successful\n"
" 1: At least one call failed\n"
" 97: exit on internal command. Calls may have been processed\n"
" 99: Normal exit without calls processed\n"
" -1: Fatal error\n"
"\n"
"\n"
"Example:\n"
"\n"
" Run sipp with embedded server (uas) scenario:\n"
" ./sipp -sn uas\n"
" On the same host, run sipp with embedded client (uac) scenario\n"
" ./sipp -sn uac 127.0.0.1\n"
"\n");
}
void help_stats()
{
printf(
"\n"
" The -trace_stat option dumps all statistics in the\n"
" <scenario_name.csv> file. The dump starts with one header\n"
" line with all counters. All following lines are 'snapshots' of \n"
" statistics counter given the statistics report frequency\n"
" (-fd option). This file can be easily imported in any\n"
" spreadsheet application, like Excel.\n"
"\n"
" In counter names, (P) means 'Periodic' - since last\n"
" statistic row and (C) means 'Cumulated' - since sipp was\n"
" started.\n"
"\n"
" Available statistics are:\n"
"\n"
" - StartTime: \n"
" Date and time when the test has started.\n"
"\n"
" - LastResetTime:\n"
" Date and time when periodic counters where last reseted.\n"
"\n"
" - CurrentTime:\n"
" Date and time of the statistic row.\n"
"\n"
" - ElapsedTime:\n"
" Elapsed time.\n"
"\n"
" - CallRate:\n"
" Call rate (calls per seconds).\n"
"\n"
" - IncomingCall:\n"
" Number of incoming calls.\n"
"\n"
" - OutgoingCall:\n"
" Number of outgoing calls.\n"
"\n"
" - TotalCallCreated:\n"
" Number of calls created.\n"
"\n"
" - CurrentCall:\n"
" Number of calls currently ongoing.\n"
"\n"
" - SuccessfulCall:\n"
" Number of successful calls.\n"
"\n"
" - FailedCall:\n"
" Number of failed calls (all reasons).\n"
"\n"
" - FailedCannotSendMessage:\n"
" Number of failed calls because Sipp cannot send the\n"
" message (transport issue).\n"
"\n"
" - FailedMaxUDPRetrans:\n"
" Number of failed calls because the maximum number of\n"
" UDP retransmission attempts has been reached.\n"
"\n"
" - FailedUnexpectedMessage:\n"
" Number of failed calls because the SIP message received\n"
" is not expected in the scenario.\n"
"\n"
" - FailedCallRejected:\n"
" Number of failed calls because of Sipp internal error.\n"
" (a scenario sync command is not recognized or a scenario\n"
" action failed or a scenario variable assignment failed).\n"
"\n"
" - FailedCmdNotSent:\n"
" Number of failed calls because of inter-Sipp\n"
" communication error (a scenario sync command failed to\n"
" be sent).\n"
"\n"
" - FailedRegexpDoesntMatch:\n"
" Number of failed calls because of regexp that doesn't\n"
" match (there might be several regexp that don't match\n"
" during the call but the counter is increased only by\n"
" one).\n"
"\n"
" - FailedRegexpHdrNotFound:\n"
" Number of failed calls because of regexp with hdr \n"
" option but no matching header found.\n"
"\n"
" - OutOfCallMsgs:\n"
" Number of SIP messages received that cannot be associated\n"
" to an existing call.\n"
"\n"
" - AutoAnswered:\n"
" Number of unexpected specific messages received for new Call-ID.\n"
" The message has been automatically answered by a 200 OK\n"
" Currently, implemented for 'PING' message only.\n"
"\n");
}
/************* exit handler *****************/
void print_last_stats()
{
interrupt = 1;
// print last current screen
print_statistics(1);
// and print statistics screen
currentScreenToDisplay = DISPLAY_STAT_SCREEN;
print_statistics(1);
}
void releaseGlobalAllocations()
{
message * L_ptMsg = NULL;
CStat::instance()->close();
for(int i=0; i<SCEN_VARIABLE_SIZE; i++)
{
if (scenVariableTable[i] != NULL)
delete(scenVariableTable[i]);
scenVariableTable[i] = NULL;
}
for(int i=0; i<scenario_len; i++)
{
L_ptMsg = scenario[i];
if (L_ptMsg != NULL)
{
delete(L_ptMsg);
scenario[i] = NULL;
}
}
}
char* remove_pattern(char* P_buffer, char* P_extensionPattern) {
char *L_ptr = P_buffer;
if (P_extensionPattern == NULL) {
return P_buffer ;
}
if (P_buffer == NULL) {
return P_buffer ;
}
L_ptr = strstr(P_buffer, P_extensionPattern) ;
if (L_ptr != NULL) {
*L_ptr = '\0' ;
}
return P_buffer ;
}
/* Main */
int main(int argc, char *argv[])
{
int argi = 0;
int index = 0;
struct sockaddr_storage local_sockaddr;
struct sockaddr_storage localTwin_sockaddr;
struct sockaddr_storage media_sockaddr;
int user_port = 0;
pthread_t pthread_id, pthread2_id;
int argiFileName = 0;
int argiInputFile = 0;
char *scenario_name = NULL;
char hostname[80];
bool is_ipv6 = false;
int err;
/* At least one argument is needed */
if(argc < 2) {
help();
exit(EXIT_OTHER);
}
/* Ignore the SIGPIPE signal */
{
struct sigaction action_pipe;
memset(&action_pipe, 0, sizeof(action_pipe));
action_pipe.sa_handler=SIG_IGN;
sigaction(SIGPIPE, &action_pipe, NULL);
/* sig usr1 management */
struct sigaction action_usr1;
memset(&action_usr1, 0, sizeof(action_usr1));
action_usr1.sa_handler = sipp_sigusr1;
sigaction(SIGUSR1, &action_usr1, NULL);
/* sig usr2 management */
struct sigaction action_usr2;
memset(&action_usr2, 0, sizeof(action_usr2));
action_usr2.sa_handler = sipp_sigusr2;
sigaction(SIGUSR2, &action_usr2, NULL);
}
screen_set_exename((char *)"sipp");
pid = getpid();
memset(local_ip, 0, 40);
memset(media_ip,0, 40);
/* Load compression pluggin if available */
comp_load();
/* Command line parsing */
for(argi = 1; argi < argc; argi++) {
int processed = 0;
if((!strcmp(argv[argi], "-h" )) ||
(!strcmp(argv[argi], "--h" )) ||
(!strcmp(argv[argi], "--help")) ||
(!strcmp(argv[argi], "-help" )) ) {
if(((argi+1) < argc) && (!strcmp(argv[argi+1], "stat"))) {
help_stats();
} else {
help();
}
exit(EXIT_OTHER);
}
if(!strcmp(argv[argi], "-p")) {
if((++argi) < argc) {
user_port = atol(argv[argi]);
processed = 1;
} else {
ERROR_P1("Missing argument for param '%s'.\nUse 'sipp -h' for details",
argv[argi-1]);
}
}
if(!strcmp(argv[argi], "-mp")) {
if((++argi) < argc) {
media_port = atol(argv[argi]);
processed = 1;
} else {
ERROR_P1("Missing argument for param '%s'.\nUse 'sipp -h' for details",
argv[argi-1]);
}
}
if(!strcmp(argv[argi], "-mi")) {
if((++argi) < argc) {
processed = 1;
strcpy(media_ip, argv[argi]);
} else {
ERROR_P1("Missing argument for param '%s'.\n"
"Use 'sipp -h' for details", argv[argi-1]);
}
}
if(!strcmp(argv[argi], "-t")) {
if((++argi) < argc) {
processed = 1;
if(!strcmp(argv[argi], "u1")) {
transport = T_UDP;
multisocket = 0;
} else if(!strcmp(argv[argi], "un")) {
transport = T_UDP;
multisocket = 1;
} else if(!strcmp(argv[argi], "t1")) {
transport = T_TCP;
multisocket = 0;
} else if(!strcmp(argv[argi], "tn")) {
transport = T_TCP;
multisocket = 1;
#ifdef _USE_OPENSSL
} else if(!strcmp(argv[argi], "l1")) {
transport = T_TLS;
multisocket = 0;
if ( init_OpenSSL() != 1) {
printf("OpenSSL Initialization problem\n");
exit ( -1);
}
} else if (!strcmp(argv[argi], "ln")) {
transport = T_TLS;
multisocket = 1;
if ( init_OpenSSL() != 1) {
printf("OpenSSL Initialization problem\n");
exit ( -1);
}
#endif
} else if(!strcmp(argv[argi], "c1")) {
if(strlen(comp_error)) {
ERROR_P1("No " COMP_PLUGGIN " pluggin available:\n%s", comp_error);
}
transport = T_UDP;
multisocket = 0;
compression = 1;
} else if(!strcmp(argv[argi], "cn")) {
if(strlen(comp_error)) {
ERROR_P1("No " COMP_PLUGGIN " pluggin available:\n%s", comp_error);
}
transport = T_UDP;
multisocket = 1;
compression = 1;
} else {
ERROR_P1("Invalid argument for -t param : '%s'.\n"
"Use 'sipp -h' for details", argv[argi]);
}
} else {
ERROR_P1("Missing argument for param '%s'.\n"
"Use 'sipp -h' for details", argv[argi-1]);
}
}
if(!strcmp(argv[argi], "-nr")) {
processed = 1;
retrans_enabled = 0;
}
if(!strcmp(argv[argi], "-nd")) {
processed = 1;
default_behavior = 0;
}
if(!strcmp(argv[argi], "-trace_msg")) {
useMessagef = 1 ;
processed = 1;
}
if(!strcmp(argv[argi], "-trace_screen")) {
useScreenf = 1 ;
processed = 1;
}
if(!strcmp(argv[argi], "-trace_err")) {
processed = 1;
print_all_responses = 1;
}
if(!strcmp(argv[argi], "-trace_timeout")) {
useTimeoutf = 1 ;
processed = 1;
}
if(!strcmp(argv[argi], "-trace_stat")) {
processed = 1;
dumpInFile = 1;
}
if(!strcmp(argv[argi], "-trace_logs")) {
processed = 1;
useLogf = 1;
}
if(!strcmp(argv[argi], "-stf")) {
if((++argi) < argc) {
processed = 1;
argiFileName = argi;
} else {
ERROR_P1("Missing argument for param '%s'.\n"
"Use 'sipp -h' for details", argv[argi-1]);
}
}
if(!strcmp(argv[argi], "-inf")) {
if((++argi) < argc) {
processed = 1;
argiInputFile = argi;
} else {
ERROR_P1("Missing argument for param '%s'.\n"
"Use 'sipp -h' for details", argv[argi-1]);
}
}
if(!strcmp(argv[argi], "-d")) {
if((++argi) < argc) {
processed = 1;
duration = atol(argv[argi]);
} else {
ERROR_P1("Missing argument for param '%s'.\n"
"Use 'sipp -h' for details", argv[argi-1]);
}
}
if(!strcmp(argv[argi], "-i")) {
if((++argi) < argc) {
processed = 1;
int dummy_port;
strcpy(local_ip, argv[argi]);
get_host_and_port(local_ip, local_ip, &dummy_port);
} else {
ERROR_P1("Missing argument for param '%s'.\n"
"Use 'sipp -h' for details", argv[argi-1]);
}
}
if(!strcmp(argv[argi], "-m")) {
if((++argi) < argc) {
processed = 1;
stop_after = atol(argv[argi]);
} else {
ERROR_P1("Missing argument for param '%s'.\n"
"Use 'sipp -h' for details", argv[argi-1]);
}
}
if(!strcmp(argv[argi], "-f")) {
if((++argi) < argc) {
processed = 1;
report_freq = atol(argv[argi]) * 1000;
} else {
ERROR_P1("Missing argument for param '%s'.\n"
"Use 'sipp -h' for details", argv[argi-1]);
}
}
if(!strcmp(argv[argi], "-fd")) {
if((++argi) < argc) {
processed = 1;
report_freq_dumpLog = atol(argv[argi]) * 1000;
} else {
ERROR_P1("Missing argument for param '%s'.\n"
"Use 'sipp -h' for details", argv[argi-1]);
}
}
if(!strcmp(argv[argi], "-l")) {
if((++argi) < argc) {
processed = 1;
open_calls_allowed = atol(argv[argi]);
open_calls_user_setting = 1;
} else {
ERROR_P1("Missing argument for param '%s'.\n"
"Use 'sipp -h' for details", argv[argi-1]);
}
}
if(!strcmp(argv[argi], "-bg")) {
processed = 1;
backgroundMode = true;
}
if(!strcmp(argv[argi], "-v")) {
#ifdef _USE_OPENSSL
printf("\n Sipp v1.1pre-with-TLS, built %s, %s.\n\n", __DATE__, __TIME__);
#else
printf("\n Sipp v1.1pre-without-TLS, built %s, %s.\n\n", __DATE__, __TIME__);
#endif
printf
(" This program is free software; you can redistribute it and/or\n"
" modify it under the terms of the GNU General Public License as\n"
" published by the Free Software Foundation; either version 2 of\n"
" the License, or (at your option) any later version.\n"
"\n"
" This program is distributed in the hope that it will be useful,\n"
" but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
" GNU General Public License for more details.\n"
"\n"
" You should have received a copy of the GNU General Public\n"
" License along with this program; if not, write to the\n"
" Free Software Foundation, Inc.,\n"
" 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n"
"\n"
" Author: Richard GAYRAUD - 04 Nov 2003.\n\n");
exit(EXIT_OTHER);
}
if(!strcmp(argv[argi], "-r")) {
if((++argi) < argc) {
processed = 1;
rate = atof(argv[argi]);
} else {
ERROR_P1("Missing argument for param '%s'.\n"
"Use 'sipp -h' for details", argv[argi-1]);
}
}
if(!strcmp(argv[argi], "-rp")) {
if((++argi) < argc) {
processed = 1;
rate_period_s = atof(argv[argi]) / 1000 ;
} else {
ERROR_P1("Missing argument for param '%s'.\n"
"Use 'sipp -h' for details", argv[argi-1]);
}
}
if(!strcmp(argv[argi], "-s")) {
if((++argi) < argc) {
processed = 1;
service = argv[argi];
} else {
ERROR_P1("Missing argument for param '%s'.\n"
"Use 'sipp -h' for details", argv[argi-1]);
}
}
#ifdef _USE_OPENSSL
if(!strcmp(argv[argi], "-ap")) {
if((++argi) < argc) {
auth_password = argv[argi];
processed = 1;
} else {
ERROR_P1("Missing argument for param '%s'.\n"
"Use 'sipp -h' for details", argv[argi-1]);
}
}
#endif
if(!strcmp(argv[argi], "-sf")) {
if((++argi) < argc) {
processed = 1;
load_scenario(argv[argi], 0);
scenario_file = new char [strlen(argv[argi])+1] ;
sprintf(scenario_file,"%s", argv[argi]);
CStat::instance()->setFileName(argv[argi], (char*)".csv");
} else {
ERROR_P1("Missing argument for param '%s'.\n"
"Use 'sipp -h' for details", argv[argi-1]);
}
}
// Remote sending address different from the received messages
if(!strcmp(argv[argi], "-rsa")) {
if((++argi) < argc) {
char *remote_s_address ;
int remote_s_p;
int temp_remote_s_p;
processed = 1;
temp_remote_s_p = 0;
remote_s_address = argv[argi] ;
get_host_and_port(remote_s_address, remote_s_address, &temp_remote_s_p);
if (temp_remote_s_p != 0) {
remote_s_p = temp_remote_s_p;
}
struct addrinfo hints;
struct addrinfo * local_addr;
printf("Resolving remote sending address %s...\n", remote_s_address);
memset((char*)&hints, 0, sizeof(hints));
hints.ai_flags = AI_PASSIVE;
hints.ai_family = PF_UNSPEC;
if (getaddrinfo(remote_s_address,
NULL,
&hints,
&local_addr) != 0) {
ERROR_P1("Unknown remote host '%s'.\n"
"Use 'sipp -h' for details", remote_s_address);
}
memcpy(&remote_sending_sockaddr,
local_addr->ai_addr,
SOCK_ADDR_SIZE(
_RCAST(struct sockaddr_storage *, local_addr->ai_addr)));
if (remote_sending_sockaddr.ss_family == AF_INET) {
(_RCAST(struct sockaddr_in *, &remote_sending_sockaddr))->sin_port =
htons((short)remote_s_p);
} else {
(_RCAST(struct sockaddr_in6 *, &remote_sending_sockaddr))->sin6_port =
htons((short)remote_s_p);
}
use_remote_sending_addr = 1 ;
} else {
ERROR_P1("Missing argument for param '%s'.\n"
"Use 'sipp -h' for details", argv[argi-1]);
}
}
if(!strcmp(argv[argi], "-sn")) {
if((++argi) < argc) {
processed = 1;
if(!strcmp(argv[argi], "uac")) {
CStat::instance()->setFileName((char*)"uac", (char*)".csv");
load_scenario(0, 0);
} else if(!strcmp(argv[argi], "uas")) {
CStat::instance()->setFileName((char*)"uas", (char*)".csv");
load_scenario(0, 1);
} else if(!strcmp(argv[argi], "regexp")) {
CStat::instance()->setFileName((char*)"regexp", (char*)".csv");
load_scenario(0, 2);
} else if(!strcmp(argv[argi], "3pcc-C-A")) {
CStat::instance()->setFileName((char*)"3pcc-C-A", (char*)".csv");
load_scenario(0, 3);
} else if(!strcmp(argv[argi], "3pcc-C-B")) {
CStat::instance()->setFileName((char*)"3pcc-C-B", (char*)".csv");
load_scenario(0, 4);
} else if(!strcmp(argv[argi], "3pcc-A")) {
CStat::instance()->setFileName((char*)"3pcc-A", (char*)".csv");
load_scenario(0, 5);
} else if(!strcmp(argv[argi], "3pcc-B")) {
CStat::instance()->setFileName((char*)"3pcc-B", (char*)".csv");
load_scenario(0, 6);
} else if(!strcmp(argv[argi], "branchc")) {
CStat::instance()->setFileName((char*)"branchc", (char*)".csv");
load_scenario(0, 7);
} else if(!strcmp(argv[argi], "branchs")) {
CStat::instance()->setFileName((char*)"branchs", (char*)".csv");
load_scenario(0, 8);
} else {
ERROR_P1("Invalid default scenario name '%s'.\n", argv[argi]);
}
scenario_file = new char [strlen(argv[argi])+1] ;
sprintf(scenario_file,"%s", argv[argi]);
} else {
ERROR_P1("Missing argument for param '%s'.\n"
"Use 'sipp -h' for details", argv[argi-1]);
}
}
if(!strcmp(argv[argi], "-sd")) {
if((++argi) < argc) {
processed = 1;
if(!strcmp(argv[argi], "uac")) {
fprintf(stdout, "%s", default_scenario[0]);
exit(EXIT_OTHER);
} else if(!strcmp(argv[argi], "uas")) {
fprintf(stdout, "%s", default_scenario[1]);
exit(EXIT_OTHER);
} else if(!strcmp(argv[argi], "regexp")) {
fprintf(stdout, "%s", default_scenario[2]);
exit(EXIT_OTHER);
} else if(!strcmp(argv[argi], "3pcc-C-A")) {
fprintf(stdout, "%s", default_scenario[3]);
exit(EXIT_OTHER);
} else if(!strcmp(argv[argi], "3pcc-C-B")) {
fprintf(stdout, "%s", default_scenario[4]);
exit(EXIT_OTHER);
} else if(!strcmp(argv[argi], "3pcc-A")) {
fprintf(stdout, "%s", default_scenario[5]);
exit(EXIT_OTHER);
} else if(!strcmp(argv[argi], "3pcc-B")) {
fprintf(stdout, "%s", default_scenario[6]);
exit(EXIT_OTHER);
} else if(!strcmp(argv[argi], "branchc")) {
fprintf(stdout, "%s", default_scenario[7]);
exit(EXIT_OTHER);
} else if(!strcmp(argv[argi], "branchs")) {
fprintf(stdout, "%s", default_scenario[8]);
exit(EXIT_OTHER);
} else {
ERROR_P1("Invalid default scenario name '%s'.\n", argv[argi]);
}
} else {
ERROR_P1("Missing argument for param '%s'.\n"
"Use 'sipp -h' for details", argv[argi-1]);
}
}
#ifdef __3PCC__
if(!strcmp(argv[argi], "-3pcc")) {
if((++argi) < argc) {
processed = 1;
twinSippMode = true;
strcpy(twinSippHost, argv[argi]);
} else {
ERROR_P1("Missing argument for param '%s'.\n"
"Use 'sipp -h' for details", argv[argi-1]);
}
}
#endif
if(!processed) {
if((argv[argi])[0] != '-') {
strcpy(remote_host, argv[argi]);
} else {
help();
ERROR_P1("Invalid argument: '%s'.\n"
"Use 'sipp -h' for details", argv[argi]);
}
}
}
/* trace file setting */
if (scenario_file == NULL) {
scenario_file = new char [ 5 ] ;
sprintf(scenario_file, "%s", "sipp");
} else {
scenario_file = remove_pattern (scenario_file, (char*)".xml");
}
if (useMessagef == 1) {
char *L_file_name ;
/* 14 for '_messages.log' and 6 for pid */
L_file_name = new char [ strlen(scenario_file)+14+6 ] ;
sprintf (L_file_name, "%s_%d_messages.log", scenario_file, getpid());
messagef = fopen(L_file_name, "w");
if(!messagef) {
ERROR_P1("Unable to create '%s'", L_file_name);
}
delete [] L_file_name ;
L_file_name = NULL ;
}
if (useScreenf == 1) {
char *L_file_name ;
/* 11 for '_screen.log' and 6 for pid */
L_file_name = new char [ strlen(scenario_file)+11+6 ] ;
sprintf (L_file_name, "%s_%d_screen.log", scenario_file, getpid());
screenf = fopen(L_file_name, "w");
if(!screenf) {
ERROR_P1("Unable to create '%s'", L_file_name);
}
delete [] L_file_name ;
L_file_name = NULL ;
}
if (useTimeoutf == 1) {
char *L_file_name ;
/* 13 for '_timeout.log' and 6 for pid */
L_file_name = new char [ strlen(scenario_file)+13+6 ] ;
sprintf (L_file_name, "%s_%d_timeout.log", scenario_file, getpid());
timeoutf = fopen(L_file_name, "w");
if(!timeoutf) {
ERROR_P1("Unable to create '%s'", L_file_name);
}
delete [] L_file_name ;
L_file_name = NULL ;
}
if (useLogf == 1) {
char *L_file_name ;
/* 9 for '_logs.log' and 6 for pid */
L_file_name = new char [ strlen(scenario_file)+9+6 ] ;
sprintf (L_file_name, "%s_%d_logs.log", scenario_file, getpid());
logfile = fopen(L_file_name, "w");
if(!logfile) {
ERROR_P1("Unable to create '%s'", L_file_name);
}
delete L_file_name ;
L_file_name = NULL ;
}
/* Initialization: boost open file limit to the max (AgM)*/
{
struct rlimit rlimit;
if (getrlimit (RLIMIT_NOFILE, &rlimit) < 0) {
ERROR_NO("getrlimit error");
}
if (rlimit.rlim_max > FD_SETSIZE) {
fprintf (stderr, "Warning: open file limit > FD_SETSIZE; "
"limiting max. # of open files to FD_SETSIZE = %d\n",
FD_SETSIZE);
rlimit.rlim_max = FD_SETSIZE;
}
rlimit.rlim_cur = rlimit.rlim_max;
if (setrlimit (RLIMIT_NOFILE, &rlimit) < 0) {
ERROR_P1("Unable to increase the open file limit to FD_SETSIZE = %d",
FD_SETSIZE);
}
}
/* Load default scenario in case nothing was loaded */
if(!scenario_len) {
load_scenario(0, 0);
CStat::instance()->setFileName((char*)"uac", (char*)".csv");
sprintf(scenario_file,"uac");
}
if(argiFileName) {
CStat::instance()->setFileName(argv[argiFileName]);
}
if(argiInputFile) {
call::readInputFileContents(argv[argiInputFile]);
}
/* In which mode the tool is launched ? */
computeSippMode();
/* checking if we need to launch the tool in background mode */
if(backgroundMode == true)
{
pid_t l_pid;
switch(l_pid = fork())
{
case -1:
// error when forking !
ERROR_NO("Forking error");
exit(EXIT_FATAL_ERROR);
case 0:
// child process - poursuing the execution
break;
default:
// parent process - killing the parent - the child get the parent pid
printf("Background mode - PID=[%d]\n", l_pid);
exit(EXIT_OTHER);
}
}
/* Setting the rate and its dependant params (open_calls_allowed) */
set_rate(rate);
if(!strlen(remote_host)) {
if(toolMode != MODE_SERVER) {
ERROR("Missing remote host parameter. This scenario requires it");
}
} else {
int temp_remote_port;
get_host_and_port(remote_host, remote_host, &temp_remote_port);
if (temp_remote_port != 0) {
remote_port = temp_remote_port;
}
/* Resolving the remote IP */
{
struct addrinfo hints;
struct addrinfo * local_addr;
printf("Resolving remote host '%s'...\n", remote_host);
memset((char*)&hints, 0, sizeof(hints));
hints.ai_flags = AI_PASSIVE;
hints.ai_family = PF_UNSPEC;
if (getaddrinfo(remote_host,
NULL,
&hints,
&local_addr) != 0) {
ERROR_P1("Unknown remote host '%s'.\n"
"Use 'sipp -h' for details", remote_host);
}
memset(&remote_sockaddr, 0, sizeof( remote_sockaddr ));
memcpy(&remote_sockaddr,
local_addr->ai_addr,
SOCK_ADDR_SIZE(
_RCAST(struct sockaddr_storage *,local_addr->ai_addr)));
strcpy(remote_ip, get_inet_address(&remote_sockaddr));
if (remote_sockaddr.ss_family == AF_INET) {
(_RCAST(struct sockaddr_in *, &remote_sockaddr))->sin_port =
htons((short)remote_port);
strcpy(remote_ip_escaped, remote_ip);
} else {
(_RCAST(struct sockaddr_in6 *, &remote_sockaddr))->sin6_port =
htons((short)remote_port);
sprintf(remote_ip_escaped, "[%s]", remote_ip);
}
}
}
if(gethostname(hostname,64) != 0) {
ERROR_NO("Can't get local hostname in 'gethostname(hostname,64)'");
}
{
char * local_host = NULL;
struct addrinfo hints;
struct addrinfo * local_addr;
if (!strlen(local_ip)) {
local_host = (char *)hostname;
} else {
local_host = (char *)local_ip;
}
memset((char*)&hints, 0, sizeof(hints));
hints.ai_flags = AI_PASSIVE;
hints.ai_family = PF_UNSPEC;
/* Resolving local IP */
if (getaddrinfo(local_host,
NULL,
&hints,
&local_addr) != 0) {
ERROR_P2("Can't get local IP address in getaddrinfo, local_host='%s', local_ip='%s'",
local_host,
local_ip);
}
memset(&local_sockaddr,0,sizeof(struct sockaddr_storage));
local_sockaddr.ss_family = local_addr->ai_addr->sa_family;
if (!strlen(local_ip)) {
strcpy(local_ip,
get_inet_address(
_RCAST(struct sockaddr_storage *, local_addr->ai_addr)));
}
if (local_sockaddr.ss_family == AF_INET6) {
is_ipv6 = true;
sprintf(local_ip_escaped, "[%s]", local_ip);
} else {
strcpy(local_ip_escaped, local_ip);
}
}
/* Creating and binding the local socket */
if((main_socket = socket(is_ipv6 ? AF_INET6 : AF_INET,
(transport == T_UDP) ? SOCK_DGRAM : SOCK_STREAM,
0)) == -1) {
ERROR_NO("Unable to get the local socket");
}
/* Trying to bind local port */
if(!user_port) {
unsigned short l_port;
for(l_port = DEFAULT_PORT;
l_port < (DEFAULT_PORT + 60);
l_port++) {
if (is_ipv6) {
(_RCAST(struct sockaddr_in6 *, &local_sockaddr))->sin6_port
= htons((short)l_port);
} else {
(_RCAST(struct sockaddr_in *, &local_sockaddr))->sin_port
= htons((short)l_port);
}
if(!bind(main_socket,
(sockaddr *)(void *)&local_sockaddr,
SOCK_ADDR_SIZE(&local_sockaddr))) {
local_port = l_port;
break;
}
}
}
if(!local_port) {
/* Not already binded, use user_port of 0 to leave
* the system choose a port. */
if (is_ipv6) {
(_RCAST(struct sockaddr_in6 *, &local_sockaddr))->sin6_port
= htons((short)user_port);
} else {
(_RCAST(struct sockaddr_in *, &local_sockaddr))->sin_port
= htons((short)user_port);
}
if(bind(main_socket,
(sockaddr *)(void *)&local_sockaddr,
SOCK_ADDR_SIZE(&local_sockaddr))) {
ERROR_NO("Unable to bind main socket");
}
}
/* Recover system port */
{
sipp_socklen_t len = SOCK_ADDR_SIZE(&local_sockaddr);
getsockname(main_socket,
(sockaddr *)(void *)&local_sockaddr,
&len);
if (is_ipv6) {
local_port =
ntohs((short)
(_RCAST(struct sockaddr_in6 *,&local_sockaddr))->sin6_port);
} else {
local_port =
ntohs((short)
(_RCAST(struct sockaddr_in *,&local_sockaddr))->sin_port);
}
}
sipp_customize_socket(main_socket);
#ifdef _USE_OPENSSL
if((!multisocket) && (transport == T_TCP || transport == T_TLS) &&
#else
if((!multisocket) && (transport == T_TCP) &&
#endif
(toolMode != MODE_SERVER)) {
if((tcp_multiplex = socket(is_ipv6 ? AF_INET6 : AF_INET,
SOCK_STREAM,
0))== -1) {
ERROR_NO("Unable to get a TCP socket");
}
/*
struct sockaddr_storage *L_dest = &remote_sockaddr;
if (use_remote_sending_addr) {
L_dest = &remote_sending_sockaddr ;
}
(struct sockaddr *)(void *)L_dest,
*/
if(connect(tcp_multiplex,
(struct sockaddr *)(void *)&remote_sockaddr,
SOCK_ADDR_SIZE(&remote_sockaddr))) {
if(errno == EINVAL){
/* This occurs sometime on HPUX but is not a true INVAL */
ERROR_NO("Unable to connect a TCP socket, remote peer error.\n"
"Use 'sipp -h' for details");
} else {
ERROR_NO("Unable to connect a TCP socket.\n"
"Use 'sipp -h' for details");
}
}
#ifdef _USE_OPENSSL
if ( transport == T_TLS ) {
if ((sip_trp_ssl_ctx_client = SSL_CTX_new(SSLv23_method())) == NULL){
ERROR("Unable to init the SSL_CTX - SSL_CTX_new Fail\n");
}
if ( (bio = BIO_new_socket(tcp_multiplex,BIO_NOCLOSE)) == NULL) {
ERROR("Unable to create BIO object:Problem with BIO_new_socket()\n");
}
if (!(ssl_tcp_multiplex = SSL_new(sip_trp_ssl_ctx_client))){
ERROR("Unable to create SSL object : Problem with SSL_new() \n");
}
SSL_set_bio(ssl_tcp_multiplex,bio,bio);
if ( (err = SSL_connect(ssl_tcp_multiplex)) < 0 ) {
ERROR("Error in SSL connection \n");
}
ssl_list[tcp_multiplex] = ssl_tcp_multiplex;
}
#endif
sipp_customize_socket(tcp_multiplex);
}
#ifdef _USE_OPENSSL
if (transport == T_TLS ) {
if ((sip_trp_ssl_ctx = SSL_CTX_new(SSLv23_method())) == NULL) {
ERROR("SSL_CTX_new() - main() - Fails\n");
}
/* Load the Certificate into the SSL context */
if ( SSL_CTX_use_certificate_file(sip_trp_ssl_ctx,CERTFILE,SSL_FILETYPE_PEM) != 1 ) {
ERROR_P1("Unable to load Certificate SSL_CTX_use_certificate_file '%s'\n",
CERTFILE);
}
if ( SSL_CTX_use_PrivateKey_file(sip_trp_ssl_ctx,PRIVATE_KEY_FILE,SSL_FILETYPE_PEM) != 1) {
ERROR_P1("SSL_CTX_use_PrivateKey_file Fails with file '%s'\n",
PRIVATE_KEY_FILE);
}
}
if(transport == T_TCP || transport == T_TLS) {
#else
if(transport == T_TCP) {
#endif
if(listen(main_socket, 100)) {
ERROR_NO("Unable to listen main socket");
}
}
#ifdef __3PCC__
/* Trying to connect to Twin Sipp in 3PCC mode */
if(twinSippMode) {
if(toolMode == MODE_3PCC_CONTROLLER_A || toolMode == MODE_3PCC_A_PASSIVE) {
if(strstr(twinSippHost, ":")) {
twinSippPort = atol(strstr(twinSippHost, ":")+1);
*(strstr(twinSippHost, ":")) = 0;
}
/* Resolving the twin IP */
printf("Resolving twin address : %s...\n", twinSippHost);
struct addrinfo hints;
struct addrinfo * local_addr;
memset((char*)&hints, 0, sizeof(hints));
hints.ai_flags = AI_PASSIVE;
hints.ai_family = PF_UNSPEC;
is_ipv6 = false;
/* Resolving local IP */
if (getaddrinfo(twinSippHost,
NULL,
&hints,
&local_addr) != 0) {
ERROR_P1("Unknown twin host '%s'.\n"
"Use 'sipp -h' for details", twinSippHost);
}
memcpy(&twinSipp_sockaddr,
local_addr->ai_addr,
SOCK_ADDR_SIZE(
_RCAST(struct sockaddr_storage *,local_addr->ai_addr)));
if (twinSipp_sockaddr.ss_family == AF_INET) {
(_RCAST(struct sockaddr_in *,&twinSipp_sockaddr))->sin_port =
htons((short)twinSippPort);
} else {
(_RCAST(struct sockaddr_in6 *,&twinSipp_sockaddr))->sin6_port =
htons((short)twinSippPort);
is_ipv6 = true;
}
strcpy(twinSippIp, get_inet_address(&twinSipp_sockaddr));
if((twinSippSocket = socket(is_ipv6 ? AF_INET6 : AF_INET,
SOCK_STREAM, 0))== -1) {
ERROR_NO("Unable to get a TCP socket in 3PCC controller A mode");
}
if(connect(twinSippSocket,
(struct sockaddr *)(void *)&twinSipp_sockaddr,
SOCK_ADDR_SIZE(&twinSipp_sockaddr))) {
if(errno == EINVAL) {
/* This occurs sometime on HPUX but is not a true INVAL */
ERROR_NO("Unable to connect a TCP socket in 3PCC controller "
"A mode, remote peer error.\n"
"Use 'sipp -h' for details");
} else {
ERROR_NO("Unable to connect a TCP socket in 3PCC controller "
"A mode.\n"
"Use 'sipp -h' for details");
}
}
sipp_customize_socket(twinSippSocket);
} else if(toolMode == MODE_3PCC_CONTROLLER_B) {
if(strstr(twinSippHost, ":")) {
twinSippPort = atol(strstr(twinSippHost, ":")+1);
*(strstr(twinSippHost, ":")) = 0;
}
/* Resolving the listener IP */
printf("Resolving listener address : %s...\n", twinSippHost);
struct addrinfo hints;
struct addrinfo * local_addr;
memset((char*)&hints, 0, sizeof(hints));
hints.ai_flags = AI_PASSIVE;
hints.ai_family = PF_UNSPEC;
is_ipv6 = false;
/* Resolving local IP */
if (getaddrinfo(twinSippHost,
NULL,
&hints,
&local_addr) != 0) {
ERROR_P1("Unknown twin host '%s'.\n"
"Use 'sipp -h' for details", twinSippHost);
}
memcpy(&twinSipp_sockaddr,
local_addr->ai_addr,
SOCK_ADDR_SIZE(
_RCAST(struct sockaddr_storage *,local_addr->ai_addr)));
if (twinSipp_sockaddr.ss_family == AF_INET) {
(_RCAST(struct sockaddr_in *,&twinSipp_sockaddr))->sin_port =
htons((short)twinSippPort);
} else {
(_RCAST(struct sockaddr_in6 *,&twinSipp_sockaddr))->sin6_port =
htons((short)twinSippPort);
is_ipv6 = true;
}
strcpy(twinSippIp, get_inet_address(&twinSipp_sockaddr));
if((localTwinSippSocket = socket(is_ipv6 ? AF_INET6 : AF_INET,
SOCK_STREAM, 0))== -1) {
ERROR_NO("Unable to get a TCP socket in 3PCC controller B mode");
}
memset(&localTwin_sockaddr, 0, sizeof(struct sockaddr_storage));
if (!is_ipv6) {
localTwin_sockaddr.ss_family = AF_INET;
(_RCAST(struct sockaddr_in6 *,&localTwin_sockaddr))->sin6_port =
htons((short)twinSippPort);
} else {
localTwin_sockaddr.ss_family = AF_INET6;
(_RCAST(struct sockaddr_in *,&localTwin_sockaddr))->sin_port =
htons((short)twinSippPort);
}
if(bind(localTwinSippSocket,
(sockaddr *)(void *)&localTwin_sockaddr,
SOCK_ADDR_SIZE(&localTwin_sockaddr))) {
ERROR_NO("Unable to bind twin sipp socket in "
"3PCC_CONTROLLER_B mode");
}
if(listen(localTwinSippSocket, 100))
ERROR_NO("Unable to listen twin sipp socket in "
"3PCC_CONTROLLER_B mode");
sipp_customize_socket(localTwinSippSocket);
} else {
ERROR("TwinSipp Mode enabled but toolMode is different "
"from 3PCC_CONTROLLER_B and 3PCC_CONTROLLER_A\n");
}
} /* end if(twinSippMode) */
#endif
/* MaL : Create and Bind RTP socket */
if (media_port > 0) {
if((media_socket = socket(is_ipv6 ? AF_INET6 : AF_INET,
SOCK_DGRAM, 0)) == -1) {
ERROR_NO("Unable to get the RTP echo socket");
}
/* retrieve RTP local addr */
if (media_ip[0] == 0) {
strcpy(media_ip, local_ip);
}
struct addrinfo hints;
struct addrinfo * local_addr;
memset((char*)&hints, 0, sizeof(hints));
hints.ai_flags = AI_PASSIVE;
hints.ai_family = PF_UNSPEC;
is_ipv6 = false;
/* Resolving local IP */
if (getaddrinfo(media_ip,
NULL,
&hints,
&local_addr) != 0) {
ERROR_P1("Unknown RTP address '%s'.\n"
"Use 'sipp -h' for details", media_ip);
}
memcpy(&media_sockaddr,
local_addr->ai_addr,
SOCK_ADDR_SIZE(
_RCAST(struct sockaddr_storage *,local_addr->ai_addr)));
if (media_sockaddr.ss_family == AF_INET) {
(_RCAST(struct sockaddr_in *,&media_sockaddr))->sin_port =
htons((short)media_port);
strcpy(media_ip_escaped, media_ip);
} else {
(_RCAST(struct sockaddr_in6 *,&media_sockaddr))->sin6_port =
htons((short)media_port);
is_ipv6 = true;
sprintf(media_ip_escaped, "[%s]", media_ip);
}
if(bind(media_socket,
(sockaddr *)(void *)&media_sockaddr,
SOCK_ADDR_SIZE(&media_sockaddr))) {
ERROR_NO("Unable to bind RTP socket");
}
} else {
/* If media_port is not defined, need to put a default
* value for XML script variables */
media_port = 10000;
if (media_ip[0] == 0) {
strcpy(media_ip, local_ip);
}
}
if( backgroundMode == false ) {
if (print_all_responses) {
char *L_file_name ;
/* 12 for '_errors.log' and 6 for pid */
L_file_name = new char [ strlen(scenario_file)+12+6 ] ;
sprintf (L_file_name, "%s_%d_errors.log", scenario_file, getpid());
screen_init(L_file_name, print_last_stats);
delete [] L_file_name ;
L_file_name = NULL ;
} else {
screen_init(NULL, print_last_stats);
}
/* Creating the keyb thread */
if (pthread_create
(&pthread_id,
NULL,
(void *(*)(void *)) keyb_thread,
(void*)NULL)
== -1) {
ERROR_NO("Unable to create recv thread");
}
}
/* Creating the RTP echo thread */
if (media_socket > 0) {
if (pthread_create
(&pthread2_id,
NULL,
(void *(*)(void *)) rtp_echo_thread,
(void*)NULL)
== -1) {
ERROR_NO("Unable to create RTP echo thread");
}
}
traffic_thread(is_ipv6);
if (scenario_file != NULL) {
delete [] scenario_file ;
scenario_file = NULL ;
}
}
|