|
| 1 | +## Notes on Traffic Filtering and Marking code |
| 2 | + |
| 3 | + |
| 4 | +### Need to make: |
| 5 | +- `Get-VNVDTrafficRuleAction` |
| 6 | +- `Set-VNVDTrafficRuleSet -Enabled -Precedence -TrafficRuleset` |
| 7 | + - define cmdlet `ConfirmImpact` to High |
| 8 | +- Examples/docs |
| 9 | + |
| 10 | +### Maybe eventually add: |
| 11 | +- `Copy-VNVDTrafficRule -Rule -Ruleset <rulesettowhichtocopy>` |
| 12 | +- `Set-VNVDTrafficRule` -- to update a rule, maybe? (like change qualifier/action?) |
| 13 | +- `New-VNVDTrafficRule` |
| 14 | + - may need to add logic to ensure it meets requirement stated in API ref of, "There can be a maximum of 1 DvsIpNetworkRuleQualifier, 1 DvsMacNetworkRuleQualifier, and 1 DvsSystemTrafficNetworkRuleQualifier for a total of 3 qualifiers" |
| 15 | +- `Set-VNVDTrafficRuleSet -Enabled -Precedence -Rule -TrafficRuleset` |
| 16 | + - to enable/disable the Ruleset, and maybe to allow for the overwriting of the rules in the ruleset with just the new Rule(s) specified |
| 17 | +- add `-RunAsync` to `New-VNVDTrafficRule`, `Remove-VNVDTrafficRule`, and any other cmdlet where it makes sense |
| 18 | + |
| 19 | +Done (to at least some extent -- some may have further features to implement): |
| 20 | +- `Get-VNVDTrafficFilterPolicyConfig` |
| 21 | +- `Get-VNVDTrafficRuleSet` (returns VNVDTrafficRuleSet object with VDPG property, too) |
| 22 | +- `Get-VNVDTrafficRule` |
| 23 | +- `Get-VNVDTrafficRuleQualifier` |
| 24 | +- `New-VNVDTrafficRuleQualifier` |
| 25 | +- `New-VNVDTrafficRuleAction` |
| 26 | + - remaining Action types to implement: DvsCopyNetworkRuleAction, DvsGreEncapNetworkRuleAction, DvsLogNetworkRuleAction, DvsMacRewriteNetworkRuleAction, DvsPuntNetworkRuleAction, DvsRateLimitNetworkRuleAction |
| 27 | +- Ruleset object returned from `Get-VNVDTrafficRuleSet` should have property of "parent vDPG", to be used for vDPG reconfig task (need to add vDPG property to return from `Get-VNVDTrafficFilterPolicyConfig`, `Get-VNVDTrafficRuleSet`, and `Get-VNVDTrafficRule`) |
| 28 | +- `New-VNVDTrafficRule` |
| 29 | + - adds rule to TrafficRuleset |
| 30 | +- `Remove-VNVDTrafficRule -Rule[]` |
| 31 | + - define cmdlet `ConfirmImpact` to `High` |
| 32 | + - removes a given rule from the associated ruleset on the given vDPortgroup |
| 33 | + - implemented, but initially with a bug (now worked around): cannot rely on TrafficRule object's `Key` property, as that changes with every vDPortgroup reconfig, apparently (so, if iterating through several Rules, after the removal of the 1st one, the keys for the rest in the pipeline are invalid) |
| 34 | + - so, must do the `Process` differently so that all TrafficRule items per vDPortgroup are removed in one reconfig (or, other, less reliable ways, for which I did not opt) |
| 35 | + - Operating with the understanding/observation that there is only ever one (1) `Config.DefaultPortConfig.FilterPolicy.FilterConfig` per vDPortgroup (and, so, one subsequent TrafficRuleset, since a FilterConfig has one TrafficRuleset), even though the `.FilterConfig` property is of type `VMware.Vim.DvsFilterConfig[]`; so, using single TrafficRuleset per group of TrafficRules to remove; may need revisited in the future |
| 36 | + |
| 37 | +## Get |
| 38 | +`Get-VDPortgroup | Get-VNVDTrafficRuleSet | Get-VNVDTrafficRule` |
| 39 | + |
| 40 | +## New traffic rule, (adding traffic rule to traffic ruleset) |
| 41 | +`Get-VDPortgroup someVdpg | Get-VNVDTrafficRuleSet | New-VNVDTrafficRule -Rule (New-VNVDTrafficRule -Direction blahh -Qualifier (New-VNVDTrafficRuleQualifier -ParmsHere))` |
| 42 | + |
| 43 | +## eventually? Set (overwrite) all rules in the ruleset (if any) with new rule(s) specified |
| 44 | +`Get-VDPortgroup someVdpg | Get-VNVDTrafficRuleSet | Set-VNVDTrafficRuleSet -Enabled -Rule (New-VNVDTrafficRule -Direction blahh -Qualifier (New-VNVDTrafficRuleQualifier -ParmsHere))` |
| 45 | + |
| 46 | +## Remove some traffic rules |
| 47 | +`Get-VDPortgroup someVdpg | Get-VNVDTrafficRuleSet | Get-VNVDTrafficRule -Name testRule0, otherRule* | Remove-VNVDTrafficRule` |
| 48 | + |
| 49 | + |
| 50 | +## Other |
| 51 | +- example core code, from https://communities.vmware.com/thread/493610?q=distributed%20switch%20traffic%20filter |
| 52 | +``` PowerShell |
| 53 | +$dvSwName = 'dvSw1' |
| 54 | +$dvPgNames = 'dvPg1' |
| 55 | +
|
| 56 | +$dvSw = Get-VDSwitch -Name $dvSwName |
| 57 | +
|
| 58 | +foreach($pg in (Get-View -Id $dvSw.ExtensionData.Portgroup | Where {$dvPgNames -contains $_.Name})){ |
| 59 | + $spec = New-Object VMware.Vim.DVPortgroupConfigSpec |
| 60 | + $spec.ConfigVersion = $pg.Config.ConfigVersion |
| 61 | + $spec.DefaultPortConfig = New-Object VMware.Vim.VMwareDVSPortSetting |
| 62 | + $spec.DefaultPortConfig.FilterPolicy = New-Object VMware.Vim.DvsFilterPolicy |
| 63 | +
|
| 64 | + $filter = New-Object VMware.Vim.DvsTrafficFilterConfig |
| 65 | + $filter.AgentName = 'dvfilter-generic-vmware' |
| 66 | +
|
| 67 | + $ruleSet = New-Object VMware.Vim.DvsTrafficRuleset |
| 68 | + $ruleSet.Enabled = $true |
| 69 | +
|
| 70 | + $rule =New-Object VMware.Vim.DvsTrafficRule |
| 71 | + $rule.Description = 'Traffic Rule Name' |
| 72 | + $rule.Direction = 'outgoingPackets' |
| 73 | +
|
| 74 | + $action = New-Object VMware.Vim.DvsUpdateTagNetworkRuleAction |
| 75 | + $action.QosTag = 4 |
| 76 | +
|
| 77 | + $rule.Action += $action |
| 78 | +
|
| 79 | + $ruleSet.Rules += $rule |
| 80 | +
|
| 81 | + $filter.TrafficRuleSet += $ruleSet |
| 82 | +
|
| 83 | + $spec.DefaultPortConfig.FilterPolicy.FilterConfig += $filter |
| 84 | +
|
| 85 | + $pg.ReconfigureDVPortgroup($spec) |
| 86 | +} |
| 87 | +``` |
| 88 | + |
| 89 | +Other info: |
| 90 | +get VDTrafficFilterPolicyConfig: |
| 91 | +`$viewVDPG.Config.DefaultPortConfig.FilterPolicy.FilterConfig` |
0 commit comments