本文整理匯總了Golang中github.com/NetSys/quilt/join.HashJoin函數的典型用法代碼示例。如果您正苦於以下問題:Golang HashJoin函數的具體用法?Golang HashJoin怎麽用?Golang HashJoin使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了HashJoin函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: updateOpenFlow
// Sets up the OpenFlow tables to get packets from containers into the OVN controlled
// bridge. The Openflow tables are organized as follows.
//
// - Table 0 will check for packets destined to an ip address of a label with MAC
// 0A:00:00:00:00:00 (obtained by OVN faking out arp) and use the OF mulipath action
// to balance load packets across n links where n is the number of containers
// implementing the label. This result is stored in NXM_NX_REG0. This is done using
// a symmetric l3/4 hash, so transport connections should remain intact.
//
// -Table 1 reads NXM_NX_REG0 and changes the destination mac address to one of the
// MACs of the containers that implement the label
//
// XXX: The multipath action doesn't perform well. We should migrate away from it
// choosing datapath recirculation instead.
func updateOpenFlow(dk docker.Client, odb ovsdb.Ovsdb, containers []db.Container,
labels []db.Label, connections []db.Connection) {
targetOF, err := generateTargetOpenFlow(dk, odb, containers, labels, connections)
if err != nil {
log.WithError(err).Error("failed to get target OpenFlow flows")
return
}
currentOF, err := generateCurrentOpenFlow(dk)
if err != nil {
log.WithError(err).Error("failed to get current OpenFlow flows")
return
}
_, flowsToDel, flowsToAdd := join.HashJoin(currentOF, targetOF, nil, nil)
for _, f := range flowsToDel {
if err := deleteOFRule(dk, f.(OFRule)); err != nil {
log.WithError(err).Error("error deleting OpenFlow flow")
}
}
for _, f := range flowsToAdd {
if err := addOFRule(dk, f.(OFRule)); err != nil {
log.WithError(err).Error("error adding OpenFlow flow")
}
}
}
示例2: updatePlacements
func updatePlacements(view db.Database, spec stitch.Stitch) {
stitchPlacements := toDBPlacements(spec.QueryPlacements())
key := func(val interface{}) interface{} {
pVal := val.(db.Placement)
return struct {
tl string
rule db.PlacementRule
}{pVal.TargetLabel, pVal.Rule}
}
_, addSet, removeSet := join.HashJoin(stitchPlacements,
db.PlacementSlice(view.SelectFromPlacement(nil)), key, key)
for _, toAddIntf := range addSet {
toAdd := toAddIntf.(db.Placement)
newPlacement := view.InsertPlacement()
newPlacement.TargetLabel = toAdd.TargetLabel
newPlacement.Rule = toAdd.Rule
view.Commit(newPlacement)
}
for _, toRemove := range removeSet {
view.Remove(toRemove.(db.Placement))
}
}
示例3: updatePlacements
func updatePlacements(view db.Database, spec stitch.Stitch) {
var placements db.PlacementSlice
for _, sp := range spec.Placements {
placements = append(placements, db.Placement{
TargetLabel: sp.TargetLabel,
Exclusive: sp.Exclusive,
OtherLabel: sp.OtherLabel,
Provider: sp.Provider,
Size: sp.Size,
Region: sp.Region,
})
}
key := func(val interface{}) interface{} {
p := val.(db.Placement)
p.ID = 0
return p
}
dbPlacements := db.PlacementSlice(view.SelectFromPlacement(nil))
_, addSet, removeSet := join.HashJoin(placements, dbPlacements, key, key)
for _, toAddIntf := range addSet {
toAdd := toAddIntf.(db.Placement)
id := view.InsertPlacement().ID
toAdd.ID = id
view.Commit(toAdd)
}
for _, toRemove := range removeSet {
view.Remove(toRemove.(db.Placement))
}
}
示例4: syncDir
func syncDir(store Store, dir directory, path string, idsArg []string) {
_, dirKeys, ids := join.HashJoin(join.StringSlice(dir.keys()),
join.StringSlice(idsArg), nil, nil)
var etcdLog string
for _, dirKey := range dirKeys {
id := dirKey.(string)
keyPath := fmt.Sprintf("%s/%s", path, id)
err := store.Delete(keyPath)
if err != nil {
etcdLog = fmt.Sprintf("Failed to delete %s: %s", keyPath, err)
}
delete(dir, id)
}
for _, idElem := range ids {
id := idElem.(string)
if _, ok := dir[id]; ok {
continue
}
key := fmt.Sprintf("%s/%s", path, id)
if err := store.Mkdir(key); err != nil {
etcdLog = fmt.Sprintf("Failed to create dir %s: %s", key, err)
continue
}
dir[id] = map[string]string{}
}
// Etcd failure leads to a bunch of useless errors. Therefore we only log once.
if etcdLog != "" {
log.Error(etcdLog)
}
}
示例5: updateConnections
func updateConnections(view db.Database, spec stitch.Stitch) {
scs, vcs := stitch.ConnectionSlice(spec.Connections),
view.SelectFromConnection(nil)
dbcKey := func(val interface{}) interface{} {
c := val.(db.Connection)
return stitch.Connection{
From: c.From,
To: c.To,
MinPort: c.MinPort,
MaxPort: c.MaxPort,
}
}
pairs, stitches, dbcs := join.HashJoin(scs, db.ConnectionSlice(vcs), nil, dbcKey)
for _, dbc := range dbcs {
view.Remove(dbc.(db.Connection))
}
for _, stitchc := range stitches {
pairs = append(pairs, join.Pair{L: stitchc, R: view.InsertConnection()})
}
for _, pair := range pairs {
stitchc := pair.L.(stitch.Connection)
dbc := pair.R.(db.Connection)
dbc.From = stitchc.From
dbc.To = stitchc.To
dbc.MinPort = stitchc.MinPort
dbc.MaxPort = stitchc.MaxPort
view.Commit(dbc)
}
}
示例6: updateDBLabels
func updateDBLabels(view db.Database, etcdData storeData, ipMap map[string]string) {
// Gather all of the label keys and IPs for single host labels, and IPs of
// the containers in a given label.
containerIPs := map[string][]string{}
labelIPs := map[string]string{}
labelKeys := map[string]struct{}{}
for _, c := range etcdData.containers {
for _, l := range c.Labels {
labelKeys[l] = struct{}{}
cIP := ipMap[strconv.Itoa(c.StitchID)]
if _, ok := etcdData.multiHost[l]; !ok {
labelIPs[l] = cIP
}
// The ordering of IPs between function calls will be consistent
// because the containers are sorted by their StitchIDs when
// inserted into etcd.
containerIPs[l] = append(containerIPs[l], cIP)
}
}
labelKeyFunc := func(val interface{}) interface{} {
return val.(db.Label).Label
}
labelKeySlice := join.StringSlice{}
for l := range labelKeys {
labelKeySlice = append(labelKeySlice, l)
}
pairs, dbls, dirKeys := join.HashJoin(db.LabelSlice(view.SelectFromLabel(nil)),
labelKeySlice, labelKeyFunc, nil)
for _, dbl := range dbls {
view.Remove(dbl.(db.Label))
}
for _, key := range dirKeys {
pairs = append(pairs, join.Pair{L: view.InsertLabel(), R: key})
}
for _, pair := range pairs {
dbl := pair.L.(db.Label)
dbl.Label = pair.R.(string)
if _, ok := etcdData.multiHost[dbl.Label]; ok {
dbl.IP = etcdData.multiHost[dbl.Label]
dbl.MultiHost = true
} else {
dbl.IP = labelIPs[dbl.Label]
dbl.MultiHost = false
}
dbl.ContainerIPs = containerIPs[dbl.Label]
view.Commit(dbl)
}
}
示例7: syncACLs
func syncACLs(ovsdbClient ovsdb.Client, connections []db.Connection) {
ovsdbACLs, err := ovsdbClient.ListACLs(lSwitch)
if err != nil {
log.WithError(err).Error("Failed to list ACLs")
return
}
expACLs := directedACLs(ovsdb.ACL{
Core: ovsdb.ACLCore{
Action: "drop",
Match: "ip",
Priority: 0,
},
})
for _, conn := range connections {
if conn.From == stitch.PublicInternetLabel ||
conn.To == stitch.PublicInternetLabel {
continue
}
expACLs = append(expACLs, directedACLs(
ovsdb.ACL{
Core: ovsdb.ACLCore{
Action: "allow",
Match: matchString(conn),
Priority: 1,
},
})...)
}
ovsdbKey := func(ovsdbIntf interface{}) interface{} {
return ovsdbIntf.(ovsdb.ACL).Core
}
_, toCreate, toDelete := join.HashJoin(ovsdbACLSlice(expACLs),
ovsdbACLSlice(ovsdbACLs), ovsdbKey, ovsdbKey)
for _, acl := range toDelete {
if err := ovsdbClient.DeleteACL(lSwitch, acl.(ovsdb.ACL)); err != nil {
log.WithError(err).Warn("Error deleting ACL")
}
}
for _, intf := range toCreate {
acl := intf.(ovsdb.ACL).Core
if err := ovsdbClient.CreateACL(lSwitch, acl.Direction,
acl.Priority, acl.Match, acl.Action); err != nil {
log.WithError(err).Warn("Error adding ACL")
}
}
}
示例8: checkACLs
func checkACLs(t *testing.T, client ovsdb.Client,
connections []db.Connection, exp []ovsdb.ACL) {
syncACLs(client, connections)
actual, _ := client.ListACLs(lSwitch)
ovsdbKey := func(ovsdbIntf interface{}) interface{} {
return ovsdbIntf.(ovsdb.ACL).Core
}
if _, left, right := join.HashJoin(ovsdbACLSlice(actual), ovsdbACLSlice(exp),
ovsdbKey, ovsdbKey); len(left) != 0 || len(right) != 0 {
t.Errorf("Wrong ACLs: expected %v, got %v.", exp, actual)
}
}
示例9: syncAddressSets
func syncAddressSets(ovsdbClient ovsdb.Client, labels []db.Label) {
ovsdbAddresses, err := ovsdbClient.ListAddressSets(lSwitch)
if err != nil {
log.WithError(err).Error("Failed to list address sets")
return
}
var expAddressSets []ovsdb.AddressSet
for _, l := range labels {
if l.Label == stitch.PublicInternetLabel {
continue
}
expAddressSets = append(expAddressSets,
ovsdb.AddressSet{
Name: addressSetName(l.Label),
Addresses: unique(append(l.ContainerIPs, l.IP)),
},
)
}
ovsdbKey := func(intf interface{}) interface{} {
addrSet := intf.(ovsdb.AddressSet)
// OVSDB returns the addresses in a non-deterministic order, so we
// sort them.
sort.Strings(addrSet.Addresses)
return addressSetKey{
name: addrSet.Name,
addresses: strings.Join(addrSet.Addresses, " "),
}
}
_, toCreate, toDelete := join.HashJoin(addressSlice(expAddressSets),
addressSlice(ovsdbAddresses), ovsdbKey, ovsdbKey)
for _, intf := range toDelete {
addr := intf.(ovsdb.AddressSet)
if err := ovsdbClient.DeleteAddressSet(lSwitch, addr.Name); err != nil {
log.WithError(err).Warn("Error deleting address set")
}
}
for _, intf := range toCreate {
addr := intf.(ovsdb.AddressSet)
if err := ovsdbClient.CreateAddressSet(
lSwitch, addr.Name, addr.Addresses); err != nil {
log.WithError(err).Warn("Error adding address set")
}
}
}
示例10: updatePorts
// There certain exceptions, as certain ports will never be deleted.
func updatePorts(odb ovsdb.Ovsdb, containers []db.Container) {
// An Open vSwitch patch port is referred to as a "port".
targetPorts := generateTargetPorts(containers)
currentPorts, err := generateCurrentPorts(odb)
if err != nil {
log.WithError(err).Error("failed to generate current openflow ports")
return
}
key := func(val interface{}) interface{} {
return struct {
name, bridge string
}{
name: val.(ovsPort).name,
bridge: val.(ovsPort).bridge,
}
}
pairs, lefts, rights := join.HashJoin(currentPorts, targetPorts, key, key)
for _, l := range lefts {
if l.(ovsPort).name == l.(ovsPort).bridge {
// The "bridge" port for the bridge should never be deleted
continue
}
if err := delPort(odb, l.(ovsPort)); err != nil {
log.WithError(err).Error("failed to delete openflow port")
continue
}
}
for _, r := range rights {
if err := addPort(odb, r.(ovsPort)); err != nil {
log.WithError(err).Error("failed to add openflow port")
continue
}
}
for _, p := range pairs {
if err := modPort(odb, p.L.(ovsPort), p.R.(ovsPort)); err != nil {
log.WithError(err).Error("failed to modify openflow port")
continue
}
}
}
示例11: test
func (tester networkTester) test(container db.Container) (
unreachable []string, unauthorized []string) {
// We should be able to ping ourselves.
expReachable := map[string]struct{}{
container.IP: {},
}
for _, label := range container.Labels {
for _, toLabelName := range tester.connectionMap[label] {
toLabel := tester.labelMap[toLabelName]
for _, ip := range append(toLabel.ContainerIPs, toLabel.IP) {
expReachable[ip] = struct{}{}
}
}
// We can ping our ovearching label, but not other containers within the
// label. E.g. 1.yellow.q can ping yellow.q (but not 2.yellow.q).
expReachable[tester.labelMap[label].IP] = struct{}{}
}
var expPings []pingResult
for _, ip := range tester.allIPs {
_, reachable := expReachable[ip]
expPings = append(expPings, pingResult{
target: ip,
reachable: reachable,
})
}
pingResults := tester.pingAll(container)
_, failures, _ := join.HashJoin(pingSlice(expPings), pingSlice(pingResults),
nil, nil)
for _, badIntf := range failures {
bad := badIntf.(pingResult)
if bad.reachable {
unreachable = append(unreachable, bad.target)
} else {
unauthorized = append(unauthorized, bad.target)
}
}
return unreachable, unauthorized
}
示例12: updateIPs
func updateIPs(namespace string, dev string, currIPs []string,
targetIPs []string) error {
_, ipToDel, ipToAdd := join.HashJoin(join.StringSlice(currIPs),
join.StringSlice(targetIPs), nil, nil)
for _, ip := range ipToDel {
if err := delIP(namespace, ip.(string), dev); err != nil {
return err
}
}
for _, ip := range ipToAdd {
if err := addIP(namespace, ip.(string), dev); err != nil {
return err
}
}
return nil
}
示例13: checkAddressSet
func checkAddressSet(t *testing.T, client ovsdb.Client,
labels []db.Label, exp []ovsdb.AddressSet) {
syncAddressSets(client, labels)
actual, _ := client.ListAddressSets(lSwitch)
ovsdbKey := func(intf interface{}) interface{} {
addrSet := intf.(ovsdb.AddressSet)
// OVSDB returns the addresses in a non-deterministic order, so we
// sort them.
sort.Strings(addrSet.Addresses)
return addressSetKey{
name: addrSet.Name,
addresses: strings.Join(addrSet.Addresses, " "),
}
}
if _, lefts, rights := join.HashJoin(addressSlice(actual), addressSlice(exp),
ovsdbKey, ovsdbKey); len(lefts) != 0 || len(rights) != 0 {
t.Errorf("Wrong address sets: expected %v, got %v.", exp, actual)
}
}
示例14: runAppTransact
func (sv *supervisor) runAppTransact(view db.Database,
dkcsArgs []docker.Container) []string {
var tearDowns []string
dbKey := func(val interface{}) interface{} {
return val.(db.Container).DockerID
}
dkKey := func(val interface{}) interface{} {
return val.(docker.Container).ID
}
pairs, dbcs, dkcs := join.HashJoin(db.ContainerSlice(
view.SelectFromContainer(nil)),
docker.ContainerSlice(dkcsArgs), dbKey, dkKey)
for _, iface := range dbcs {
dbc := iface.(db.Container)
tearDowns = append(tearDowns, dbc.DockerID)
view.Remove(dbc)
}
for _, dkc := range dkcs {
pairs = append(pairs, join.Pair{L: view.InsertContainer(), R: dkc})
}
for _, pair := range pairs {
dbc := pair.L.(db.Container)
dkc := pair.R.(docker.Container)
dbc.DockerID = dkc.ID
dbc.Pid = dkc.Pid
dbc.Image = dkc.Image
dbc.Command = append([]string{dkc.Path}, dkc.Args...)
view.Commit(dbc)
}
return tearDowns
}
示例15: updateRoutes
func updateRoutes(containers []db.Container) {
targetRoutes := routeSlice{
{
ip: "10.0.0.0/8",
dev: innerVeth,
isDefault: false,
},
{
ip: gatewayIP,
dev: innerVeth,
isDefault: true,
},
}
for _, dbc := range containers {
ns := networkNS(dbc.DockerID)
currentRoutes, err := generateCurrentRoutes(ns)
if err != nil {
log.WithError(err).Error("failed to get current ip routes")
continue
}
_, routesDel, routesAdd := join.HashJoin(currentRoutes, targetRoutes,
nil, nil)
for _, l := range routesDel {
if err := deleteRoute(ns, l.(route)); err != nil {
log.WithError(err).Error("error deleting route")
}
}
for _, r := range routesAdd {
if err := addRoute(ns, r.(route)); err != nil {
log.WithError(err).Error("error adding route")
}
}
}
}