Compares *True* if local router id is greater when compared to peer
        bgp id.

        Should only be called after protocol has reached OpenConfirm state.
327258
def is_local_router_id_greater(self):
        
        from ryu.services.protocols.bgp.utils.bgp import from_inet_ptoi

        if not self.state == BGP_FSM_OPEN_CONFIRM:
            raise BgpProtocolException(desc='Can access remote router id only'
                                            ' after open message is received')
        remote_id = self.recv_open_msg.bgp_identifier
        local_id = self.sent_open_msg.bgp_identifier
        return from_inet_ptoi(local_id) > from_inet_ptoi(remote_id)
138449
def updateRouterStatus(self):
        """"""
        print '%s call updateRouterStatus' % self.port
        cmd = 'state'
        while True:
            state = self.__sendCommand(cmd)[0]
            if state == 'detached':
                continue
            elif state == 'child':
                break
            else:
                return False

        cmd = 'state router'
        return self.__sendCommand(cmd)[0] == 'Done'
317013
private boolean checkIfHostHasChanged(EventChannelStruct event_channel_struct) {
        boolean retVal = false;
        try {
            IORdump dump = new IORdump(event_channel_struct.adm_device_proxy);
            String server_host = dump.get_hostname();

            //	Keep server_host name without Fully Qualify Domain Name
            int idx = server_host.indexOf('.');
            if (idx > 0)
                server_host = server_host.substring(0, idx);

            if (!event_channel_struct.host.equals(server_host))
                retVal = true;
        } catch (DevFailed e) { /* */ }
        return retVal;
    }
1320912
function DetectLocalIPAddress(callback) {
            if (!DetectRTC.isWebRTCSupported) {
                return;
            }

            if (DetectRTC.isORTCSupported) {
                return;
            }

            getIPs(function(ip) {
                //local IPs
                if (ip.match(/^(192\.168\.|169\.254\.|10\.|172\.(1[6-9]|2\d|3[01]))/)) {
                    callback('Local: ' + ip);
                }

                //assume the rest are public IPs
                else {
                    callback('Public: ' + ip);
                }
            });
        }
1193033
def has_authority_over(self, url):
        
        s = urlparse(url)
        if (s.scheme != self.master_scheme):
            return(False)
        if (s.netloc != self.master_netloc):
            if (not s.netloc.endswith('.' + self.master_netloc)):
                return(False)
            # Maybe should allow parallel for 3+ components, eg. a.example.org,
            # b.example.org
        path = os.path.dirname(s.path)
        if (self.strict and
                path != self.master_path and
                not path.startswith(self.master_path)):
            return(False)
        return(True)
1317422
void validateRevocationStatus(X509Certificate[] chain, String peerHost) throws CertificateException
  {
    final List<Certificate> bcChain = convertToBouncyCastleCertificate(chain);
    final List<SFPair<Certificate, Certificate>> pairIssuerSubjectList =
        getPairIssuerSubject(bcChain);

    if (peerHost.startsWith("ocspssd"))
    {
      return;
    }

    if (ocspCacheServer.new_endpoint_enabled)
    {
      ocspCacheServer.resetOCSPResponseCacheServer(peerHost);
    }

    synchronized (OCSP_RESPONSE_CACHE_LOCK)
    {
      boolean isCached = isCached(pairIssuerSubjectList);
      if (this.useOcspResponseCacheServer && !isCached)
      {
        if (!ocspCacheServer.new_endpoint_enabled)
        {
          LOGGER.debug(
              "Downloading OCSP response cache from the server. URL: {}",
              SF_OCSP_RESPONSE_CACHE_SERVER_URL);
        }
        else
        {
          LOGGER.debug(
              "Downloading OCSP response cache from the server. URL: {}",
              ocspCacheServer.SF_OCSP_RESPONSE_CACHE_SERVER);
        }
        readOcspResponseCacheServer();
        // if the cache is downloaded from the server, it should be written
        // to the file cache at all times.
        WAS_CACHE_UPDATED = true;
      }
      executeRevocationStatusChecks(pairIssuerSubjectList, peerHost);
      if (WAS_CACHE_UPDATED)
      {
        JsonNode input = encodeCacheToJSON();
        fileCacheManager.writeCacheFile(input);
        WAS_CACHE_UPDATED = false;
      }
    }
  }
800521
function isInbound(network, id) {
  for( var i = 0; i < network.edge.in.length; i++ ) {
    if(id === network.edge.out[i].properties.hobbes.id) {
      return true;
    }
  }

  return false;
}
459900
def get_bgp_neighbors(self):
        results = {}
        bgp_state_dict = {
            "Idle": {"is_up": False, "is_enabled": True},
            "Active": {"is_up": False, "is_enabled": True},
            "Open": {"is_up": False, "is_enabled": True},
            "Established": {"is_up": True, "is_enabled": True},
            "Closing": {"is_up": True, "is_enabled": True},
            "Shutdown": {"is_up": False, "is_enabled": False},
        }
        
        af_name_dict = {
            1: {1: "ipv4", 128: "vpnv4"},
            2: {1: "ipv6", 128: "vpnv6"},
            25: {70: "l2vpn"},
        }

        try:
            cmd = "show bgp all summary vrf all"
            vrf_list = self._get_command_table(cmd, "TABLE_vrf", "ROW_vrf")
        except NXAPICommandError:
            vrf_list = []

        for vrf_dict in vrf_list:
            result_vrf_dict = {
                "router_id": py23_compat.text_type(vrf_dict["vrf-router-id"]),
                "peers": {},
            }

            af_list = vrf_dict.get("TABLE_af", {}).get("ROW_af", [])
            if isinstance(af_list, dict):
                af_list = [af_list]

            for af_dict in af_list:
                saf_dict = af_dict.get("TABLE_saf", {}).get("ROW_saf", {})
                neighbors_list = saf_dict.get("TABLE_neighbor", {}).get(
                    "ROW_neighbor", []
                )

                if isinstance(neighbors_list, dict):
                    neighbors_list = [neighbors_list]

                for neighbor_dict in neighbors_list:
                    neighborid = napalm.base.helpers.ip(neighbor_dict["neighborid"])
                    remoteas = napalm.base.helpers.as_number(
                        neighbor_dict["neighboras"]
                    )
                    state = py23_compat.text_type(neighbor_dict["state"])

                    bgp_state = bgp_state_dict[state]
                    afid_dict = af_name_dict[int(af_dict["af-id"])]
                    safi_name = afid_dict[int(saf_dict["safi"])]

                    result_peer_dict = {
                        "local_as": int(vrf_dict["vrf-local-as"]),
                        "remote_as": remoteas,
                        "remote_id": neighborid,
                        "is_enabled": bgp_state["is_enabled"],
                        "uptime": -1,
                        "description": "",
                        "is_up": bgp_state["is_up"],
                        "address_family": {
                            safi_name: {
                                "sent_prefixes": -1,
                                "accepted_prefixes": -1,
                                "received_prefixes": int(
                                    neighbor_dict["prefixreceived"]
                                ),
                            }
                        },
                    }
                    result_vrf_dict["peers"][neighborid] = result_peer_dict

            vrf_name = vrf_dict["vrf-name-out"]
            if vrf_name == "default":
                vrf_name = "global"
            results[vrf_name] = result_vrf_dict
        return results
662767
def atlas_peer_is_whitelisted( peer_hostport, peer_table=None ):
    
    ret = None
    with AtlasPeerTableLocked(peer_table) as ptbl:
        if peer_hostport not in ptbl.keys():
            return None 

        ret = ptbl[peer_hostport].get("whitelisted", False)

    return ret
838586
boolean isEligible(Address address, @Nullable List<Route> routes) {
    // If this connection is not accepting new exchanges, we're done.
    if (transmitters.size() >= allocationLimit || noNewExchanges) return false;

    // If the non-host fields of the address don't overlap, we're done.
    if (!Internal.instance.equalsNonHost(this.route.address(), address)) return false;

    // If the host exactly matches, we're done: this connection can carry the address.
    if (address.url().host().equals(this.route().address().url().host())) {
      return true; // This connection is a perfect match.
    }

    // At this point we don't have a hostname match. But we still be able to carry the request if
    // our connection coalescing requirements are met. See also:
    // https://hpbn.co/optimizing-application-delivery/#eliminate-domain-sharding
    // https://daniel.haxx.se/blog/2016/08/18/http2-connection-coalescing/

    // 1. This connection must be HTTP/2.
    if (http2Connection == null) return false;

    // 2. The routes must share an IP address.
    if (routes == null || !routeMatchesAny(routes)) return false;

    // 3. This connection's server certificate's must cover the new host.
    if (address.hostnameVerifier() != OkHostnameVerifier.INSTANCE) return false;
    if (!supportsUrl(address.url())) return false;

    // 4. Certificate pinning must match the host.
    try {
      address.certificatePinner().check(address.url().host(), handshake().peerCertificates());
    } catch (SSLPeerUnverifiedException e) {
      return false;
    }

    return true; // The caller's address can be carried by this connection.
  }
693865
private boolean newStep(RouteProgress routeProgress) {
    boolean newStep = currentStep == null || !currentStep.equals(routeProgress.currentLegProgress().currentStep());
    currentStep = routeProgress.currentLegProgress().currentStep();
    return newStep;
  }
673901
def getLocalID(self):
        """"""
        # I looked at this conditional and thought "ah-hah! there's the bug!"
        # but Python actually makes that one big expression somehow, i.e.
        # "x is x is x" is not the same thing as "(x is x) is x".
        # That's pretty weird, dude.  -- kmt, 1/07
        if (self.local_id is self.canonicalID is None):
            return self.claimed_id
        else:
            return self.local_id or self.canonicalID
916918
function compareByIdThenRev(a, b) {
  var idCompare = compare(a._id, b._id);
  if (idCompare !== 0) {
    return idCompare;
  }
  var aStart = a._revisions ? a._revisions.start : 0;
  var bStart = b._revisions ? b._revisions.start : 0;
  return compare(aStart, bStart);
}
396867
def p_route_version(self, p):
        """"""
        if len(p) > 2:
            if p[2] <= 0:
                msg = "Version number should be a positive integer."
                self.errors.append((msg, p.lineno(2), self.path))
            p[0] = p[2]
        else:
            p[0] = 1
447757
def channel_is_opened(
            self,
            participant1: Address,
            participant2: Address,
            block_identifier: BlockSpecification,
            channel_identifier: ChannelID,
    ) -> bool:
        
        try:
            channel_state = self._get_channel_state(
                participant1=participant1,
                participant2=participant2,
                block_identifier=block_identifier,
                channel_identifier=channel_identifier,
            )
        except RaidenRecoverableError:
            return False
        return channel_state == ChannelState.OPENED
1217551
def req_rr_to_non_rtc_peers(self, route_family):
        
        assert route_family != RF_RTC_UC
        for peer in self._peers.values():
            # First check if peer is in established state
            if (peer.in_established and
                # Check if peer has valid capability for given address
                # family
                    peer.is_mbgp_cap_valid(route_family) and
                # Check if peer has valid capability for RTC
                    not peer.is_mbgp_cap_valid(RF_RTC_UC)):
                peer.request_route_refresh(route_family)
1236897
def get_bgp_neighbors_detail(self, neighbor_address=""):
        """"""
        bgp_neighbors = {}
        default_neighbor_details = {
            "up": False,
            "local_as": 0,
            "remote_as": 0,
            "router_id": "",
            "local_address": "",
            "routing_table": "",
            "local_address_configured": False,
            "local_port": 0,
            "remote_address": "",
            "remote_port": 0,
            "multihop": False,
            "multipath": False,
            "remove_private_as": False,
            "import_policy": "",
            "export_policy": "",
            "input_messages": -1,
            "output_messages": -1,
            "input_updates": -1,
            "output_updates": -1,
            "messages_queued_out": -1,
            "connection_state": "",
            "previous_connection_state": "",
            "last_event": "",
            "suppress_4byte_as": False,
            "local_as_prepend": False,
            "holdtime": 0,
            "configured_holdtime": 0,
            "keepalive": 0,
            "configured_keepalive": 0,
            "active_prefix_count": -1,
            "received_prefix_count": -1,
            "accepted_prefix_count": -1,
            "suppressed_prefix_count": -1,
            "advertised_prefix_count": -1,
            "flap_count": 0,
        }
        OPTION_KEY_MAP = {
            "RemovePrivateAS": "remove_private_as",
            "Multipath": "multipath",
            "Multihop": "multihop",
            "AddressFamily": "local_address_configured"
            # 'AuthKey'        : 'authentication_key_set'
            # but other vendors do not specify if auth key is set
            # other options:
            # Preference, HoldTime, Ttl, LogUpDown, Refresh
        }

        def _bgp_iter_core(neighbor_data, instance=None):
            """
            Iterate over a list of neighbors.
            For older junos, the routing instance is not specified inside the
            BGP neighbors XML, therefore we need to use a super sub-optimal structure
            as in get_bgp_neighbors: iterate through the list of network instances
            then execute one request for each and every routing instance.
            For newer junos, this is not necessary as the routing instance is available
            and we can get everything solve in a single request.
            """
            for bgp_neighbor in neighbor_data:
                remote_as = int(bgp_neighbor[0])
                neighbor_details = deepcopy(default_neighbor_details)
                neighbor_details.update(
                    {
                        elem[0]: elem[1]
                        for elem in bgp_neighbor[1]
                        if elem[1] is not None
                    }
                )
                if not instance:
                    peer_fwd_rti = neighbor_details.pop("peer_fwd_rti")
                    instance = peer_fwd_rti
                else:
                    peer_fwd_rti = neighbor_details.pop("peer_fwd_rti", "")
                instance_name = "global" if instance == "master" else instance
                options = neighbor_details.pop("options", "")
                if isinstance(options, str):
                    options_list = options.split()
                    for option in options_list:
                        key = OPTION_KEY_MAP.get(option)
                        if key is not None:
                            neighbor_details[key] = True
                four_byte_as = neighbor_details.pop("4byte_as", 0)
                local_address = neighbor_details.pop("local_address", "")
                local_details = local_address.split("+")
                neighbor_details["local_address"] = napalm.base.helpers.convert(
                    napalm.base.helpers.ip, local_details[0], local_details[0]
                )
                if len(local_details) == 2:
                    neighbor_details["local_port"] = int(local_details[1])
                else:
                    neighbor_details["local_port"] = 179
                neighbor_details["suppress_4byte_as"] = remote_as != four_byte_as
                peer_address = neighbor_details.pop("peer_address", "")
                remote_details = peer_address.split("+")
                neighbor_details["remote_address"] = napalm.base.helpers.convert(
                    napalm.base.helpers.ip, remote_details[0], remote_details[0]
                )
                if len(remote_details) == 2:
                    neighbor_details["remote_port"] = int(remote_details[1])
                else:
                    neighbor_details["remote_port"] = 179
                neighbor_details["routing_table"] = instance_name
                neighbor_details["local_as"] = napalm.base.helpers.as_number(
                    neighbor_details["local_as"]
                )
                neighbor_details["remote_as"] = napalm.base.helpers.as_number(
                    neighbor_details["remote_as"]
                )
                neighbors_rib = neighbor_details.pop("rib")
                neighbors_queue = neighbor_details.pop("queue")
                messages_queued_out = 0
                for queue_entry in neighbors_queue.items():
                    messages_queued_out += queue_entry[1][0][1]
                neighbor_details["messages_queued_out"] = messages_queued_out
                if instance_name not in bgp_neighbors.keys():
                    bgp_neighbors[instance_name] = {}
                if remote_as not in bgp_neighbors[instance_name].keys():
                    bgp_neighbors[instance_name][remote_as] = []
                neighbor_rib_stats = neighbors_rib.items()
                if not neighbor_rib_stats:
                    bgp_neighbors[instance_name][remote_as].append(neighbor_details)
                    continue  # no RIBs available, pass default details
                neighbor_rib_details = {
                    "active_prefix_count": 0,
                    "received_prefix_count": 0,
                    "accepted_prefix_count": 0,
                    "suppressed_prefix_count": 0,
                    "advertised_prefix_count": 0,
                }
                for rib_entry in neighbor_rib_stats:
                    for elem in rib_entry[1]:
                        if elem[1] is None:
                            neighbor_rib_details[elem[0]] += 0
                        else:
                            neighbor_rib_details[elem[0]] += elem[1]
                neighbor_details.update(neighbor_rib_details)
                bgp_neighbors[instance_name][remote_as].append(neighbor_details)

        # old_junos = napalm.base.helpers.convert(
        #     int, self.device.facts.get('version', '0.0').split('.')[0], 0) < 15
        bgp_neighbors_table = junos_views.junos_bgp_neighbors_table(self.device)

        # if old_junos:
        instances = junos_views.junos_route_instance_table(self.device)
        for instance, instance_data in instances.get().items():
            if instance.startswith("__"):
                # junos internal instances
                continue
            neighbor_data = bgp_neighbors_table.get(
                instance=instance, neighbor_address=str(neighbor_address)
            ).items()
            _bgp_iter_core(neighbor_data, instance=instance)
        # else:
        #     bgp_neighbors_table = junos_views.junos_bgp_neighbors_table(self.device)
        #     neighbor_data = bgp_neighbors_table.get(neighbor_address=neighbor_address).items()
        #     _bgp_iter_core(neighbor_data)
        return bgp_neighbors