Redefeind interfaces; Added better modelled data strauctures
Router interface has been redefined which fits better with what we are looking for. Routing table now offers a comprehensive set of information about its entries which will make up for rich queries in the future Query interface has been defined to enable current basic and more advanced queries in the future.
This commit is contained in:
		
							
								
								
									
										58
									
								
								router/table.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								router/table.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,58 @@ | ||||
| package router | ||||
|  | ||||
| import "errors" | ||||
|  | ||||
| var ( | ||||
| 	// ErrRouteNotFound is returned when no rout was found | ||||
| 	ErrRouteNotFound = errors.New("route not found") | ||||
| ) | ||||
|  | ||||
| // Entry is micro network routing table entry | ||||
| type Entry struct { | ||||
| 	// NetID is micro network ID | ||||
| 	NetID string | ||||
| 	// Hop is the next route hop | ||||
| 	Hop Router | ||||
| 	// Metric is route cost metric | ||||
| 	Metric int | ||||
| } | ||||
|  | ||||
| // Table is routing table | ||||
| // It maps service name to routes | ||||
| type Table struct { | ||||
| 	// m stores routing table map | ||||
| 	m map[string][]Entry | ||||
| } | ||||
|  | ||||
| // NewTable creates new routing table and returns it | ||||
| func NewTable() *Table { | ||||
| 	return &Table{ | ||||
| 		m: make(map[string][]Entry), | ||||
| 	} | ||||
| } | ||||
|  | ||||
| // TODO: Define lookup query interface | ||||
| // Lookup looks up entry in the routing table | ||||
| func (t *Table) Lookup() (*Entry, error) { | ||||
| 	return nil, nil | ||||
| } | ||||
|  | ||||
| // Remove removes entry from the routing table | ||||
| func (t *Table) Remove(e *Entry) error { | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // Update updates routin entry | ||||
| func (t *Table) Update(e *Entry) error { | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // Size returns the size of the routing table | ||||
| func (t *Table) Size() int { | ||||
| 	return 0 | ||||
| } | ||||
|  | ||||
| // String returns text representation of routing table | ||||
| func (t *Table) String() string { | ||||
| 	return "" | ||||
| } | ||||
		Reference in New Issue
	
	Block a user