// Gateways retrieves the list of child Gateways of the RedundancyGroup
767900
func (o *RedundancyGroup) Gateways(info *bambou.FetchingInfo) (GatewaysList, *bambou.Error) {

	var list GatewaysList
	err := bambou.CurrentSession().FetchChildren(o, GatewayIdentity, &list, info)
	return list, err
}
1297875
func (o *GatewaySecurity) GatewaySecuredDatas(info *bambou.FetchingInfo) (GatewaySecuredDatasList, *bambou.Error) {

	var list GatewaySecuredDatasList
	err := bambou.CurrentSession().FetchChildren(o, GatewaySecuredDataIdentity, &list, info)
	return list, err
}
277036
func (o *Enterprise) NSGatewayTemplates(info *bambou.FetchingInfo) (NSGatewayTemplatesList, *bambou.Error) {

	var list NSGatewayTemplatesList
	err := bambou.CurrentSession().FetchChildren(o, NSGatewayTemplateIdentity, &list, info)
	return list, err
}
1080714
func (o *IKEGateway) IKEGatewayConfigs(info *bambou.FetchingInfo) (IKEGatewayConfigsList, *bambou.Error) {

	var list IKEGatewayConfigsList
	err := bambou.CurrentSession().FetchChildren(o, IKEGatewayConfigIdentity, &list, info)
	return list, err
}
199305
func (s *Server) Gateway() string {
	if len(s.Interfaces) == 0 || s.Interfaces[0].Switch == nil {
		return ""
	}
	if s.Interfaces[0].Switch.UserSubnet != nil {
		return s.Interfaces[0].Switch.UserSubnet.DefaultRoute
	}
	return s.Interfaces[0].Switch.Subnet.DefaultRoute
}
604091
func NewNSRedundantGatewayGroup() *NSRedundantGatewayGroup {

	return &NSRedundantGatewayGroup{
		GatewayPeer1Connected:    false,
		GatewayPeer2Connected:    false,
		HeartbeatInterval:        500,
		HeartbeatVLANID:          4094,
		ConsecutiveFailuresCount: 3,
	}
}
175235
func (o *Domain) NSGatewaySummaries(info *bambou.FetchingInfo) (NSGatewaySummariesList, *bambou.Error) {

	var list NSGatewaySummariesList
	err := bambou.CurrentSession().FetchChildren(o, NSGatewaySummaryIdentity, &list, info)
	return list, err
}
570634
func (o *RedundancyGroup) SAPIngressQoSProfiles(info *bambou.FetchingInfo) (SAPIngressQoSProfilesList, *bambou.Error) {

	var list SAPIngressQoSProfilesList
	err := bambou.CurrentSession().FetchChildren(o, SAPIngressQoSProfileIdentity, &list, info)
	return list, err
}
588899
func (s *Server) getAllGatewayConnections(conns map[uint64]*client) {
	gw := s.gateway
	gw.RLock()
	for _, c := range gw.out {
		c.mu.Lock()
		cid := c.cid
		c.mu.Unlock()
		conns[cid] = c
	}
	for cid, c := range gw.in {
		conns[cid] = c
	}
	gw.RUnlock()
}
1056536
func (s *Server) gossipGatewaysToInboundGateway(gwName string, c *client) {
	gw := s.gateway
	gw.RLock()
	defer gw.RUnlock()
	for gwCfgName, cfg := range gw.remotes {
		// Skip the gateway that we just created
		if gwCfgName == gwName {
			continue
		}
		info := Info{
			ID:         s.info.ID,
			GatewayCmd: gatewayCmdGossip,
		}
		urls := cfg.getURLsAsStrings()
		if len(urls) > 0 {
			info.Gateway = gwCfgName
			info.GatewayURLs = urls
			b, _ := json.Marshal(&info)
			c.mu.Lock()
			c.sendProto([]byte(fmt.Sprintf(InfoProto, b)), true)
			c.mu.Unlock()
		}
	}
}
683057
func (b *Broker) DeleteGroups(request *DeleteGroupsRequest) (*DeleteGroupsResponse, error) {
	response := new(DeleteGroupsResponse)

	if err := b.sendAndReceive(request, response); err != nil {
		return nil, err
	}

	return response, nil
}
891720
func (o *NSGateway) NSGatewayMonitors(info *bambou.FetchingInfo) (NSGatewayMonitorsList, *bambou.Error) {

	var list NSGatewayMonitorsList
	err := bambou.CurrentSession().FetchChildren(o, NSGatewayMonitorIdentity, &list, info)
	return list, err
}
477358
func (r *Route) getChildren() []*Route {

	// allocate once
	allRoutes := make([]*Route, 0, len(r.children)+2)

	// start with the normal routes
	allRoutes = append(allRoutes, r.children...)

	// then add the param child
	if r.paramChild != nil {
		allRoutes = append(allRoutes, r.paramChild)
	}

	// then add the wildcard child
	if r.wildcardChild != nil {
		allRoutes = append(allRoutes, r.wildcardChild)
	}

	return allRoutes
}
646092
func (c *Client) GetGroups() (groups []common.Group, err error) {
	return c.protocol.GetGroups()
}
1073524
func (o *Me) AllGateways(info *bambou.FetchingInfo) (AllGatewaysList, *bambou.Error) {

	var list AllGatewaysList
	err := bambou.CurrentSession().FetchChildren(o, AllGatewayIdentity, &list, info)
	return list, err
}
604777
func (claims *Claims) GatewayAccess(gatewayID string) bool {
	return claims.HasScope(scope.Gateway(gatewayID))
}
575536
func MigrateGatewayStats(p *redis.Pool, db sqlx.Queryer) error {
	log.Info("migrating gateway stats")

	var row struct {
		GatewayID           lorawan.EUI64               `db:"gateway_id"`
		Timestamp           time.Time                   `db:"timestamp"`
		Interval            storage.AggregationInterval `db:"interval"`
		RXPacketsReceived   int                         `db:"rx_packets_received"`
		RXPacketsReceivedOK int                         `db:"rx_packets_received_ok"`
		TXPacketsReceived   int                         `db:"tx_packets_received"`
		TXPacketsEmitted    int                         `db:"tx_packets_emitted"`
	}

	rows, err := db.Queryx(`
		select
			gateway_id,
			timestamp,
			interval,
			rx_packets_received,
			rx_packets_received_ok,
			tx_packets_received,
			tx_packets_emitted
		from
			gateway_stats
		where
			(interval = 'MINUTE' and timestamp >= (now() - interval '65 minutes')) or
			(interval = 'HOUR' and timestamp >= (now() - interval '25 hours')) or
			(interval = 'DAY' and timestamp >= (now() - interval '32 days')) or
			(interval = 'MONTH' and timestamp >= (now() - interval '13 months'))
	`)
	if err != nil {
		return errors.Wrap(err, "select error")
	}
	defer rows.Close()

	for rows.Next() {
		if err := rows.StructScan(&row); err != nil {
			return errors.Wrap(err, "scan error")
		}

		switch row.Interval {
		case storage.AggregationMinute, storage.AggregationHour, storage.AggregationDay, storage.AggregationMonth:
			err = storage.SaveMetricsForInterval(p, row.Interval, "gw:"+row.GatewayID.String(), storage.MetricsRecord{
				Time: row.Timestamp,
				Metrics: map[string]float64{
					"rx_count":    float64(row.RXPacketsReceived),
					"rx_ok_count": float64(row.RXPacketsReceivedOK),
					"tx_count":    float64(row.TXPacketsReceived),
					"tx_ok_count": float64(row.TXPacketsEmitted),
				},
			})
			if err != nil {
				return errors.Wrap(err, "save metrics error")
			}
		}
	}

	log.Info("gateway stats migrated")
	return nil
}