summaryrefslogtreecommitdiff
path: root/demoscript/Ice/multicast.py
blob: 059fe37cf9c5cc89853fd29e4779d72046600356 (plain)
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
#!/usr/bin/env python
# **********************************************************************
#
# Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved.
#
# This copy of Ice is licensed to you under the terms described in the
# ICE_LICENSE file included in this distribution.
#
# **********************************************************************

import sys, signal
from demoscript import Util
import Expect

def runClient(clientCmd, server1, server2):
    client = Util.spawn(clientCmd)
    received = False
    ex = None
    for i in range(0, 20):
        try:
            server1.expect('Hello World!', 1)
            received = True
        except Expect.TIMEOUT:
            pass
        try:
            server2.expect('Hello World!', 1)
            received = True
        except Expect.TIMEOUT as e:
            ex = e
            pass

        if received:
            break

    if not received:
        raise ex
    client.waitTestSuccess()

def runDemo(clientCmd, serverCmd):
    server1 = Util.spawn(serverCmd + ' --Ice.PrintAdapterReady')
    server1.expect('Discover ready')
    server1.expect('Hello ready')

    server2 = Util.spawn(serverCmd + ' --Ice.PrintAdapterReady')
    server2.expect('Discover ready')
    server2.expect('Hello ready')

    runClient(clientCmd, server1, server2)
    runClient(clientCmd, server1, server2)
    runClient(clientCmd, server1, server2)

    server1.kill(signal.SIGINT)
    server1.waitTestSuccess()

    server2.kill(signal.SIGINT)
    server2.waitTestSuccess()

def run(clientCmd, serverCmd):
    sys.stdout.write("testing multicast discovery (IPv4)... ")
    sys.stdout.flush()
    if serverCmd.startswith("java"):
        runDemo(clientCmd, "java -Djava.net.preferIPv4Stack=true Server")
    else:
        runDemo(clientCmd, serverCmd)
    print("ok")

    #
    # No IPv6 support in Windows with Java 1.6.x
    #
    if Util.getMapping() != "java" or not Util.isWin32() or not Util.getJavaVersion().startswith("1.6"):
    
        sys.stdout.write("testing multicast discovery (IPv6)... ")
        sys.stdout.flush()

        #
        # On OS X, using the interface-local address doesn't work, the client fails with 
        # a "Host not reachable" error, instead we use a link-local address with on loopback.
        #
        if Util.isDarwin():
            endpoint = 'udp -h \\"ff02::1:1\\" -p 10000 --interface \\"lo0\\"'
        else:
            endpoint = 'udp -h \\"ff01::1:1\\" -p 10000'
        serverCmd += ' --Ice.IPv6=1 --Discover.Endpoints="%s"' % (endpoint)
        clientCmd += ' --Ice.IPv6=1 --Discover.Proxy="discover:%s"' % (endpoint)
            
        runDemo(clientCmd, serverCmd)
        print("ok")