// while using ip_add_del_table
routingProtocolContext.addName(tableId, newProtocolName, mappingContext);
} else {
- throw new IllegalStateException(String.format(
- "An attempt to assign protocol %s to table id %s. Table id already assigned to protocol %s",
- newProtocolName, tableId, routingProtocolContext.getName(tableId, mappingContext)));
+ // prevent to fail while restoring data(trying to remap already mapped name)
+ if (!newProtocolName.equals(routingProtocolContext.getName(tableId, mappingContext))) {
+ throw new IllegalStateException(String.format(
+ "An attempt to assign protocol %s to table id %s. Table id already assigned to protocol %s",
+ newProtocolName, tableId, routingProtocolContext.getName(tableId, mappingContext)));
+ }
}
}
}
package io.fd.hc2vpp.routing.write;
import static io.fd.hc2vpp.routing.helpers.RoutingRequestTestHelper.ROUTE_PROTOCOL_NAME;
+import static io.fd.hc2vpp.routing.helpers.RoutingRequestTestHelper.ROUTE_PROTOCOL_NAME_2;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
private InstanceIdentifier<RoutingProtocol> validId;
private RoutingProtocol validData;
+ private RoutingProtocol validData2;
private RoutingProtocol invalidData;
private RoutingProtocolCustomizer customizer;
private NamingContext routingProtocolContext;
.build())
.build();
+ validData2= new RoutingProtocolBuilder()
+ .setName(ROUTE_PROTOCOL_NAME_2)
+ .setType(Static.class)
+ .addAugmentation(RoutingProtocolVppAttr.class, new RoutingProtocolVppAttrBuilder()
+ .setVppProtocolAttributes(new VppProtocolAttributesBuilder()
+ .setPrimaryVrf(new VniReference(1L))
+ .build())
+ .build())
+ .build();
+
invalidData = new RoutingProtocolBuilder()
.setType(Direct.class)
.build();
}
}
+ /**
+ * Should not fail, just ignore re-mapping same name
+ * */
@Test
- public void testWriteIsStaticAllreadyExist() throws WriteFailedException {
+ public void testWriteIsStaticSameAllreadyExist() throws WriteFailedException {
defineMapping(mappingContext, ROUTE_PROTOCOL_NAME, 1, "routing-protocol-context");
try {
customizer.writeCurrentAttributes(validId, validData, writeContext);
+ } catch (Exception e) {
+ fail("Test should have passed without throwing exception");
+ }
+ }
+
+ /**
+ * Should fail, because of attempt to map different name to same index
+ * */
+ @Test
+ public void testWriteIsStaticOtherAllreadyExist() throws WriteFailedException {
+ defineMapping(mappingContext, ROUTE_PROTOCOL_NAME, 1, "routing-protocol-context");
+ try {
+ customizer.writeCurrentAttributes(validId, validData2, writeContext);
} catch (Exception e) {
assertTrue(e instanceof IllegalStateException);
return;