Example #1
0
func (c *Config) ConstructRule(rule Rule) *routing.Rule {
	if rule.Next == "" && rule.Pool == "" {
		logger.Errorf("[rule %s] no pool or trie", rule.Name)
		return routing.DummyRule(rule.Name)
	}

	var next *routing.Trie
	if rule.Next != "" {
		next = c.Tries[rule.Next]
		if next == nil {
			logger.Errorf("[rule %s] trie %s absent", rule.Name, rule.Next)
			next = routing.DummyTrie(rule.Next)
		}
	}

	var pool *backend.Pool
	if rule.Pool != "" {
		pool = c.Pools[rule.Pool]
		if pool == nil {
			logger.Errorf("[rule %s] trie %s absent", rule.Name, rule.Pool)
			pool = backend.DummyPool(rule.Pool)
		}
	}

	matcher, err := c.MatcherFactory.Make(rule.Type, rule.Value)
	if err != nil {
		logger.Errorf("[rule %s] setting matcher false", rule.Name)
		matcher = routing.NewStaticMatcher("false")
	}

	return routing.NewRule(rule.Name, matcher, next, pool)
}
Example #2
0
func (c *Config) DelTrie(name string) {
	c.Lock()
	defer c.Unlock()

	if _, ok := c.Tries[name]; !ok {
		logger.Errorf("no trie %s to delete", name)
		return
	}

	// nil references to this trie
	dummy := routing.DummyTrie(name)
	for _, rule := range c.Rules {
		if rule.Next == name {
			rule.NextPtr = dummy
		}
	}

	for num, _ := range c.Ports {
		if c.Ports[num].Name == name {
			c.Ports[num] = dummy
		}
	}

	delete(c.Tries, name)
}
Example #3
0
func (c *Config) UpdatePort(port Port) {
	c.Lock()
	defer c.Unlock()

	trie, ok := c.Tries[port.Trie]
	if !ok {
		trie = routing.DummyTrie(port.Trie)
		logger.Errorf("no trie %s in config", port.Trie)
	}
	c.Ports[port.Port] = trie
}
Example #4
0
func (c *Config) AddPort(port Port) {
	c.Lock()
	defer c.Unlock()

	if _, ok := c.Ports[port.Port]; ok {
		logger.Errorf("port %s exists in config", port.Port)
		return
	}

	trie, ok := c.Tries[port.Trie]
	if !ok {
		trie = routing.DummyTrie(port.Trie)
		logger.Errorf("no trie %s in config", port.Trie)
	}
	c.Ports[port.Port] = trie
}