Search in sources :

Example 1 with StackType

use of org.jgroups.util.StackType in project JGroups by belaban.

the class ChannelTestBase method initializeBase.

@BeforeClass
@Parameters(value = { "channel.conf", "use_blocking" })
protected void initializeBase(@Optional("udp.xml") String chconf, @Optional("false") String use_blocking) throws Exception {
    log = LogFactory.getLog(this.getClass());
    Test annotation = this.getClass().getAnnotation(Test.class);
    // this should never ever happen!
    if (annotation == null)
        throw new Exception("Test is not marked with @Test annotation");
    StackType type = Util.getIpStackType();
    bind_addr = type == StackType.IPv6 ? "::1" : "127.0.0.1";
    this.channel_conf = chconf;
    bind_addr = Util.getProperty(new String[] { Global.BIND_ADDR }, null, "bind_addr", bind_addr);
    System.setProperty(Global.BIND_ADDR, bind_addr);
}
Also used : StackType(org.jgroups.util.StackType)

Example 2 with StackType

use of org.jgroups.util.StackType in project JGroups by belaban.

the class Probe method main.

public static void main(String[] args) {
    InetAddress bind_addr = null;
    List<InetAddress> addrs = new ArrayList<>();
    int port = 0;
    int ttl = 32;
    long timeout = 500;
    final String DEFAULT_DIAG_ADDR = "224.0.75.75";
    final String DEFAULT_DIAG_ADDR_IPv6 = "ff0e::0:75:75";
    final int DEFAULT_DIAG_PORT = 7500;
    List<String> query = new ArrayList<>();
    String match = null;
    boolean weed_out_duplicates = false;
    String passcode = null;
    try {
        for (int i = 0; i < args.length; i++) {
            if ("-addr".equals(args[i])) {
                addrs.add(InetAddress.getByName(args[++i]));
                continue;
            }
            if ("-bind_addr".equals(args[i])) {
                bind_addr = InetAddress.getByName(args[++i]);
                continue;
            }
            if ("-port".equals(args[i])) {
                port = Integer.parseInt(args[++i]);
                continue;
            }
            if ("-ttl".equals(args[i])) {
                ttl = Integer.parseInt(args[++i]);
                continue;
            }
            if ("-timeout".equals(args[i])) {
                timeout = Long.parseLong(args[++i]);
                continue;
            }
            if ("-match".equals(args[i])) {
                match = args[++i];
                continue;
            }
            if ("-weed_out_duplicates".equals(args[i])) {
                weed_out_duplicates = true;
                continue;
            }
            if ("-passcode".equals(args[i])) {
                passcode = args[++i];
                continue;
            }
            if ("-cluster".equals(args[i])) {
                String cluster = args[++i];
                query.add("cluster=" + cluster);
                continue;
            }
            /* if("-node".equals(args[i])) {
                    String node=args[++i];
                    query.add("node=" + node);
                    continue;
                }*/
            if ("-help".equals(args[i]) || "-h".equals(args[i]) || "--help".equals(args[i])) {
                help();
                return;
            }
            query.add(args[i]);
        }
        Probe p = new Probe();
        if (addrs.isEmpty()) {
            StackType stack_type = Util.getIpStackType();
            boolean ipv6 = stack_type == StackType.IPv6;
            InetAddress addr = InetAddress.getByName(ipv6 ? DEFAULT_DIAG_ADDR_IPv6 : DEFAULT_DIAG_ADDR);
            addrs.add(addr);
        }
        if (port == 0)
            port = DEFAULT_DIAG_PORT;
        p.start(addrs, bind_addr, port, ttl, timeout, query, match, weed_out_duplicates, passcode);
    } catch (Throwable t) {
        t.printStackTrace();
    }
}
Also used : StackType(org.jgroups.util.StackType)

Example 3 with StackType

use of org.jgroups.util.StackType in project JGroups by belaban.

the class IpAddressTest method testEqualityWithDnsRoundRobin.

public static void testEqualityWithDnsRoundRobin() throws UnknownHostException {
    IpAddress x1, x2, x3;
    StackType type = Util.getIpStackType();
    String tmp = type == StackType.IPv6 ? "::1" : "127.0.0.1";
    InetAddress addr = InetAddress.getByName(tmp);
    byte[] rawAddr = addr.getAddress();
    InetAddress inet1 = InetAddress.getByAddress("MyHost1", rawAddr);
    InetAddress inet2 = InetAddress.getByAddress("MyHost2", rawAddr);
    InetAddress inet3 = InetAddress.getByAddress("MyHost3", rawAddr);
    Assert.assertEquals(inet1, inet2);
    x1 = new IpAddress(inet1, 5555);
    x2 = new IpAddress(inet2, 5555);
    x3 = new IpAddress(inet3, 5555);
    Assert.assertEquals(x1, x2);
    Assert.assertEquals(x3, x1);
    Set<Address> s = new HashSet<>();
    Collections.addAll(s, x1, x2, x3);
    System.out.println("s=" + s);
    Assert.assertEquals(1, s.size());
    Map<Address, String> m = new HashMap<>();
    m.put(x1, "Bela");
    m.put(x2, "Michelle");
    m.put(x3, "Nicole");
    Assert.assertEquals(1, m.size());
    Assert.assertEquals("Nicole", m.get(x1));
}
Also used : StackType(org.jgroups.util.StackType) IpAddress(org.jgroups.stack.IpAddress) InetAddress(java.net.InetAddress) Address(org.jgroups.Address) IpAddress(org.jgroups.stack.IpAddress) InetAddress(java.net.InetAddress)

Example 4 with StackType

use of org.jgroups.util.StackType in project JGroups by belaban.

the class Configurator method setupProtocolStack.

/**
 * The configuration string has a number of entries, separated by a ':' (colon).
 * Each entry consists of the name of the protocol, followed by an optional configuration
 * of that protocol. The configuration is enclosed in parentheses, and contains entries
 * which are name/value pairs connected with an assignment sign (=) and separated by
 * a semicolon.
 * <pre>UDP(in_port=5555;out_port=4445):FRAG(frag_size=1024)</pre><p>
 * The <em>first</em> entry defines the <em>bottommost</em> layer, the string is parsed
 * left to right and the protocol stack constructed bottom up. Example: the string
 * "UDP(in_port=5555):FRAG(frag_size=32000):DEBUG" results is the following stack:<pre>
 *
 *   -----------------------
 *  | DEBUG                 |
 *  |-----------------------|
 *  | FRAG frag_size=32000  |
 *  |-----------------------|
 *  | UDP in_port=32000     |
 *   -----------------------
 * </pre>
 */
public static Protocol setupProtocolStack(List<ProtocolConfiguration> protocol_configs, ProtocolStack st) throws Exception {
    List<Protocol> protocols = createProtocols(protocol_configs, st);
    if (protocols == null)
        return null;
    // check InetAddress related features of stack
    Map<String, Map<String, InetAddressInfo>> inetAddressMap = createInetAddressMap(protocol_configs, protocols);
    Collection<InetAddress> addrs = getAddresses(inetAddressMap);
    // 0 = n/a, 4 = IPv4, 6 = IPv6
    StackType ip_version = Util.getIpStackType();
    if (!addrs.isEmpty()) {
        for (InetAddress addr : addrs) {
            if (addr instanceof Inet6Address && ip_version == StackType.IPv4)
                throw new IllegalArgumentException("found IPv6 address " + addr + " in an IPv4 stack");
            if (addr instanceof Inet4Address && addr.isMulticastAddress() && ip_version == StackType.IPv6)
                throw new Exception("found IPv4 multicast address " + addr + " in an IPv6 stack");
        }
    }
    // process default values
    setDefaultValues(protocol_configs, protocols, ip_version);
    ensureValidBindAddresses(protocols);
    // Fixes NPE with concurrent channel creation when using a shared stack (https://issues.jboss.org/browse/JGRP-1488)
    Protocol top_protocol = protocols.get(protocols.size() - 1);
    top_protocol.setUpProtocol(st);
    return connectProtocols(protocols);
}
Also used : StackType(org.jgroups.util.StackType) Inet4Address(java.net.Inet4Address) Inet6Address(java.net.Inet6Address) InetAddress(java.net.InetAddress)

Example 5 with StackType

use of org.jgroups.util.StackType in project JGroups by belaban.

the class Configurator method setDefaultValues.

public static void setDefaultValues(List<Protocol> protocols) throws Exception {
    if (protocols == null)
        return;
    // check InetAddress related features of stack
    Collection<InetAddress> addrs = getInetAddresses(protocols);
    // 0 = n/a, 4 = IPv4, 6 = IPv6
    StackType ip_version = Util.getIpStackType();
    if (!addrs.isEmpty()) {
        for (InetAddress addr : addrs) {
            if (addr instanceof Inet6Address && ip_version == StackType.IPv4)
                throw new IllegalArgumentException("found IPv6 address " + addr + " in an IPv4 stack");
            if (addr instanceof Inet4Address && addr.isMulticastAddress() && ip_version == StackType.IPv6)
                throw new Exception("found IPv4 multicast address " + addr + " in an IPv6 stack");
        }
    }
    // process default values
    setDefaultValues(protocols, ip_version);
}
Also used : StackType(org.jgroups.util.StackType) Inet4Address(java.net.Inet4Address) Inet6Address(java.net.Inet6Address) InetAddress(java.net.InetAddress)

Aggregations

StackType (org.jgroups.util.StackType)10 BeforeClass (org.testng.annotations.BeforeClass)4 InetAddress (java.net.InetAddress)3 GossipRouter (org.jgroups.stack.GossipRouter)3 Inet4Address (java.net.Inet4Address)2 Inet6Address (java.net.Inet6Address)2 IpAddress (org.jgroups.stack.IpAddress)2 Address (org.jgroups.Address)1 IpAddressUUID (org.jgroups.stack.IpAddressUUID)1 BeforeMethod (org.testng.annotations.BeforeMethod)1