VMware Cloud Community
itmI11
Contributor
Contributor

Adding a "Traffic filtering and marking" rule to Distributed Port Group

Hello,

I would like to add a new Traffic Rule ("Traffic filtering and marking") to an existing Distributed Port Group on a VDS. In this case I want to set the CoS tag and a MAC Traffic Qualifier.

There are already more than 100 rules - i just want to add 1 more.

When I run this workflow I can see the "Reconfigure Distributed Port Group" task in vCenter with status "completed". The dvUPortgroup.config.configVersion also increases by 1.

But the new rule was not added. It's just the same configuration as before.

I'm particularly unsure about line 17: add. I dont know if I have done this right.

I mainly orientated on Traffic filtering using PowerCLI  post #3. I think im pretty close to the solution. But now I need a second pair of eyes to solve the problem.

Thank you for any help.

var cosTag = 4;

vlanID = 999;

description = "test999";

//dvUPortgroup = <insert DVPortgroup here>

var spec = new VcDVPortgroupConfigSpec();

spec.configVersion = dvUPortgroup.config.configVersion;

spec.defaultPortConfig = dvUPortgroup.config.defaultPortConfig;

spec.defaultPortConfig.filterPolicy = dvUPortgroup.config.defaultPortConfig.filterPolicy;

spec.defaultPortConfig.filterPolicy.filterConfig = dvUPortgroup.config.defaultPortConfig.filterPolicy.filterConfig;

//add rules

var filter = new VcDvsTrafficFilterConfigSpec();

filter.agentName = 'dvfilter-generic-vmware';

filter.operation = "add";

var ruleSet = new VcDvsTrafficRuleset();

ruleSet.enabled = true;

var rule = new VcDvsTrafficRule();

rule.description = description;

rule.direction = 'incomingPackets';

var qualifier = new Array();

qualifier[0] = new VcDvsMacNetworkRuleQualifier();

qualifier[0].vlanId = new VcIntExpression();

qualifier[0].vlanId.negate = false;

qualifier[0].vlanId.value = vlanID;

rule.qualifier = qualifier;

rule.action = new VcDvsUpdateTagNetworkRuleAction();

rule.action.qosTag = cosTag;

ruleSet.rules = new Array();

ruleSet.rules.push(rule);

//add to spec

filter.trafficRuleset = ruleSet;

spec.defaultPortConfig.filterPolicy.filterConfig.push(filter);

dvUPortgroup.reconfigureDVPortgroup_Task(spec);

Tags (1)
0 Kudos
0 Replies