Skip to content
Home » Articles » Opensips 3.2 + Rtpengine +Topology hiding + Bridging under Debian Bullseye

Opensips 3.2 + Rtpengine +Topology hiding + Bridging under Debian Bullseye

    App Opensips repo to sources lists
    apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 049AD65B
    echo "deb https://apt.opensips.org bullseye 3.2-releases" >/etc/apt/sources.list.d/opensips.list
    echo "deb https://apt.opensips.org bullseye cli-nightly" >/etc/apt/sources.list.d/opensips-cli.list

    Install opensips and it’s dependencies
    apt install opensips opensips-*
    
    Main route for the example, replace OPENSIPS_WAN_IP with your Opensips server’s public IP address, replace OPENSIPS_LAN_IP with the Lan IP of Opensips. We route every call to an Asterisk server listening on REMOTE_ASTERISK_IP:PORT. All calls from Asterisk will be routed out to your outbound provider at YOUR_PROVIDER_IP:PORT.
    ####### Main routing Logic ########
    
    route{
        if(!has_totag() && is_method("INVITE")) {
            create_dialog();
            topology_hiding("UC");
    
            if ( $socket_in(ip) == "OPENSIPS_WAN_IP" ) {
                $var(direction) =  "in-iface=wan out-iface=lan";
                $var(whereto_send) = "REMOTE_ASTERISK_IP:PORT";
            }
    
            if ( $socket_in(ip) == "OPENSIPS_LAN_IP" ) {
                $var(direction) =  "in-iface=lan out-iface=wan";
                $var(whereto_send) = "YOUR_PROVIDER_IP:PORT";
            }
    
            $var(rtpengine_params) = $var(direction) + " replace-origin replace-session-connection";
    
            if ( has_body("application/sdp") )
                rtpengine_manage("$var(rtpengine_params)");
    
            $du = "sip:" + $var(whereto_send);
            $ru = "sip:" + $rU + "@" + $var(whereto_send);
    
            route(RELAY);
        }
    
        if ( has_totag() ) {
            if ( is_method("ACK") && t_check_trans() ) {
                route(RELAY);
            }
            if ( topology_hiding_match() ) {
                if ( is_method("BYE") ) rtpengine_manage();
                route(RELAY);
            } else
                send_reply(404,"Not found");
        }
    
        if (is_method("CANCEL")) {
            if (t_check_trans()) {
                rtpengine_manage();
                route(RELAY);
            }
        }
    
        send_reply(501,"$rm not implemented");
    }
    
    route[RELAY] {
            if (!t_relay()) {
                    send_reply(500,"Internal Error");
            }
            exit;
    }
    
    onreply_route {
            if ( has_body("application/sdp") )
                           rtpengine_manage();
    }

    Thats it, now you have installed Opensips 3.2 in a front of Asterisk that is listening on a private IP.
    Your suggestions are always welcome! We want to say thank you for your continued liking and sharing. If you haven’t liked this post yet, you may do that by hitting the buttons at the sidebar. If you are a blogger and you appreciate the hard work, whether or not you copied this post, we implore you to kindly link back this post here, you may do it anyhow you can. We consider that a great contribution.